On Sun, 15 Nov 2020 17:23:09 +0100 (CET) Mark Kettenis <[email protected]> wrote:
> This is the diff from: > > https://reviews.llvm.org/D75419 > > which is needed to be able to link llvm with lld on powerpc. > > Not enough to link code generated by gcc 4.x though, but if I dissable > building gcc a make build completes. > > What would the impact on ports of disabling base-gcc be on powerpc? > > ok? ok gkoehler@ This diff is in upstream llvm, so let's take it as is. Large PIC uses pointers at -32768(%r30), -32764(%r30), ..., where r30 points to .LTOC in the .got2 section. Each file can have a different .LTOC, so the addend like -32768 fits in a signed 16-bit integer. .got2 can hold pointers to symbols in other shared objects, but powerpc clang also uses .got2 for pointers to local symbols in the same file! For example, "int f(void){static int i; return i++;}" would put the address of "static int i" in .got2. In upstream's test case, lld links 2 copies of .text.foo, discards 1 copy, and gets stuck with an extra .got2 pointer to a discarded local symbol. After the diff, lld leaves an extra .got2 pointer with R_PPC_NONE: $ objdump -rsj .got2 exam2.o ... RELOCATION RECORDS FOR [.got2]: OFFSET TYPE VALUE 00000000 R_PPC_ADDR32 .text.foo+0x00000004 00000004 R_PPC_NONE *ABS*+0x00000004 lld can't link a macppc kernel, because it can't handle branch absolute "ba" instructions with R_PPC_ADDR24 = 2: | ld: error: locore.S:(.text+0x208): unknown relocation (2) against symbol s_trap After I link ld.lld to /usr/bin/ld, the build of base-gcc fails with | ld: error: unable to find library -lc because we haven't taught base-gcc to pass -L/usr/lib to ld, as we did on amd64. I don't use base-gcc on powerpc, and won't miss it if we disable it. I suspect that ports-gcc will need a patch to do -L/usr/lib. --George > Index: gnu/llvm/lld/ELF/InputSection.cpp > =================================================================== > RCS file: /cvs/src/gnu/llvm/lld/ELF/InputSection.cpp,v > retrieving revision 1.1.1.2 > diff -u -p -r1.1.1.2 InputSection.cpp > --- gnu/llvm/lld/ELF/InputSection.cpp 9 Aug 2020 15:52:06 -0000 1.1.1.2 > +++ gnu/llvm/lld/ELF/InputSection.cpp 15 Nov 2020 16:15:46 -0000 > @@ -438,11 +438,12 @@ void InputSection::copyRelocations(uint8 > // 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<Defined>(&sym); > if (!d) { > if (!isDebugSection(*sec) && 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<Undefined>(sym).discardedSecIdx; > Elf_Shdr_Impl<ELFT> sec = > CHECK(file->getObj().sections(), file)[secIdx]; > Index: gnu/llvm/lld/ELF/Relocations.cpp > =================================================================== > RCS file: /cvs/src/gnu/llvm/lld/ELF/Relocations.cpp,v > retrieving revision 1.1.1.1 > diff -u -p -r1.1.1.1 Relocations.cpp > --- gnu/llvm/lld/ELF/Relocations.cpp 3 Aug 2020 14:32:29 -0000 1.1.1.1 > +++ gnu/llvm/lld/ELF/Relocations.cpp 15 Nov 2020 16:15:46 -0000 > @@ -926,8 +926,12 @@ static bool maybeReportUndefined(Symbol > // .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<Undefined>(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<Undefined>(sym).discardedSecIdx != 0 && > + (sec.name == ".got2" || sec.name == ".toc")) > return false; > > bool isWarning = > -- George Koehler <[email protected]>
