[PATCH] D83244: [lld] Don't error out on relocations in .gcc_except_table to discarded sections.

Hafiz Abid Qadeer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 10 11:08:07 PDT 2020


abidh updated this revision to Diff 277104.
abidh added a comment.

I have removed the .eh_frame. I have looked a bit more into it. It seems that riscv target does create relocations in .gcc_except_table.  The following commit gives some background on its encoding.
https://reviews.llvm.org/rGab009a602e96b238000d9e20e5c54b078d08aad3

If I use -mno-relax during compilation then I dont see the relocations in .gcc_except_table and the problem goes away. I was able to create a simpler testcase which is attached with https://bugs.llvm.org/show_bug.cgi?id=46675


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83244/new/

https://reviews.llvm.org/D83244

Files:
  lld/ELF/Relocations.cpp
  lld/test/ELF/comdat-discarded-no-error.s


Index: lld/test/ELF/comdat-discarded-no-error.s
===================================================================
--- /dev/null
+++ lld/test/ELF/comdat-discarded-no-error.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t1.o
+# RUN: echo '.section .text.foo,"axG", at progbits,foo,comdat; .globl foo; foo:' |\
+# RUN:   llvm-mc -filetype=obj -triple=x86_64 - -o %t2.o
+# RUN: echo '.section .text.foo,"axG", at progbits,foo,comdat; .globl bar; bar:' |\
+# RUN:   llvm-mc -filetype=obj -triple=x86_64 - -o %t3.o
+
+# RUN: ld.lld %t2.o %t3.o %t1.o -o /dev/null 2>&1
+
+.globl _start
+_start:
+  nop
+
+.section .text.foo,"axG", at progbits,foo,comdat
+  nop
+
+.section .gcc_except_table,"a"
+  .quad .text.foo
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -955,6 +955,12 @@
       (sec.name == ".got2" || sec.name == ".toc"))
     return false;
 
+  // The "gcc_except_table" can have relocations to discarded sections.
+  // Don't error out.
+  if (cast<Undefined>(sym).discardedSecIdx != 0 &&
+      sec.name == ".gcc_except_table")
+    return false;
+
   bool isWarning =
       (config->unresolvedSymbols == UnresolvedPolicy::Warn && canBeExternal) ||
       config->noinhibitExec;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83244.277104.patch
Type: text/x-patch
Size: 1330 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200710/8f9aba59/attachment.bin>


More information about the llvm-commits mailing list