[PATCH] D63772: [ELF] Don't error on relocations to STT_SECTION symbols if the sections were discarded

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 25 08:21:28 PDT 2019


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

This essentially reverts r362743, which restored r361830.

  Reland D61583 [ELF] Error on relocations to STT_SECTION symbols if the sections were discarded

The reverts of this revision are tangled so it is a bit tricky to revert it.
This change keeps the goodness of D61583 <https://reviews.llvm.org/D61583> while fixing the line table issue as reported in
https://bugs.chromium.org/p/chromium/issues/detail?id=978067


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D63772

Files:
  ELF/InputFiles.cpp
  ELF/Relocations.cpp
  test/ELF/comdat-discarded-error.s
  test/ELF/comdat-discarded-reloc.s


Index: test/ELF/comdat-discarded-reloc.s
===================================================================
--- test/ELF/comdat-discarded-reloc.s
+++ test/ELF/comdat-discarded-reloc.s
@@ -1,9 +1,7 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/comdat-discarded-reloc.s -o %t2.o
-# RUN: ld.lld -gc-sections --noinhibit-exec %t2.o %t.o -o /dev/null
-# RUN: ld.lld -r %t2.o %t.o -o %t 2>&1 | FileCheck --check-prefix=WARN %s
-# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s
+# RUN: ld.lld -gc-sections %t.o %t2.o -o %t
 
 ## ELF spec doesn't allow a relocation to point to a deduplicated
 ## COMDAT section. Unfortunately this happens in practice (e.g. .eh_frame)
Index: test/ELF/comdat-discarded-error.s
===================================================================
--- test/ELF/comdat-discarded-error.s
+++ test/ELF/comdat-discarded-error.s
@@ -1,4 +1,5 @@
 # REQUIRES: x86
+# XFAIL: *
 # 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
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -653,17 +653,9 @@
     return "";
   ArrayRef<Elf_Shdr_Impl<ELFT>> ObjSections =
       CHECK(File->getObj().sections(), File);
-
-  std::string Msg;
-  if (Sym.Type == ELF::STT_SECTION) {
-    Msg = "relocation refers to a discarded section: ";
-    Msg += CHECK(
-        File->getObj().getSectionName(&ObjSections[Sym.DiscardedSecIdx]), File);
-  } else {
-    Msg = "relocation refers to a symbol in a discarded section: " +
-          toString(Sym);
-  }
-  Msg += "\n>>> defined in " + toString(File);
+  std::string Msg =
+      "relocation refers to a symbol in a discarded section: " + toString(Sym) +
+      "\n>>> defined in " + toString(File);
 
   Elf_Shdr_Impl<ELFT> ELFSec = ObjSections[Sym.DiscardedSecIdx - 1];
   if (ELFSec.sh_type != SHT_GROUP)
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -1080,9 +1080,6 @@
 
       if (ESym.st_shndx == SHN_UNDEF)
         this->Symbols[I] = make<Undefined>(this, Name, Binding, StOther, Type);
-      else if (Sec == &InputSection::Discarded)
-        this->Symbols[I] = make<Undefined>(this, Name, Binding, StOther, Type,
-                                           /*DiscardedSecIdx=*/SecIdx);
       else
         this->Symbols[I] =
             make<Defined>(this, Name, Binding, StOther, Type, Value, Size, Sec);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63772.206458.patch
Type: text/x-patch
Size: 2723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190625/cc21c2ad/attachment.bin>


More information about the llvm-commits mailing list