Bug 23856 - Executables linked with gold against musl segfault at startup
Summary: Executables linked with gold against musl segfault at startup
Status: UNCONFIRMED
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-11-04 11:53 UTC by Niklas Hambüchen
Modified: 2023-02-14 05:34 UTC (History)
6 users (show)

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 Niklas Hambüchen 2018-11-04 11:53:55 UTC
Hey,

we're trying to link (dynamically) some executables against musl with gold.

When we link with GNU ld, everything works fine, but with gold the executables segfault at startup.

Version:

   GNU gold (GNU Binutils 2.30) 1.15

We strongly suspect that it is the issue described in here:

    https://www.openwall.com/lists/musl/2015/05/01/5

Quote:

    The problem is that gold does not know how to process relocations for
    undefined weak references correctly. When the code in question is
    PIC/PIE, the weak reference can be kept for resolving at runtime.
    Instead of:

      804846f:     b8 70 83 04 08          mov    $0x8048370,%eax

    where the linker filled in a fixed address (the PLT slot) which the
    code happily sees is non-zero and then calls it, PIC code would read
    the address from the GOT. In non-PIC code, the linker (ld) *MUST*
    resolve undefined weak references to the address zero; they are not
    overridable at runtime because non-PIC doesn't support that.

    This is a bug in gold, but I have no idea how it works at all, even
    with glibc. The same issue should arise in gcc's crt files.

    You can probably work around it for now by building the app as PIE.

Here the musl author suggests that it's a bug in gold, but from what I can tell, an issue was never filed, so I'm taking on that task now.

What is your take on this issue?

Is this something that you think gold should support, or is this a feature intentionally left out (or maybe something else is at play)?

Thanks a lot!
Comment 1 Niklas Hambüchen 2018-11-04 11:54:17 UTC
This was found as part of https://github.com/NixOS/nixpkgs/issues/49071
Comment 2 Rasmus Thomsen 2019-06-07 20:56:44 UTC
Hello,

FWIW I've hit this on Alpine too and adding `-fPIE` to CFLAGS does indeed fix his.