Bug 14798 - gas mips target generates badly typed symbols
Summary: gas mips target generates badly typed symbols
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-02 04:03 UTC by Rich Felker
Modified: 2020-07-22 11:47 UTC (History)
0 users

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rich Felker 2012-11-02 04:03:33 UTC
Symptom: failure of -Bsymbolic-functions to resolve libgcc references at link-time under certain circumstances. In particular, Sabotage Linux (https://github.com/rofl0r/sabotage) ends up building a broken musl libc.so on MIPS; its dynamic linker attempts to call libgcc functions before symbolic relocations have been processed.

Cause: When gcc generates calls to libgcc functions for long division, etc., it adds a .globl directive to the output asm for those functions. This is entirely unnecessary, but should be harmless. However, the mips target for gas, upon seeing a .globl directive, adds OBJECT type to the undefined symbol reference unless there is a .type directive. On other targets, the type remains UNKNOWN. This in turn prevents the linker's -Bsymbolic-functions option from resolving the symbol reference at link-time. Assuming libgcc was compiled correctly with visibility, these functions have hidden visibility and thus they get resolved at link time anyway; however, if libgcc was built with --disable-shared, they don't.

Really, this bug is an interaction of 3 separate issues in 3 pieces of software:

1. gcc: outputting useless .globl
2. gas mips target: treating .globl as implying type==OBJECT
3. libgcc: failure to use visibility when --disable-shared is specified

I believe at least numbers 2 and 3, and maybe all three of them, should be fixed, but only 2 pertains to binutils.
Comment 1 Sourceware Commits 2019-05-20 18:09:34 UTC
The master branch has been updated by Faraz Shahbazker <farazs@sourceware.org>:

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

commit d87343802b81ad123a27beccb140d406f54727c6
Author: Faraz Shahbazker <fshahbazker@wavecomp.com>
Date:   Mon May 6 09:09:02 2019 -0700

    [MIPS] PR gas/14798: Limit IRIX5 specific default typing to IRIX targets
    
    On IRIX 5, every global symbol that is not explicitly labelled as
    being a function is assumed to be an object.  There is no reason
    why IRIX behaviour should extend to all MIPS targets, so limit this
    to only IRIX targets.
    
    gas/
    	PR 14798
    	* config/tc-mips.c (s_mips_globl): Only treat symbols that are
    	not explicitly labelled as BSF_OBJECTs for IRIX targets.
    	* testsuite/gas/mips/pr14798.s: New test source.
    	* testsuite/gas/mips/pr14798-irix.d: New test.
    	* testsuite/gas/mips/pr14798.d: Likewise.
    	* testsuite/gas/mips/mips.exp: Run the new tests.
    
    binutils/
    	PR 14798
    	* testsuite/binutils-all/readelf.ss-mips: Update reference output.
    	* testsuite/binutils-all/readelf.ss-tmips: Likewise.
    
    ld/
    	PR 14798
    	* testsuite/ld-mips-elf/reloc-6a.s: Specify .text section for
    	global code symbols.
    	* testsuite/ld-mips-elf/reloc-6b.s: Likewise.
Comment 2 Sourceware Commits 2020-07-22 11:47:33 UTC
The master branch has been updated by Maciej W. Rozycki <macro@sourceware.org>:

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

commit b83d958fc7050bf990d7c24596b9dcdc130433a7
Author: Maciej W. Rozycki <macro@linux-mips.org>
Date:   Wed Jul 22 12:46:00 2020 +0100

    MIPS/GAS/testsuite: Use a helper variable for IRIX/non-IRIX test selection
    
    Define a helper variable for IRIX/non-IRIX test selection and use it
    with the PR 14798 test case.
    
            gas/
            * testsuite/gas/mips/mips.exp: Use a helper variable for
            IRIX/non-IRIX test selection.