Bug 22770 - [MIPS] GOLD fails to link ghc: internal error in get_got_page_offset, at gold/mips.cc:6271
Summary: [MIPS] GOLD fails to link ghc: internal error in get_got_page_offset, at gold...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.30
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-01 13:40 UTC by James Cowgill
Modified: 2018-04-05 16:46 UTC (History)
2 users (show)

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


Attachments
objects.tar.xz (1.76 MB, application/x-xz)
2018-02-01 13:40 UTC, James Cowgill
Details
patch from James Cowgill (1.96 KB, patch)
2018-04-05 14:57 UTC, Clint Adams
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Cowgill 2018-02-01 13:40:26 UTC
Created attachment 10767 [details]
objects.tar.xz

From:
https://bugs.debian.org/886222

The GOLD linker fails to link GHC on the 3 mips Debian architectures. Using the BFD linker works. It seems to fail in previous binutils versions as well so I don't think this is a regression.

The original link command is very large, but I have at least managed to get the input objects down to around 24MB worth of objects (attached). Ignore all the undefined references which come from missing objects I have removed.

Simply linking the objects together:
 ld objects/*

Gives:
> [...]
> Syntax.p_o:ghc_3.p_hc:function s1oJN_entry: error: undefined reference to 'base_GHCziShow_zdfShowZLz2cUz2cUZRzuzdsgo2_entry'
> Syntax.p_o:ghc_3.p_hc:function s1oMG_entry: error: undefined reference to 'base_GHCziShow_zdfShowZLz2cUz2cUZRzuzdsgo2_entry'
> Syntax.p_o:ghc_3.p_hc:function s1oMT_entry: error: undefined reference to 'base_GHCziShow_zdfShowZLz2cUz2cUZRzuzdsgo2_entry'
> ../../build-mips/gold/ld-new: internal error in get_got_page_offset, at ../../binutils-gdb/gold/mips.cc:6271
Comment 1 Clint Adams 2018-04-05 14:57:20 UTC
Created attachment 10936 [details]
patch from James Cowgill
Comment 2 Sourceware Commits 2018-04-05 15:49:12 UTC
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=67faf1f4c206516837fa44f6b7d131966be6bf0f

commit 67faf1f4c206516837fa44f6b7d131966be6bf0f
Author: James Cowgill <james.cowgill@mips.com>
Date:   Thu Apr 5 08:47:53 2018 -0700

    MIPS: Fix GOT page counter in multi-got links
    
    The record_got_page_entry function records and updates the maximum
    number of GOT page entries which may be required by an object. In the
    case where an existing GOT page entry was expanded, only the entry
    belonging to output GOT would have its page count updated. This leaves
    the entry belonging to the object GOT with the num_pages count of 1 it
    was originally initialized with. Later on when GOTs are being merged in a
    multi-got link, this causes the value of entry->num_pages in
    add_got_page_entries to always be 1 and underestimates the number of pages
    required for the new entry. This in turn leads to an assertion failure in
    get_got_page_offset where we run out of pages.
    
    Fix by obtaining the object's GOT entry unconditionally and not just
    the first time it gets created. Now that entry2 is always valid, remove
    the useless NULL checks.
    
    gold/
    	PR gold/22770
    	* mips.cc (Mips_got_info::record_got_page_entry): Fetch existing
    	page entries for the object's GOT.
Comment 3 Cary Coutant 2018-04-05 15:51:21 UTC
Fixed on master.
Comment 4 Sourceware Commits 2018-04-05 16:46:28 UTC
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=494e49c9855c75e5cf95a2c031401d2d4f5e21fe

commit 494e49c9855c75e5cf95a2c031401d2d4f5e21fe
Author: Cary Coutant <ccoutant@gmail.com>
Date:   Thu Apr 5 09:41:42 2018 -0700

    Revert previous patch and apply revised patch.
    
    Revert:
    
    2018-04-05  James Cowgill  <james.cowgill@mips.com>
    
    	PR gold/22770
    	* mips.cc (Mips_got_info::record_got_page_entry): Fetch existing
    	page entries for the object's GOT.
    
    Apply:
    
    	PR gold/22770
    	* mips.cc (Mips_got_info::record_got_page_entry): Don't insert
    	Got_page_entry for object's GOT.
    	(Mips_got_info::add_got_page_entries): Add all pages from from's GOT.
    	Rename to add_got_page_count.
    	(Got_page_entry): Remove num_pages.