Mailing List Archive

musl: static-linking fails with crossdev built toolchain
Hi,

I've been trying to build a musl based cross-compilation toolchain for
building static packages. With:

CFLAGS="-O2 -pipe" crossdev -s4 -t armv7a-hardfloat-linux-musleabi

I get a *working* toolchain, with which i can build dynamically linked
executables, but static linking of libc fails. For example, the simple
C program

#include <stdio.h>
int main()
{
puts("hello");
}

gives:

$ armv7a-hardfloat-linux-musleabi-gcc main.c -static
/usr/libexec/gcc/armv7a-hardfloat-linux-musleabi/ld: skipping
incompatible /usr/armv7a-hardfloat-linux-musleabi/usr/lib/libc.a when
searching for -lc
/usr/libexec/gcc/armv7a-hardfloat-linux-musleabi/ld: skipping
incompatible /usr/armv7a-hardfloat-linux-musleabi/usr/lib/libc.a when
searching for -lc
/usr/libexec/gcc/armv7a-hardfloat-linux-musleabi/ld: cannot find -lc

I'm trying to track down what could be causing this, but so far
haven't found anything (tried disabling PIE but same result). The
crossdev toolchain uses musl 1.1.17, gcc 6.4.0 and binutils 2.29.1-r1.

Any help would be appreciated. Thanks.
Jeremi
Re: musl: static-linking fails with crossdev built toolchain [ In reply to ]
On 10/27/17 3:27 PM, Jeremi Piotrowski wrote:
> Hi,
>
> I've been trying to build a musl based cross-compilation toolchain for
> building static packages. With:
>
> CFLAGS="-O2 -pipe" crossdev -s4 -t armv7a-hardfloat-linux-musleabi
>
> I get a *working* toolchain, with which i can build dynamically linked
> executables, but static linking of libc fails. For example, the simple
> C program
>
> #include <stdio.h>
> int main()
> {
> puts("hello");
> }
>
> gives:
>
> $ armv7a-hardfloat-linux-musleabi-gcc main.c -static
> /usr/libexec/gcc/armv7a-hardfloat-linux-musleabi/ld: skipping
> incompatible /usr/armv7a-hardfloat-linux-musleabi/usr/lib/libc.a when
> searching for -lc
> /usr/libexec/gcc/armv7a-hardfloat-linux-musleabi/ld: skipping
> incompatible /usr/armv7a-hardfloat-linux-musleabi/usr/lib/libc.a when
> searching for -lc
> /usr/libexec/gcc/armv7a-hardfloat-linux-musleabi/ld: cannot find -lc
>
> I'm trying to track down what could be causing this, but so far
> haven't found anything (tried disabling PIE but same result). The
> crossdev toolchain uses musl 1.1.17, gcc 6.4.0 and binutils 2.29.1-r1.
>
> Any help would be appreciated. Thanks.
> Jeremi

I know its not what you are trying to do, but do you know if the
stage3's in experitmental/arm/musl have the same problem?

--
Anthony G. Basile, Ph.D.
Gentoo Linux Developer [Hardened]
E-Mail : basile@freeharbor.net
GnuPG FP : 1FED FAD9 D82C 52A5 3BAB DC79 9384 FA6E F52D 4BBA
GnuPG ID : F52D4BBA
Re: musl: static-linking fails with crossdev built toolchain [ In reply to ]
On Sat, Oct 28, 2017 at 01:17:57PM -0400, Anthony G. Basile wrote:
>
> I know its not what you are trying to do, but do you know if the
> stage3's in experitmental/arm/musl have the same problem?
>

I do not have the same issue with the stage3's in experimental/arm/musl -
those allow static linking without issues. But I debugged further and
found the issue: the ebuild uses the wrong strip command (host one) when
stripping the built cross-musl. This makes it bug #552616 and I should
have found it sooner because there are lots of messages like the following
in the build-log:

x86_64-pc-linux-gnu-strip: Unable to recognise the format of the input file `/var/tmp/portage/cross-armv7a-hardfloat-linux-musleabi/musl-1.1.16/image/usr/armv7a-hardfloat-linux-musleabi/usr/lib/libc.a(cabs.o)'

For now I solved the issue with RESTRICT="strip" but manual stripping
similar to glibc probably should be added at some point.

There's also another issue with the ebuild and cross-compiling: the
getconf/getent/iconv tools get built before a libc is available and so
fail to compile. They shouldn't even be built when cross-compiling,
because there's a check in src_install to prevent them from being
installed. Below is my patch to the ebuild to make things work. Would be
nice to atleast get the src_compile() part commited.
Re: musl: static-linking fails with crossdev built toolchain [ In reply to ]
On 10/31/17 9:36 AM, Jeremi Piotrowski wrote:
> On Sat, Oct 28, 2017 at 01:17:57PM -0400, Anthony G. Basile wrote:
>> I know its not what you are trying to do, but do you know if the
>> stage3's in experitmental/arm/musl have the same problem?
>>
> I do not have the same issue with the stage3's in experimental/arm/musl -
> those allow static linking without issues. But I debugged further and
> found the issue: the ebuild uses the wrong strip command (host one) when
> stripping the built cross-musl. This makes it bug #552616 and I should
> have found it sooner because there are lots of messages like the following
> in the build-log:
>
> x86_64-pc-linux-gnu-strip: Unable to recognise the format of the input file `/var/tmp/portage/cross-armv7a-hardfloat-linux-musleabi/musl-1.1.16/image/usr/armv7a-hardfloat-linux-musleabi/usr/lib/libc.a(cabs.o)'
>
> For now I solved the issue with RESTRICT="strip" but manual stripping
> similar to glibc probably should be added at some point.
>
> There's also another issue with the ebuild and cross-compiling: the
> getconf/getent/iconv tools get built before a libc is available and so
> fail to compile. They shouldn't even be built when cross-compiling,
> because there's a check in src_install to prevent them from being
> installed. Below is my patch to the ebuild to make things work. Would be
> nice to atleast get the src_compile() part commited.
>
I'm not going to add RESTRICT="strip".? Do that locally.? The rest is
okay.? I'll add it to 1.1.18.

--
Anthony G. Basile, Ph.D.
Gentoo Linux Developer [Hardened]
E-Mail : basile@freeharbor.net
GnuPG FP : 1FED FAD9 D82C 52A5 3BAB DC79 9384 FA6E F52D 4BBA
GnuPG ID : F52D4BBA