You are not logged in.

#1 2018-08-13 01:06:46

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

[SOLVED] musl-gcc cannot build functional executables

I just spent a while struggling to figure out why my busybox builds were failing to run - the static binary segfaults upon startup (strace confirms it is *immediate* right after the exec).

I then tried building another of my tools for which I've been using musl, and it failed to even build without the -static flag, and with the -static flag in produced a binary that similarly seg faulted immediately upon start up.  I was able to replicate the symptoms with the following minimal code:

#include <stdio.h>

int main() {
	printf("hello world\n");
	return 0;
}

Attempting to compile with `musl-gcc -o hello hello.c` produces the following:

/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/crtbegin.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a PIE object
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status

The build itself succeeds when -static is used (as there is no ld step, I gather) but the resulting binary segfaults immediately:

$ strace ./hello
execve("./hello", ["./hello"], 0x7fff219031e0 /* 27 vars */) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x400040} ---
+++ killed by SIGSEGV (core dumped) +++
Segmentation fault (core dumped)

I have not yet tracked down which upgrades causes this problem, but I suspect the recent changes to gcc may be related.  I have previously-compiled static binaries from March 31 which work fine, so the problem has been since then, and the musl package in the repos has not been updated in that time frame.  Gcc has been updated, and while I haven't followed the details I think there have recently been substantial changes in it.  Could musl itself need a rebuild with the current gcc?

I tried musl-git from the aur and that builds dynamic executables successfully, but static builds still segfault.

I've also tried rebuilding the stable musl using the PKGBUILD from [community], but that results in the exact same conditions as the version currently in the repos (i.e., a rebuild of the current stable code does not help).

Another potentially relevant data point: musl-clang does not give the relocation build errors for dynamic builds, but the static build still immediately segfaults upon running.

Last edited by Trilby (2018-08-13 13:46:45)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#2 2018-08-13 11:10:48

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED] musl-gcc cannot build functional executables

You'll need to update binutils, see https://bugs.archlinux.org/task/59540

The needed version should be out of testing since 17 hours ago.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3 2018-08-13 12:15:07

foutrelis
Developer
From: Athens, Greece
Registered: 2008-07-28
Posts: 705
Website

Re: [SOLVED] musl-gcc cannot build functional executables

Eschwartz wrote:

You'll need to update binutils, see https://bugs.archlinux.org/task/59540

And for dynamic linking, one will also need musl 1.1.19-2.

Offline

#4 2018-08-13 13:47:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [SOLVED] musl-gcc cannot build functional executables

Perfect, thanks.  I just updated again this morning and got the new binutils and musl rebuild and all is well again.

Sorry I missed the relevant bug report(s) - I was searching for bugs against musl.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB