mailing list of musl libc
 help / color / mirror / code / Atom feed
* musl-gcc question
@ 2012-09-20 14:50 Jens
  2012-09-20 16:00 ` Szabolcs Nagy
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jens @ 2012-09-20 14:50 UTC (permalink / raw)
  To: musl


Hello!

Looks like musl-gcc in my uclibc environment doesn't work correctly (for 
me):

bash-4.1# cat t.c
main()
{
 	printf("hejsan!\n");
}
bash-4.1# gcc -o t -static t.c
t.c: In function 'main':
t.c:3: warning: incompatible implicit declaration of built-in function 
'printf'
bash-4.1# musl-gcc -o m -static t.c
t.c: In function 'main':
t.c:3: warning: incompatible implicit declaration of built-in function 
'printf'
bash-4.1# ls -l t m
-rwxr-xr-x    1 0        0           17637 Sep 20 14:43 m
-rwxr-xr-x    1 0        0           17637 Sep 20 14:43 t
bash-4.1# cmp t m
bash-4.1#

If I try this:

bash-4.1# gcc -nostdinc -isystem /opt/musl/include -nostdlib 
-L/opt/musl/lib -o m /opt/musl/lib/crti.o  /opt/musl/lib/crtn.o 
/opt/musl/lib/Scrt1.o -lc -static t.c
t.c: In function 'main':
t.c:3: warning: incompatible implicit declaration of built-in function 
'printf'
bash-4.1# ls -l t m
-rwxr-xr-x    1 0        0           63217 Sep 20 14:44 m
-rwxr-xr-x    1 0        0           17637 Sep 20 14:43 t
bash-4.1# strip t m
bash-4.1# ls -l t m
-rwxr-xr-x    1 0        0            5152 Sep 20 14:44 m
-rwxr-xr-x    1 0        0            8424 Sep 20 14:44 t

Looks like 'm' is now actually build with musl.

If we look at the verbose output below it seems like -L/lib is a bad thing 
to have, since all the uclibc libs are there.

musl is installed under /opt/musl.

What have I missed?

I have tested musl-0.9.1 and musl-0.9.6.

Regards,
Jens

bash-4.1# musl-gcc -v -o m -static t.c
Invoked as gcc
Reference path: /bin/..
arg[ 0] = rawgcc
arg[ 1] = -nostdlib
arg[ 2] = -static
arg[ 3] = -Wl,-rpath-link,/bin/../lib
arg[ 4] = -L/bin/../lib
arg[ 5] = -L/bin/../gcc/lib
arg[ 6] = -nostdinc
arg[ 7] = -isystem
arg[ 8] = /bin/../include
arg[ 9] = -isystem
arg[10] = /bin/../gcc/include
arg[11] = -U__nptl__
arg[12] = /bin/../lib/crti.o
arg[13] = /bin/../gcc/lib/crtbeginT.o
arg[14] = /bin/../lib/crt1.o
arg[15] = -v
arg[16] = -o
arg[17] = m
arg[18] = -static
arg[19] = t.c
arg[20] = -specs
arg[21] = /opt/musl/lib/musl-gcc.specs
arg[22] = -lgcc
arg[23] = -lgcc_eh
arg[24] = -lc
arg[25] = -lgcc
arg[26] = -lgcc_eh
arg[27] = /bin/../gcc/lib/crtend.o
arg[28] = /bin/../lib/crtn.o
Using built-in specs.
Reading specs from /opt/musl/lib/musl-gcc.specs
rename spec cpp_options to old_cpp_options
Target: x86_64-unknown-linux
Configured with: 
/home/landley/firmware-0.9.6/build/temp-x86_64/gcc-core/configure 
--prefix=/home/landley/firmware-0.9.6/build/mini-native-x86_64/usr 
--disable-multilib --build=x86_64-walrus-linux --host=x86_64-unknown-linux 
--target=x86_64-unknown-linux --enable-long-long --enable-c99 
--enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-nls 
--enable-languages=c,c++ --disable-libstdcxx-pch --enable-sjlj-exceptions 
--program-prefix=
Thread model: posix
gcc version 4.1.2
  /usr/bin/../libexec/gcc/x86_64-unknown-linux/4.1.2/cc1 -quiet -nostdinc 
-v -iprefix /usr/bin/../lib/gcc/x86_64-unknown-linux/4.1.2/ -U__nptl__ 
-isystem /bin/../include -isystem /bin/../gcc/include t.c -nostdinc 
-isystem /opt/musl/include -quiet -dumpbase t.c -mtune=k8 -auxbase t 
-version -o /tmp/ccv5P4ov.s
#include "..." search starts here:
#include <...> search starts here:
  /bin/../include
  /bin/../gcc/include
  /opt/musl/include
End of search list.
GNU C version 4.1.2 (x86_64-unknown-linux)
 	compiled by GNU C version 4.1.2.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 02dced53fb1afdc2e565976e418928e8
t.c: In function 'main':
t.c:3: warning: incompatible implicit declaration of built-in function 
'printf'
  as --traditional-format -V -Qy -o /tmp/ccW901pW.o /tmp/ccv5P4ov.s
GNU assembler version 2.17 (x86_64-unknown-linux) using BFD version 2.17
  /usr/bin/../libexec/gcc/x86_64-unknown-linux/4.1.2/collect2 
-dynamic-linker /lib/ld-musl-x86_64.so.1 -nostdlib -static -o m 
-L/bin/../lib -L/bin/../gcc/lib -L/opt/musl/lib -L /lib/. -rpath-link 
/bin/../lib /bin/../lib/crti.o /bin/../gcc/lib/crtbeginT.o 
/bin/../lib/crt1.o /tmp/ccW901pW.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh 
/bin/../gcc/lib/crtend.o /bin/../lib/crtn.o



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: musl-gcc question
  2012-09-20 14:50 musl-gcc question Jens
@ 2012-09-20 16:00 ` Szabolcs Nagy
  2012-09-20 16:34   ` Jens
  2012-09-20 17:52 ` Szabolcs Nagy
  2012-09-20 18:14 ` Rich Felker
  2 siblings, 1 reply; 10+ messages in thread
From: Szabolcs Nagy @ 2012-09-20 16:00 UTC (permalink / raw)
  To: musl

* Jens <jensl@laas.mine.nu> [2012-09-20 16:50:13 +0200]:
> If we look at the verbose output below it seems like -L/lib is a bad
> thing to have, since all the uclibc libs are there.
> 
> musl is installed under /opt/musl.
> 
> What have I missed?


please show the config.mak you have

and the musl-gcc.specs file in the musl lib directory



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: musl-gcc question
  2012-09-20 16:00 ` Szabolcs Nagy
