Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu, 23 Aug 2012 13:53:18 +0600
From: agent <agentprog@...il.com>
To: musl@...ts.openwall.com
Subject: build musl with clang

i am trying to build musl with clang 3.0 from ubuntu 12.04. musl itself 
builds fairly fine with some notes on unused command line parameters and 
coding style. but i have some issues compiling a simple hello world 
program against this musl. the code is:

#include <stdio.h>

int main(int argc, char **argv) {
     printf("Hello, World!\n");
     return 0;
}

i have tried to link against musl both dynamically and statically. if i 
compile a program with the default ld-linux.so dynamic linker the 
program runs but fails at the end:

Hello, World!
Inconsistency detected by ld.so: dl-fini.c: 207: _dl_fini: Assertion `ns 
!= 0 || i == nloaded' failed!

if i use musl's ld-musl (as far as i can notice it is just symlink to 
libc.so) i get a segfault. gdb says:

(gdb) r
Starting program: /home/agent/dev/musl/musl-0.9.4_clang/lib/t.out

Program received signal SIGSEGV, Segmentation fault.
0xb7f9d73a in find_sym () from /lib/ld-musl-i386.so.1
(gdb) where
#0  0xb7f9d73a in find_sym () from /lib/ld-musl-i386.so.1

btw, exactly the same things happen when i try it with gcc (4.6.3 from 
ubuntu).

if i compile statically with gcc the program works fine, but with clang 
it even does not compile (i mean link):

/opt/musl-clang/lib/libc.a(vfprintf.o): In function `printf_core':
src/stdio/vfprintf.c:(.text+0x1088): undefined reference to `__udivdi3'
src/stdio/vfprintf.c:(.text+0x10a6): undefined reference to `__umoddi3'
/opt/musl-clang/lib/libc.a(vfprintf.o): In function `fmt_u':
src/stdio/vfprintf.c:(.text+0x1a11): undefined reference to `__udivdi3'
src/stdio/vfprintf.c:(.text+0x1a33): undefined reference to `__umoddi3'
clang: error: linker command failed with exit code 1 (use -v to see 
invocation)

i suppose those functions do not get into libc.a for some reason, but 
they are in libc.so according to readelf.

my clang command lines:
dynamic link:

clang -Wall -nostdlib -nostdinc -Wl,-dynamic-linker 
/lib/ld-musl-i386.so.1 -L/opt/musl-clang/lib -isystem 
/opt/musl-clang/include/ /opt/musl-clang/lib/crt1.o 
/opt/musl-clang/lib/crti.o t.c /opt/musl-clang/lib/crtn.o -o t.out -lc

static link:
clang -Wall -nostdlib -nostdinc -L/opt/musl-clang/lib -isystem 
/opt/musl-clang/include/ /opt/musl-clang/lib/crt1.o 
/opt/musl-clang/lib/crti.o t.c /opt/musl-clang/lib/crtn.o -o t.out 
-static -lc

as far as i can see, musl do not provide crtbegin.o and crtend.o, clang 
do not have it's own and if i add gcc's ones situation does not change.

maybe i am wrong with clang parameters (i based them on gcc spec 
provided), maybe it is impossible to compile a working musl with clang 
at this stage, maybe a quick fix can be applied (:

PS: sorry for so long message -- i'd like to be maximum verbose
PPS: and sorry for duplicates if any -- i didn't find any search on 
mainling list archive

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.