Bug 21017 - [microblaze] ld fails with missing _GLOBAL_OFFSET_TABLE_ symbol when all relocs are @GOTOFF
Summary: [microblaze] ld fails with missing _GLOBAL_OFFSET_TABLE_ symbol when all relo...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-02 20:51 UTC by Rich Felker
Modified: 2017-08-08 09:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
patch to fix the bug (248 bytes, patch)
2017-01-02 20:54 UTC, Rich Felker
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rich Felker 2017-01-02 20:51:58 UTC
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.
Comment 1 Rich Felker 2017-01-02 20:54:10 UTC
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.
Comment 2 cvs-commit@gcc.gnu.org 2017-01-03 16:20:06 UTC
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.
Comment 3 Nick Clifton 2017-01-03 16:51:58 UTC
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
Comment 4 cvs-commit@gcc.gnu.org 2017-08-08 09:31:31 UTC
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.
Comment 5 cvs-commit@gcc.gnu.org 2017-08-08 09:32:17 UTC
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.