@ 2012-09-20 16:34   ` Jens
  0 siblings, 0 replies; 10+ messages in thread
From: Jens @ 2012-09-20 16:34 UTC (permalink / raw)
  To: musl



On Thu, 20 Sep 2012, Szabolcs Nagy wrote:

> * Jens <jensl@laas.mine.nu> [2012-09-20 16:50:13 +0200]:
>> If we look at the verbose output below it seems like -L/lib is a bad
>> thing to have, since all the uclibc libs are there.
>>
>> musl is installed under /opt/musl.
>>
>> What have I missed?
>
>
> please show the config.mak you have

Thanks, file contents below.
(Linewrapping has messed them up some).

bash-4.1# cat /var/tmp/src/musl-0.9.6/config.mak
# This version of config.mak was generated by configure
# Any changes made here will be lost if configure is re-run
ARCH = x86_64
prefix = /opt/musl
exec_prefix = $(prefix)
bindir = /usr/bin
libdir = $(prefix)/lib
includedir = $(prefix)/include
syslibdir = /lib
CC = gcc
CFLAGS= -pipe -fno-unwind-tables -fno-asynchronous-unwind-tables 
-falign-functions=1 -falign-labels=1 -falign-loops=1 -falign-jumps=1 
-fno-stack-protector -Os -g
CFLAGS_C99FSE = -std=c99 -nostdinc -ffreestanding -frounding-math
CPPFLAGS =
LDFLAGS = -Wl,--hash-style=both -static
CROSS_COMPILE =
LIBCC = -lgcc -lgcc_eh

>
> and the musl-gcc.specs file in the musl lib directory

bash-4.1# cat /opt/musl/lib/musl-gcc.specs
%rename cpp_options old_cpp_options

*cpp_options:
-nostdinc -isystem /opt/musl/include %(old_cpp_options)

*cc1:
%(cc1_cpu) -nostdinc -isystem /opt/musl/include

*link_libgcc:
-L/opt/musl/lib -L .%s

*libgcc:
libgcc.a%s %:if-exists(libgcc_eh.a%s)

*startfile:
%{!shared: /opt/musl/lib/%{pie:S}crt1.o} /opt/musl/lib/crti.o 
%{shared|pie:crtbeginS.o%s;:crtbegin.o%s}

*endfile:
%{shared|pie:crtendS.o%s;:crtend.o%s} /opt/musl/lib/crtn.o

*link:
-dynamic-linker /lib/ld-musl-x86_64.so.1 -nostdlib %{shared:-shared} 
%{static:-static} %{rdynamic:-export-dynamic}

*esp_link:


*esp_options:


*esp_cpp_options:




>
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: musl-gcc question
  2012-09-20 14:50 musl-gcc question Jens
  2012-09-20 16:00 ` Szabolcs Nagy
