LinuxQuestions.org
Review your favorite Linux distribution.
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-16-2006, 12:27 PM   #1
dombrowsky
Member
 
Registered: Dec 2005
Location: New York
Distribution: Debian/GNU
Posts: 235

Rep: Reputation: 31
How to get local gcc to link with local glibc


I just finished compiling gcc with, I thought, my local build of glibc-2.3.6. However, the new compiler won't automatically link to the new libraries.
Observe ->

Code:
radish% which gcc
/usr/local/bin/gcc
radish% which ldd
/usr/glibc2/bin/ldd
radish% ldd `which gcc`
        libc.so.6 => /usr/glibc2/lib/libc.so.6 (0x40018000)
        /usr/glibc2/lib/ld-linux.so.2 (0x40000000)
radish% gcc test.c -o exec
radish% ldd exec
        libc.so.6 => /lib/libc.so.6 (0x40019000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
the output executable is still linked to the old linux loader. WTF? I can force it by passing "-Wl,--dynamic-linker=/usr/glibc2/lib/ld-linux.so.2" to it every single time I run gcc, but that's not really a solution. I know it's somehow a problem with how I compiled GCC. I tried cross-compiling gcc with /usr/glibc2 as the system root, but it fails at the stage one compiler, saying it can't find certain symbols which I can see in /usr/glibc2/lib/ld-linux.so.2, so I know that its not using the right loader either.

Any help will be very appreciated. They flat refused to help me on gcc bugzilla (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25794). I've been trying to get this working for weeks now and I'm starting to lose my nerve.

-dave
 
Old 01-16-2006, 02:39 PM   #2
dombrowsky
Member
 
Registered: Dec 2005
Location: New York
Distribution: Debian/GNU
Posts: 235

Original Poster
Rep: Reputation: 31
please please let there be someone who knows what I'm talking about. I just tried probably my 70th configuration and EVERY FREAKIN TIME it exits after compiling for about an hour with linker errors.

Code:
stage1/xgcc -Bstage1/ -B/usr/glibc2/i686-pc-linux-gnu/bin/   -O2 -g -fomit-frame-pointer -DIN_GCC   -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -pedantic -Wno-long-long -Wno-variadic-macros -Wold-style-definition     -DHAVE_CONFIG_H -DGENERATOR_FILE  -Wl,--dynamic-linker=/usr/glibc2/lib/ld-linux.so.2 -o build/genmodes \
 build/genmodes.o build/errors.o ../build-i686-pc-linux-gnu/libiberty/libiberty.a
/usr/glibc2/lib/libc.so.6: undefined reference to `_rtld_global@GLIBC_PRIVATE'
/usr/glibc2/lib/libc.so.6: undefined reference to `__libc_enable_secure@GLIBC_PRIVATE'
/usr/glibc2/lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
/usr/glibc2/lib/libc.so.6: undefined reference to `_dl_out_of_memory@GLIBC_PRIVATE'
/usr/glibc2/lib/libc.so.6: undefined reference to `_dl_argv@GLIBC_PRIVATE'
collect2: ld returned 1 exit status
make[2]: *** [build/genmodes] Error 1
make[2]: Leaving directory `/usr/home/davek/src/gcc-build/gcc'
make[1]: *** [stage2_build] Error 2
make[1]: Leaving directory `/usr/home/davek/src/gcc-build/gcc'
make: *** [bootstrap4] Error 2
And I even know that the stage1 compiler is using the new libs ->
Code:
$ ldd gcc/stage1/xgcc
        libc.so.6 => /usr/glibc2/lib/libc.so.6 (0x40018000)
        /usr/glibc2/lib/ld-linux.so.2 (0x40000000)
I'm on my last straw. I can't build a system if I can't build gcc.
 
Old 01-16-2006, 02:51 PM   #3
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
have you edited the gcc specs file? (/usr/local/lib/gcc-lib/*/*/specs)
 
Old 01-16-2006, 10:37 PM   #4
dombrowsky
Member
 
Registered: Dec 2005
Location: New York
Distribution: Debian/GNU
Posts: 235

Original Poster
Rep: Reputation: 31
radish% ls /usr/local/lib/gcc-lib
ls: /usr/local/lib/gcc-lib: No such file or directory
radish% find /usr/local -name specs
radish% find /usr/local -name \*specs\*
[noting]

I just installed a local build of gcc (using old libs). Perhaps I should use system gcc, but that's pretty old. I can't find the specs file for the local gcc.
 
Old 01-17-2006, 02:46 AM   #5
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
the command to find the specs file is:

Code:
gcc --print-file specs
( note that the gcc you built and installed has to be the first one in your path for this to work, if not, then you need to adjust your path. for example, if the newer gcc was installed in /usr/local and gcc is in /usr/local/bin:

Code:
export PATH=/usr/local/bin:$PATH
will make the one in /usr/local/bin the first one encountered when you enter the command gcc. also, what configure options did you pass when you built the new gcc?)

It would probably help if you stated what you are trying to accomplish, if you are building another system, it might help if you look here:

http://www.linuxfromscratch.org/lfs/view/stable/

it's probably not exactly what you want, but it has instructions on building a temporary toolchain used to build a linux system, linking against a fresh glibc build.

hope this helps.

Last edited by __J; 01-17-2006 at 02:50 AM.
 
Old 01-17-2006, 02:47 PM   #6
dombrowsky
Member
 
Registered: Dec 2005
Location: New York
Distribution: Debian/GNU
Posts: 235

Original Poster
Rep: Reputation: 31
that link looks very helpfull, thanks.

I've tried dozens of different configurations, and I always come up with linker errors. The only way I can get it to continue is to actually switch the makefile mid-build. I can't imagine that makes for a usable compiler.

I figured out that my gcc has compiled in specs. I just did "./configure ; make bootstrap" for the thing. I did a "gcc -dumpspecs", and I assume the important lines are:

*dynamic_linker:
/lib/ld-linux.so.2

and that should be /usr/glibc2/lib/ld-linux.so.2 (at least at compile time). I'm using the compiler flag -Wl,--dynamic-linker=/usr/glibc2/lib/ld-linux.so.2, but I still get unresolved symbols.

Last edited by dombrowsky; 01-17-2006 at 02:48 PM.
 
Old 01-17-2006, 11:50 PM   #7
dombrowsky
Member
 
Registered: Dec 2005
Location: New York
Distribution: Debian/GNU
Posts: 235

Original Poster
Rep: Reputation: 31
Got it to build this time, but the compiler won't work without hacking.

/home/davek/src/gcc-build/gcc/xgcc -Bgcc test.c
/usr/glibc2/lib/libc.so.6: undefined reference to `_rtld_global@GLIBC_PRIVATE'
/usr/glibc2/lib/libc.so.6: undefined reference to `__libc_enable_secure@GLIBC_PRIVATE'
/usr/glibc2/lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
/usr/glibc2/lib/libc.so.6: undefined reference to `_dl_out_of_memory@GLIBC_PRIVATE'
/usr/glibc2/lib/libc.so.6: undefined reference to `_dl_argv@GLIBC_PRIVATE'
collect2: ld returned 1 exit status

those symbols are defined in /usr/glibc2/lib/ld-linux.so.2. I know the compiler us using that as the linker, becuase it prints it in the specs. However, the executable is still linked to old libs.

$ ldd gcc/xgcc
libc.so.6 => /lib/libc.so.6 (0x40019000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

annoying. any help would be wonderful.
 
Old 01-18-2006, 12:48 AM   #8
dombrowsky
Member
 
Registered: Dec 2005
Location: New York
Distribution: Debian/GNU
Posts: 235

Original Poster
Rep: Reputation: 31
The compiler won't run without flags, for example ->

gcc -Wl,-rpath,/usr/glibc2/lib test.c

anyone know what I configured wrong? The tests won't pass if it has to pass those wierdo flags to it.

I also noticed something else. Observe ->

Code:
$ export LD_LIBRARY_PATH=/usr/glibc2/lib
$ gcc test.c
/usr/local/lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../i686-pc-linux-gnu/bin/as: /lib/ld-linux.so.2: version `GLIBC_PRIVATE' not found (required by /usr/glibc2/lib/libc.so.6)
isn't 'as' in binutils? Perhaps I should recompile binutils with new glibc first.
 
Old 01-20-2006, 12:34 AM   #9
dombrowsky
Member
 
Registered: Dec 2005
Location: New York
Distribution: Debian/GNU
Posts: 235

Original Poster
Rep: Reputation: 31
From reading the linux from scratch pages, I realize that I didn't understand something fundamental about the process. Rebuilding glibc is basically building a new system. You have to bootstrap it by first building
new tools with old libs and then new tools with the new libs. A much longer process than I thought....
 
Old 01-20-2006, 02:01 PM   #10
dombrowsky
Member
 
Registered: Dec 2005
Location: New York
Distribution: Debian/GNU
Posts: 235

Original Poster
Rep: Reputation: 31
SUCCESS!

$ gcc test.c
$ ldd a.out
libc.so.6 => /usr/glibc2/lib/libc.so.6 (0x40018000)
/usr/glibc2/lib/ld-linux.so.2 (0x40000000)
$ readelf -l a.out | grep lib
[Requesting program interpreter: /usr/glibc2/lib/ld-linux.so.2]

I now have a compiler which will automatically link to the new glibc libraries. My previous approach was actually correct, I was just doing things in the wrong order. In short, here's how to construct a new glibc system from sources:
  1. Compile binutils using old gcc
  2. Compile new gcc using bootstrap and old gcc
  3. Compile new glibc using new gcc
  4. recompile and install ld in binutils with LIB_PATH=/usr/glibc2
  5. recompile and install new gcc using new glibc. this is the hard part, it requires figuring out how to get gcc to link to the new libraries. In my system, I gcc compiled by default WITHOUT a specs file, so I had to change gcc/config/i386/linux.h to point to the new linker, then add LDFLAGS=-Wl,--dynamic-linker=/usr/glibc2/lib/ld-linux.so.2 . This is the part of the process which requires the most magic
  6. recompile and install binutils using new-linked gcc in /usr/glibc2
  7. take over world
 
  


Reply


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
Setup local machine to allow lan machines to retrieve its local user mail. Brian1 Linux - Networking 3 03-30-2006 05:04 AM
Local webserver -- How to deny all client install their local web server--Please help b:z Linux - Networking 13 04-16-2005 07:11 PM
gcc won't recognise local header files surio Linux - Software 0 09-10-2003 05:02 PM
IPv6 Link Local Multicast wirelessman Programming 1 11-19-2002 11:32 PM
IPv6 Link Local Multicast wirelessman Linux - Networking 0 11-19-2002 03:55 PM


All times are GMT -5. The time now is 07:16 AM.

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