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.
The master branch has been updated by Faraz Shahbazker <email@example.com>:
Author: Faraz Shahbazker <firstname.lastname@example.org>
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.
* 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.
* testsuite/binutils-all/readelf.ss-mips: Update reference output.
* testsuite/binutils-all/readelf.ss-tmips: Likewise.
* testsuite/ld-mips-elf/reloc-6a.s: Specify .text section for
global code symbols.
* testsuite/ld-mips-elf/reloc-6b.s: Likewise.