@ 2012-09-20 17:52 ` Szabolcs Nagy
  2012-09-20 18:14 ` Rich Felker
  2 siblings, 0 replies; 10+ messages in thread
From: Szabolcs Nagy @ 2012-09-20 17:52 UTC (permalink / raw)
  To: musl

* Jens <jensl@laas.mine.nu> [2012-09-20 16:50:13 +0200]:
> bash-4.1# musl-gcc -v -o m -static t.c
> Invoked as gcc
> Reference path: /bin/..
> arg[ 0] = rawgcc
> arg[ 1] = -nostdlib
> arg[ 2] = -static
> arg[ 3] = -Wl,-rpath-link,/bin/../lib
> arg[ 4] = -L/bin/../lib
> arg[ 5] = -L/bin/../gcc/lib
> arg[ 6] = -nostdinc
> arg[ 7] = -isystem
> arg[ 8] = /bin/../include
> arg[ 9] = -isystem
> arg[10] = /bin/../gcc/include
> arg[11] = -U__nptl__
> arg[12] = /bin/../lib/crti.o
> arg[13] = /bin/../gcc/lib/crtbeginT.o
> arg[14] = /bin/../lib/crt1.o
> arg[15] = -v
> arg[16] = -o
> arg[17] = m
> arg[18] = -static
> arg[19] = t.c
> arg[20] = -specs
> arg[21] = /opt/musl/lib/musl-gcc.specs
> arg[22] = -lgcc
> arg[23] = -lgcc_eh
> arg[24] = -lc
> arg[25] = -lgcc
> arg[26] = -lgcc_eh
> arg[27] = /bin/../gcc/lib/crtend.o
> arg[28] = /bin/../lib/crtn.o

now i see that gcc calls some rawgcc with extra arguments here

that may be a problem for musl-gcc

the spec file cant help if gcc already adds -nostdlib and -nostdinc
(then you already asked for a freestanding environment)

call rawgcc directly from musl-gcc
i think that should work


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: musl-gcc question
  2012-09-20 14:50 musl-gcc question Jens
  2012-09-20 16:00 ` Szabolcs Nagy
  2012-09-20 17:52 ` Szabolcs Nagy
@ 2012-09-20 18:14 ` Rich Felker
  2012-09-20 21:53   ` idunham
  2012-09-21 10:51   ` Jens
  2 siblings, 2 replies; 10+ messages in thread
From: Rich Felker @ 2012-09-20 18:14 UTC (permalink / raw)
  To: musl

On Thu, Sep 20, 2012 at 04:50:13PM +0200, Jens wrote:
> 
> Hello!
> 
> Looks like musl-gcc in my uclibc environment doesn't work correctly
> (for me):

Aboriginal Linux? The problem is that the underlying gcc is not gcc,
but Rob Landley's gcc wrapper which serves a similar purpose to
musl-gcc, but using the command line rather than spec files, so it
takes precedence. You need to either find a way to get musl-gcc to
call the underlying gcc, or build a native toolchain.

Rich


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: musl-gcc question
  2012-09-20 18:14 ` Rich Felker
