[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:42:45 PDT 2019
MaskRay created this revision.
MaskRay added reviewers: ruiu, sfertile.
Herald added subscribers: llvm-commits, jsji, kbarton, arichardson, nemanjai, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
clang/gcc PPC64 may emit a .rela.toc which references an embedded switch table in
a discarded .rodata/.text section. The .toc and the .rela.toc are incorrectly not
placed in the comdat.
Technically a relocation from outside the group is not allowed by the ELF spec:
> A symbol table entry with STB_LOCAL binding that is defined relative
> to one of a group's sections, and that is contained in a symbol table
> section that is not part of the group, must be discarded if the group
> members are discarded. References to this symbol table entry from
> outside the group are not allowed.
Don't report errors to work around the bug.
This should fix the ppc64le-lld-multistage-test bot. Some other PPC
specific sections may have similar problems. We can blacklist more
section names when problems occur.
Repository:
rLLD LLVM Linker
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,16 @@
+# REQUIRES: ppc
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
+# RUN: ld.lld %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
@@ -442,7 +442,7 @@
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.204216.patch
Type: text/x-patch
Size: 1951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190612/e951bb26/attachment.bin>
More information about the llvm-commits
mailing list