[PATCH] D63182: [ELF][PPC64] Don't report "relocation refers to a discarded section" for .toc

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 11 22:48:15 PDT 2019


MaskRay updated this revision to Diff 204217.
MaskRay edited the summary of this revision.
MaskRay added a comment.

.


Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D63182

Files:
  ELF/InputSection.cpp
  ELF/Relocations.cpp
  test/ELF/comdat-discarded-ppc64.s


Index: test/ELF/comdat-discarded-ppc64.s
===================================================================
--- /dev/null
+++ test/ELF/comdat-discarded-ppc64.s
@@ -0,0 +1,17 @@
+# REQUIRES: ppc
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
+# RUN: ld.lld %t.o %t.o -o /dev/null
+# RUN: ld.lld -r --fatal-warnings %t.o %t.o -o /dev/null
+
+## clang/gcc PPC64 may emit a .rela.toc which references a switch table in a
+## discarded .rodata/.text section. The .toc and the .rela.toc are incorrectly
+## not placed in the comdat.
+## Don't error "relocation refers to a discarded section".
+
+.section .text.foo,"axG", at progbits,foo,comdat
+.globl foo
+foo:
+.L0:
+
+.section .toc,"aw"
+.quad .L0
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -718,6 +718,13 @@
   if (Config->UnresolvedSymbols == UnresolvedPolicy::Ignore && CanBeExternal)
     return false;
 
+  // clang/gcc PPC64 may emit a .rela.toc which references a switch table in a
+  // discarded .rodata/.text section. The .toc and the .rela.toc are incorrectly
+  // not placed in the comdat. Work around the bug.
+  if (Config->EMachine == EM_PPC64 &&
+      cast<Undefined>(Sym).DiscardedSecIdx != 0 && Sec.Name == ".toc")
+    return false;
+
   auto Visibility = [&]() -> std::string {
     switch (Sym.Visibility) {
     case STV_INTERNAL:
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -438,11 +438,13 @@
       // relocation in it pointing to discarded sections with R_*_NONE, which
       // hopefully creates a frame that is ignored at runtime. Also, don't warn
       // on .gcc_except_table and debug sections.
+      //
+      // See the comment in maybeReportUndefined for PPC64 .toc .
       auto *D = dyn_cast<Defined>(&Sym);
       if (!D) {
         if (!Sec->Name.startswith(".debug") &&
             !Sec->Name.startswith(".zdebug") && Sec->Name != ".eh_frame" &&
-            Sec->Name != ".gcc_except_table") {
+            Sec->Name != ".gcc_except_table" && Sec->Name != ".toc") {
           uint32_t SecIdx = cast<Undefined>(Sym).DiscardedSecIdx;
           Elf_Shdr_Impl<ELFT> Sec =
               CHECK(File->getObj().sections(), File)[SecIdx];


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63182.204217.patch
Type: text/x-patch
Size: 2346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190612/534704d4/attachment.bin>


More information about the llvm-commits mailing list