LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-11-2018, 09:43 AM   #1
Michele13
LQ Newbie
 
Registered: May 2018
Distribution: Debian Jessie 8.10 (x86_64)
Posts: 26

Rep: Reputation: 0
Question Create a static GCC Musl toolchain for ARM device


Hello Everybody! This is my first post, I hope you can help me.

I love a lot to compile things from source, and recentrly I've discovered the Musl libc library. I use it to cross-compile simple static binaries such as busybox, rsync, etc. Now I would like to cross-compile a static host-x-host compiler for arm. I'm using the following sources packages:

Binutils 2.30
GCC 7.3.0
GMP 6.1.2
MPC 1.1.0
MPFR 4.0.1
Linux 4.15.3
Musl (libc) 1.1.19

I've managed to build everything successfully, however when I try to build a C Program such as "Hello World" it outputs this error:

Code:
/home/michele/tmp/a.out:(.data+0x0): multiple definition of `__dso_handle'
/home/michele/tmp/toolchain/output/lib/gcc/arm-linux-musleabi/7.3.0/crtbegin.o:(.data+0x0): first defined here
/home/michele/tmp/a.out: In function `_init':
:(.init+0x0): multiple definition of `_init'
/home/michele/tmp/toolchain/output/lib/gcc/arm-linux-musleabi/7.3.0/../../../../arm-linux-musleabi/lib/crti.o:(.init+0x0): first defined here
/home/michele/tmp/a.out: In function `_start':
:(.text+0x0): multiple definition of `_start'
/home/michele/tmp/toolchain/output/lib/gcc/arm-linux-musleabi/7.3.0/../../../../arm-linux-musleabi/lib/crt1.o:crt1.c:(.text+0x0): first defined here
/home/michele/tmp/a.out: In function `_start_c':
:(.text+0x1c): multiple definition of `_start_c'
/home/michele/tmp/toolchain/output/lib/gcc/arm-linux-musleabi/7.3.0/../../../../arm-linux-musleabi/lib/crt1.o:crt1.c:(.text._start_c+0x0): first defined here
/home/michele/tmp/a.out: In function `main':
:(.text+0xe8): multiple definition of `main'
/tmp/ccegcMMo.o:hello.c:(.text+0x0): first defined here
/home/michele/tmp/a.out: In function `_fini':
:(.fini+0x0): multiple definition of `_fini'
/home/michele/tmp/toolchain/output/lib/gcc/arm-linux-musleabi/7.3.0/../../../../arm-linux-musleabi/lib/crti.o:(.fini+0x0): first defined here
/home/michele/tmp/toolchain/output/lib/gcc/arm-linux-musleabi/7.3.0/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
/home/michele/tmp/a.out::(.data+0x4): first defined here
/home/michele/tmp/toolchain/output/lib/gcc/arm-linux-musleabi/7.3.0/libgcc.a(_dvmd_lnx.o): In function `__aeabi_idiv0':
/home/michele/tmp/toolchain/tmp/build-gcc/arm-linux-musleabi/libgcc/../../../src/gcc/libgcc/config/arm/lib1funcs.S:1545: undefined reference to `raise'
collect2: error: ld returned 1 exit status

I have installed qemu-user-static and binfmt-support, this way I am able to run gcc. What could have I done wrong? Could someone instruct me to build a static relocatable native host-x-host cross-compiler for arm? It needs to run on armv6 (and beyond) with soft floating point.

I already have a cross-compiler, i've built it using the same package versions and it works. I'm using it to build this version of GCC

Thanks for the help

P.S feel free to correct my English, I usually don't pay too much attention on how I write when I post a topic because I'm too focused on my problem
 
Old 05-11-2018, 09:55 PM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
The second last line is what cause ld to fail. Can I look at the command line your using?
 
Old 05-12-2018, 02:16 AM   #3
Michele13
LQ Newbie
 
Registered: May 2018
Distribution: Debian Jessie 8.10 (x86_64)
Posts: 26

Original Poster
Rep: Reputation: 0
Create Sysroot directory
Code:
mkdir -p /home/michele/tmp/toolchain/output/arm-linux-musleabi/
ln -s . /home/michele/tmp/toolchain/output/arm-linux-musleabi/usr
Linux Headers
Code:
make mrproper
ARCH=arm make headers_check
ARCH=arm make INSTALL_HDR_PATH=/home/michele/tmp/toolchain/output/arm-linux-musleabi/ headers_install
Musl Libc
Inside the Musl Libc folder I run:

Code:
./configure --target=arm-linux-musleabi --disable-shared --prefix=/
make
make DESTDIR=/home/michele/tmp/toolchain/output/arm-linux-musleabi/usr install
Now I export some variables to make binutils and GCC static.

Code:
export CC="arm-linux-musleabi-gcc -static -Wl,-Bstatic -static-libgcc
export CXX="arm-linux-musleabi-g++ -static -Wl,-Bstatic -static-libgcc
Binutils
Code:
../src/binutils/configure --host=arm-linux-musleabi --target=arm-linux-musleabi --build=x86_64-linux-gnu --prefix=/home/michele/tmp/toolchain/output --disable-nls --disable-multilib --disable-shared
make
make install
GCC
Code:
../src/gcc/configure --host=arm-linux-musleabi --target=arm-linux-musleabi --build=x86_64-linux-gnu --enable-languages=c,c++ --disable-nls --disable-multilib --disable-libsanitizer --disable-shared --disable-libmudflap --prefix=/home/michele/tmp/toolchain/output/ --with-arch=armv7 --with-float=soft
make
make install
Yes, I've disabled shared libraries so all the programs that will be compiled by the final compiler will be static
 
Old 05-13-2018, 03:29 PM   #4
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
It's helpful that you posted all that stuff, but which command gives you the error in the first post? ld is the linker. So, something is looking for a library.

Last edited by AwesomeMachine; 05-13-2018 at 03:30 PM.
 
Old 05-13-2018, 04:43 PM   #5
Michele13
LQ Newbie
 
Registered: May 2018
Distribution: Debian Jessie 8.10 (x86_64)
Posts: 26

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by AwesomeMachine View Post
which command gives you the error in the first post?
Code:
./gcc ~/hello.c -o ~/tmp/hello.arm
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gcc / musl build fails. ispgardner Linux From Scratch 2 08-03-2017 05:25 PM
Final Phase GCC build fails for ARM cross compiler toolchain bencpeters Linux - Embedded & Single-board computer 1 11-13-2011 05:23 PM
Error: Failed to create bootstrap : Requires qemu-arm-static version >= 0.13 for armv wasim@teleca Linux - Newbie 5 09-28-2011 04:23 AM
Trouble with build and install GCC-toolchain for ARM _oligarch Programming 2 04-26-2009 11:03 PM
GNU ToolChain for ARM, Linux 2.6.14-2/binutil-2.16/gcc 4.0.2/glibc-2.3.5 kumar_bst Linux - Software 0 01-22-2008 04:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration