LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 01-29-2013, 11:07 AM   #1
prushik
Member
 
Registered: Mar 2009
Location: South Korea
Distribution: Lubuntu, BetterLinux
Posts: 364

Rep: Reputation: 28
gcc toolchain works but dynamically linked executables won't run (without help)


I built a working cross compilation toolchain with binutils, gcc, and musl-libc based on modified lfs book instructions. I compiled busybox with it and all went well, but I linked it statically. I compiled a few other important programs and linked them statically as well. now I have enough cross compiled sw to chroot into.
However, I want to now executables which will be dynamically linked. so I gave it a shot using normal cross compilation methods and it made an executable, but after moving the executable to the target fs, i can't run it normally.
However, in musl-libc, the c library acts as the dynamic loader, so i symlinked ld.so to libc.so and now I can run executables by typing "/lib/ld.so <exe name>".
This is all fine and good, but wont work for bigger executables which need to run other dynamically linked executables.
objdump shows executables are linked only to libgcc_s.so.1 and libc.so
What should I do?
 
Old 01-30-2013, 06:54 AM   #2
business_kid
Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 6,289

Rep: Reputation: 543Reputation: 543Reputation: 543Reputation: 543Reputation: 543Reputation: 543
Quote:
based on modified lfs book instructions.
There, I think is your problem. We really don't know what you've done. Are they elf executables? There's paths hardcoded into gcc somewhere. I would go very close to the clfs book instructions, because headscratching has gone into every line in there. To sort you out, we would need a link to what you did exactly. What does ldd show?
 
Old 01-30-2013, 08:24 AM   #3
prushik
Member
 
Registered: Mar 2009
Location: South Korea
Distribution: Lubuntu, BetterLinux
Posts: 364

Original Poster
Rep: Reputation: 28
Quote:
Originally Posted by business_kid View Post
There, I think is your problem. We really don't know what you've done. Are they elf executables? There's paths hardcoded into gcc somewhere. I would go very close to the clfs book instructions, because headscratching has gone into every line in there. To sort you out, we would need a link to what you did exactly. What does ldd show?
Well actually, in reality, what I did was more like this: http://www.ifp.illinois.edu/~nakazato/tips/xgcc.html
I built minimal binutils and gcc using lfs book instructions to adjust gcc to look for libraries in /tools, then installed kernel headers in /tools/include, then used those newly built binutils and gcc to build musl-libc which I dropped that into /tools, then built binutils and gcc again (with the host compiler) so that they are aware of the new headers and libraries.
/tools is actually bound from /media/lfs/tools.

output of ldd:
My (host) ldd says "invalid elf header" which is expected since the executable is not linked with glibc.
Musl ldd (symlinked to /lib/libc.so) gives this output:
Code:
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x7f0928f81000)
when run with a valid dynamically linked executable
 
Old 01-31-2013, 04:05 AM   #4
business_kid
Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 6,289

Rep: Reputation: 543Reputation: 543Reputation: 543Reputation: 543Reputation: 543Reputation: 543
What you did sounds OK. You have basically replaced glibc with musl-libc on your system.

Unless your host system is also running musl-libc, you must stop cross compiling at that point and compile on musl-libc boxes only, and preferably on the target. Beware also that certain paths are hardcoded at build time into gcc. If you check the gcc pages in the hlfs book, they go adjusting the specs file in gcc and have some interesting tests for what they were trying to do.
 
Old 01-31-2013, 08:56 PM   #5
prushik
Member
 
Registered: Mar 2009
Location: South Korea
Distribution: Lubuntu, BetterLinux
Posts: 364

Original Poster
Rep: Reputation: 28
Quote:
Originally Posted by business_kid View Post
What you did sounds OK. You have basically replaced glibc with musl-libc on your system.

Unless your host system is also running musl-libc, you must stop cross compiling at that point and compile on musl-libc boxes only, and preferably on the target. Beware also that certain paths are hardcoded at build time into gcc. If you check the gcc pages in the hlfs book, they go adjusting the specs file in gcc and have some interesting tests for what they were trying to do.
Well that's what I want to do. but I need to compile GCC and binutils for the target, which works fine, but gcc and binutils executables themselves are dynamically linked and won't run without explicitly calling the loader on the command line. Which will fail if I try to do any compilation because gcc will call subprocesses which are also dynamically linked.
Right?


EDIT: OK, I think I found the problem. When I configured musl, I think I should have added --syslubdir=/tools/lib, so it looks in the wrong place for the dynamic loader

Last edited by prushik; 01-31-2013 at 09:01 PM.
 
Old 02-01-2013, 10:25 AM   #6
prushik
Member
 
Registered: Mar 2009
Location: South Korea
Distribution: Lubuntu, BetterLinux
Posts: 364

Original Poster
Rep: Reputation: 28
Ok, well that wasn't exactly the problem, but I was on the right track. I got it working, though I am still confused a bit. Essentially, I started over. I built musl-libc for my host system, and installed it at /opt/musl, then used its gcc wrapper script to cross compile binutils, musl and gcc and installed those in the target. now at least my target has a native compiler (I just verified that the executables run, not that the native toolchain is sane).
 
  


Reply

Tags
cross-compile, dynamic linking, dynamic loading, gcc, musl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to display static libraries linked in executables ? anctop Linux - General 6 04-14-2012 11:46 PM
What's the difference between static and dynamically linked library... trist007 Linux - Newbie 5 09-19-2010 08:40 PM
[SOLVED] g++ dynamically linked library not being found posop Programming 6 04-14-2010 03:20 PM
Dynamically linked libraries.. vishalbutte Programming 6 04-17-2006 08:54 PM


All times are GMT -5. The time now is 12:36 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration