When linking a program where all GOT-based relocations are GOT-relative rather than GOT slots, create_got_section is never called and linking fails due to missing _GLOBAL_OFFSET_TABLE_ symbol. This was found to happen when static linking non-PIC code with musl libc's crt1 which contains (gratuitous for non-pie, but not erroneous) logic to compute the address of _DYNAMIC if it's defined, but it probably can also happen in other situations where most object files are non-PIC but one contains PIC code with only GOT-relative relocations.
Created attachment 9735 [details] patch to fix the bug This seems to fix the issue, but there may be additional reloc types that should be checked to fully fix it.
The master branch has been updated by Nick Clifton <nickc@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=de1010f40884537cf0905ad134162cd2db71dc2a commit de1010f40884537cf0905ad134162cd2db71dc2a Author: Rich Felker <bugdal@aerifal.cx> Date: Tue Jan 3 16:18:41 2017 +0000 Fix generation of GOT table when only GOT-relative relocs are used. PR ld/21017 * elf32-microblaze.c (microblaze_elf_check_relocs): Add an entry for R_MICROBLAZE_GOTOFF_64.
Hi Rich, I have checked in your proposed patch. We can add further relocs later if need be. If you can create a test case to demonstrate the problem, that would be very helpful as I could then add it to the linker testsuite. Cheers Nick
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=206c9c79ee24759c0e0af96e6722298b413f2716 commit 206c9c79ee24759c0e0af96e6722298b413f2716 Author: Alan Modra <amodra@gmail.com> Date: Tue Aug 8 14:05:33 2017 +0930 PR21017, microblaze missing _GLOBAL_OFFSET_TABLE_ symbol PR 21017 * elf32-microblaze.c (microblaze_elf_check_relocs): Don't bump got.refcount for GOTOFF relocs, just create .got section.
The binutils-2_29-branch branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=51bd0f967a9a9dfddaa267b4b6fb2e653d252026 commit 51bd0f967a9a9dfddaa267b4b6fb2e653d252026 Author: Alan Modra <amodra@gmail.com> Date: Tue Aug 8 14:05:33 2017 +0930 PR21017, microblaze missing _GLOBAL_OFFSET_TABLE_ symbol PR 21017 * elf32-microblaze.c (microblaze_elf_check_relocs): Don't bump got.refcount for GOTOFF relocs, just create .got section.