[LLVMdev] Customize Standard C Library Using LLVM (to support llvm backend optimization)

Jonathan Roelofs jonathan at codesourcery.com
Thu Mar 12 08:49:35 PDT 2015



On 3/12/15 9:16 AM, Chao Yan wrote:
>
> 2015-03-11 16:22 GMT-05:00 Richard Gorton
> <rcgorton at cognitive-electronics.com
> <mailto:rcgorton at cognitive-electronics.com>>:
>
>     I can confirm that musl builds and works correctly with clang/llvm.
>     We are using musl as a libc for our architecture.
>     It has a much smaller code footprint than newlib or glibc.
>
>
>
> I successfully cross-compile the must-libc using clang, with the
> configuration:
>
> C=clang CFLAGS=--target=arm-none-linux-gnueabi\
> --sysroot=/usr/local/arm-2009q\ -I\
> /usr/local/arm-2009q3/arm-none-linux-gnueabi/libc/usr/include/ LIBCC=
> ./configure --target=arm
>
> But how to force clang  to use musl-libc rather than its default one? I
> tried
>
> clang --target arm-none-linux-gnueabi -nostdlib -static hello.c
> ~/research/musl-1.1.6/lib/crt1.o ~/research/musl-1.1.6/lib/crti.o
> ~/research/musl-1.1.6/lib/crtn.o -I ~/research/musl-1.1.6/include/ -L
> ~/research/musl-1.1.6/lib/ -L
> /usr/local/arm-2009q3/lib/gcc/arm-none-linux-gnueabi/4.4.1/ -lc -lgcc
> -lgcc_eh
>
> clang complaint:
>
> /usr/local/arm-2009q3/bin/arm-none-linux-gnueabi-ld: warning: library
> search path "/lib/../lib" is unsafe for cross-compilation
> /usr/local/arm-2009q3/bin/arm-none-linux-gnueabi-ld: warning: library
> search path "/usr/lib/../lib" is unsafe for cross-compilation
> /usr/local/arm-2009q3/bin/arm-none-linux-gnueabi-ld: warning: library
> search path "/lib" is unsafe for cross-compilation
> /usr/local/arm-2009q3/bin/arm-none-linux-gnueabi-ld: warning: library
> search path "/usr/lib" is unsafe for cross-compilation
You need to build a sysroot from the lib and include directories in 
~/research/musl-1.1.6 combined with the same folders from 
/usr/local/arm-2009q, then use `--sysroot` instead of the `-I`s and `-L's.
> /home/yanchao/research/musl-1.1.6/lib//libc.a(__libc_start_main.o): In
> function `__libc_start_main':
> src/env/__libc_start_main.c:(.text+0x30): undefined reference to
> `__aeabi_memset'
> /home/yanchao/research/musl-1.1.6/lib//libc.a(vfprintf.o): In function
> `vfprintf':
> src/stdio/vfprintf.c:(.text+0x28): undefined reference to `__aeabi_memset'
> /usr/local/arm-2009q3/lib/gcc/arm-none-linux-gnueabi/4.4.1//libgcc.a(_dvmd_lnx.o):
> In function `__aeabi_ldiv0':
> (.text+0x8): undefined reference to `raise'
> /usr/local/arm-2009q3/lib/gcc/arm-none-linux-gnueabi/4.4.1//libgcc_eh.a(unwind-arm.o):
> In function `unwind_phase2':
> unwind-arm.c:(.text+0xae4): undefined reference to `abort'
> /usr/local/arm-2009q3/lib/gcc/arm-none-linux-gnueabi/4.4.1//libgcc_eh.a(unwind-arm.o):
> In function `__gnu_Unwind_Resume':
> unwind-arm.c:(.text+0xbe8): undefined reference to `abort'
> unwind-arm.c:(.text+0xc10): undefined reference to `abort'
> /usr/local/arm-2009q3/lib/gcc/arm-none-linux-gnueabi/4.4.1//libgcc_eh.a(pr-support.o):
> In function `_Unwind_GetTextRelBase':
> pr-support.c:(.text+0x4): undefined reference to `abort'
> /usr/local/arm-2009q3/lib/gcc/arm-none-linux-gnueabi/4.4.1//libgcc_eh.a(pr-support.o):
> In function `_Unwind_GetDataRelBase':
> pr-support.c:(.text+0xc): undefined reference to `abort'
>
> Regards,
> Chao
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-- 
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded



More information about the llvm-dev mailing list