[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
Mon Jul 6 11:10:57 PDT 2020


abidh created this revision.
abidh added reviewers: MaskRay, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Such relocations don't generate errors for -r/--emit-relocs in InputSection::copyRelocations. This patch allows similar behaviour in general and makes lld more consistent.


Repository:
  rG LLVM Github Monorepo

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,21 @@
+# 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 .eh_frame,"a", at unwind
+  .quad .text.foo
+
+.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" and ".eh_frame" can have relocations to discarded
+  // sections. Don't error out.
+  if (cast<Undefined>(sym).discardedSecIdx != 0 &&
+      (sec.name == ".gcc_except_table" || sec.name == ".eh_frame"))
+    return false;
+
   bool isWarning =
       (config->unresolvedSymbols == UnresolvedPolicy::Warn && canBeExternal) ||
       config->noinhibitExec;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83244.275764.patch
Type: text/x-patch
Size: 1428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200706/cb16052a/attachment.bin>


More information about the llvm-commits mailing list