@ 2012-09-20 21:53   ` idunham
  2012-09-20 22:04     ` Rich Felker
  2012-09-21 10:51   ` Jens
  1 sibling, 1 reply; 10+ messages in thread
From: idunham @ 2012-09-20 21:53 UTC (permalink / raw)
  To: musl

> On Thu, Sep 20, 2012 at 04:50:13PM +0200, Jens wrote:
>>
>> Hello!
>>
>> Looks like musl-gcc in my uclibc environment doesn't work correctly
>> (for me):
>
> Aboriginal Linux? The problem is that the underlying gcc is not gcc,
> but Rob Landley's gcc wrapper which serves a similar purpose to
> musl-gcc, but using the command line rather than spec files, so it
> takes precedence. You need to either find a way to get musl-gcc to
> call the underlying gcc, or build a native toolchain.

Rich, what would you think of changing from a hardcoded "gcc" to using
something along these lines:

[ -z "$REALGCC" ] && REALGCC=gcc
$REALGCC <the current parameters>

By setting REALGCC to rawgcc, Landley's toolchain could easily be used.
This would also help for using other cross-toolchains.
(note: I'm not particular about the variable, but $GCC might be a bad
choice: ISTR seeing one or two Makefiles that set that.)




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: musl-gcc question
  2012-09-20 21:53   ` idunham
@ 2012-09-20 22:04     ` Rich Felker
  2012-09-20 23:39       ` idunham
  0 siblings, 1 reply; 10+ messages in thread
From: Rich Felker @ 2012-09-20 22:04 UTC (permalink / raw)
  To: musl

On Thu, Sep 20, 2012 at 05:53:45PM -0400, idunham@lavabit.com wrote:
> > On Thu, Sep 20, 2012 at 04:50:13PM +0200, Jens wrote:
> >>
> >> Hello!
> >>
> >> Looks like musl-gcc in my uclibc environment doesn't work correctly
> >> (for me):
> >
> > Aboriginal Linux? The problem is that the underlying gcc is not gcc,
> > but Rob Landley's gcc wrapper which serves a similar purpose to
> > musl-gcc, but using the command line rather than spec files, so it
> > takes precedence. You need to either find a way to get musl-gcc to
> > call the underlying gcc, or build a native toolchain.
> 
> Rich, what would you think of changing from a hardcoded "gcc" to using
> something along these lines:
> 
> [ -z "$REALGCC" ] && REALGCC=gcc
> $REALGCC <the current parameters>
> 
> By setting REALGCC to rawgcc, Landley's toolchain could easily be used.
> This would also help for using other cross-toolchains.
> (note: I'm not particular about the variable, but $GCC might be a bad
> choice: ISTR seeing one or two Makefiles that set that.)

Have you tested if this works okay? If it's known to work, send a
clean patch and I think it should be okay to apply.

Rich


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: musl-gcc question
  2012-09-20 22:04     ` Rich Felker
@ 2012-09-20 23:39       ` idunham
  2012-09-21  4:54         ` Rich Felker
  0 siblings, 1 reply; 10+ messages in thread
From: idunham @ 2012-09-20 23:39 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 881 bytes --]

> On Thu, Sep 20, 2012 at 05:53:45PM -0400, idunham@lavabit.com wrote:
>> Rich, what would you think of changing from a hardcoded "gcc" to using
>> something along these lines:
>>
>> [ -z "$REALGCC" ] && REALGCC=gcc
>> $REALGCC <the current parameters>
>>
>> By setting REALGCC to rawgcc, Landley's toolchain could easily be used.
>> This would also help for using other cross-toolchains.
>> (note: I'm not particular about the variable, but $GCC might be a bad
>> choice: ISTR seeing one or two Makefiles that set that.)
>
> Have you tested if this works okay? If it's known to work, send a
> clean patch and I think it should be okay to apply.

That was off the top of my head, but it works.
Patch has been tested by building musl, then building my patched netbsd m4.
(I modified musl-gcc after installation to echo REALGCC).

Usage:
REALGCC=rawgcc make CC=musl-gcc

Isaac Dunham

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: realgcc.diff --]
[-- Type: text/x-patch; name="realgcc.diff", Size: 702 bytes --]

commit 01c16bf8f4e68c838994716e77bd254b86a989bc
Author: Isaac Dunham <idunham@lavabit.com>
Date:   Thu Sep 20 16:30:00 2012 -0700

    Allow REALGCC to set the compiler for musl-gcc to use

diff --git a/Makefile b/Makefile
index 10c174c..f62635d 100644
--- a/Makefile
+++ b/Makefile
@@ -112,7 +112,7 @@ lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
 	sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
 
 tools/musl-gcc: config.mak
-	printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
+	printf '#!/bin/sh\n[ -z "$$REALGCC" ] && REALGCC=gcc\nexec $$REALGCC "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
 	chmod +x $@
 
 $(DESTDIR)$(bindir)/%: tools/%

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: musl-gcc question
  2012-09-20 23:39       ` idunham
