From 5a0c326f6389b80a22ccc7fbb8cabef47d0e3b71 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 18 Mar 2020 20:38:15 +0000 Subject: [PATCH] Merge commit 315f8a55f from llvm git (by Fangrui Song): [ELF][PPC32] Don't report "relocation refers to a discarded section" for .got2 Similar to D63182 [ELF][PPC64] Don't report "relocation refers to a discarded section" for .toc Reviewed By: Bdragon28 Differential Revision: https://reviews.llvm.org/D75419 This is needed to fix compile errors when building for ppc32/lld10. Requested by: bdragon MFC after: 6 weeks X-MFC-With: 358851 Differential Revision: https://reviews.freebsd.org/D24110 --- contrib/llvm-project/lld/ELF/InputSection.cpp | 5 +++-- contrib/llvm-project/lld/ELF/Relocations.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/contrib/llvm-project/lld/ELF/InputSection.cpp b/contrib/llvm-project/lld/ELF/InputSection.cpp index 147c51ab285e..a59e61976f30 100644 --- a/contrib/llvm-project/lld/ELF/InputSection.cpp +++ b/contrib/llvm-project/lld/ELF/InputSection.cpp @@ -438,12 +438,13 @@ void InputSection::copyRelocations(uint8_t *buf, ArrayRef rels) { // 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 . + // See the comment in maybeReportUndefined for PPC32 .got2 and PPC64 .toc auto *d = dyn_cast(&sym); if (!d) { if (!sec->name.startswith(".debug") && !sec->name.startswith(".zdebug") && sec->name != ".eh_frame" && - sec->name != ".gcc_except_table" && sec->name != ".toc") { + sec->name != ".gcc_except_table" && sec->name != ".got2" && + sec->name != ".toc") { uint32_t secIdx = cast(sym).discardedSecIdx; Elf_Shdr_Impl sec = CHECK(file->getObj().sections(), file)[secIdx]; diff --git a/contrib/llvm-project/lld/ELF/Relocations.cpp b/contrib/llvm-project/lld/ELF/Relocations.cpp index 5609fb92fd27..c90990ac2752 100644 --- a/contrib/llvm-project/lld/ELF/Relocations.cpp +++ b/contrib/llvm-project/lld/ELF/Relocations.cpp @@ -926,8 +926,12 @@ static bool maybeReportUndefined(Symbol &sym, InputSectionBase &sec, // .toc and the .rela.toc are incorrectly not placed in the comdat. The ELF // spec says references from outside the group to a STB_LOCAL symbol are not // allowed. Work around the bug. - if (config->emachine == EM_PPC64 && - cast(sym).discardedSecIdx != 0 && sec.name == ".toc") + // + // PPC32 .got2 is similar but cannot be fixed. Multiple .got2 is infeasible + // because .LC0-.LTOC is not representable if the two labels are in different + // .got2 + if (cast(sym).discardedSecIdx != 0 && + (sec.name == ".got2" || sec.name == ".toc")) return false; bool isWarning =