@ 2012-09-21  4:54         ` Rich Felker
  0 siblings, 0 replies; 10+ messages in thread
From: Rich Felker @ 2012-09-21  4:54 UTC (permalink / raw)
  To: musl

On Thu, Sep 20, 2012 at 07:39:46PM -0400, idunham@lavabit.com wrote:
> commit 01c16bf8f4e68c838994716e77bd254b86a989bc
> Author: Isaac Dunham <idunham@lavabit.com>
> Date:   Thu Sep 20 16:30:00 2012 -0700
> 
>     Allow REALGCC to set the compiler for musl-gcc to use
> 
> diff --git a/Makefile b/Makefile
> index 10c174c..f62635d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -112,7 +112,7 @@ lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
>  	sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
>  
>  tools/musl-gcc: config.mak
> -	printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
> +	printf '#!/bin/sh\n[ -z "$$REALGCC" ] && REALGCC=gcc\nexec $$REALGCC "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@

Slight optimization:

+	printf '#!/bin/sh\nexec $${REALGCC:-gcc} "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@

:)

Rich


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: musl-gcc question
  2012-09-20 18:14 ` Rich Felker
  2012-09-20 21:53   ` idunham
@ 2012-09-21 10:51   ` Jens
  1 sibling, 0 replies; 10+ messages in thread
From: Jens @ 2012-09-21 10:51 UTC (permalink / raw)
  To: musl



On Thu, 20 Sep 2012, Rich Felker wrote:

> On Thu, Sep 20, 2012 at 04:50:13PM +0200, Jens wrote:
>>
>> Hello!
>>
>> Looks like musl-gcc in my uclibc environment doesn't work correctly
>> (for me):
>
> Aboriginal Linux? The problem is that the underlying gcc is not gcc,
> but Rob Landley's gcc wrapper which serves a similar purpose to
> musl-gcc, but using the command line rather than spec files, so it
> takes precedence. You need to either find a way to get musl-gcc to
> call the underlying gcc, or build a native toolchain.

Thank you all for the help.
I got it working now. Its the mini-native chroot from uclibcs site Im 
working in, so its pretty old.

musl-gcc changed as suggested.

I had to change the specs-file also, but I suspect its my borkish 
environment thats at fault.
Basically I need to add /usr/gcc/lib/ so the linker could find the 
objectfiles. I tried but failed to get the linker to look into other 
directories, so I changed the spec-file instead.

Incase somebody else runs into this, the (linewrap broken) patch is 
below.

Thanks again,
Jens

--- opt/musl/lib/musl-gcc.specs.orig	Fri Sep 21 07:04:50 2012
+++ opt/musl/lib/musl-gcc.specs	Fri Sep 21 07:12:34 2012
@@ -10,13 +10,13 @@
  -L/opt/musl/lib -L .%s

  *libgcc:
-libgcc.a%s %:if-exists(libgcc_eh.a%s)
+/usr/gcc/lib/libgcc.a%s %:if-exists(/usr/gcc/lib/libgcc_eh.a%s)

  *startfile:
-%{!shared: /opt/musl/lib/%{pie:S}crt1.o} /opt/musl/lib/crti.o 
%{shared|pie:crtbeginS.o%s;:crtbegin.o%s}
+%{!shared: /opt/musl/lib/%{pie:S}crt1.o} /opt/musl/lib/crti.o 
%{shared|pie:crtbeginS.o%s;:/usr/gcc/lib/crtbegin.o%s}

  *endfile:
-%{shared|pie:crtendS.o%s;:crtend.o%s} /opt/musl/lib/crtn.o
+%{shared|pie:crtendS.o%s;:/usr/gcc/lib/crtend.o%s} /opt/musl/lib/crtn.o

  *link:
  -dynamic-linker /lib/ld-musl-i386.so.1 -nostdlib %{shared:-shared} 
%{static:-static} %{rdynamic:-export-dynamic}


>
> Rich
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-09-21 10:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-20 14:50 musl-gcc question Jens
2012-09-20 16:00 ` Szabolcs Nagy
2012-09-20 16:34   ` Jens
2012-09-20 17:52 ` Szabolcs Nagy
2012-09-20 18:14 ` Rich Felker
2012-09-20 21:53   ` idunham
2012-09-20 22:04     ` Rich Felker
2012-09-20 23:39       ` idunham
2012-09-21  4:54         ` Rich Felker
2012-09-21 10:51   ` Jens

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).