LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to get local gcc to link with local glibc (https://www.linuxquestions.org/questions/linux-software-2/how-to-get-local-gcc-to-link-with-local-glibc-404087/)

dombrowsky 01-16-2006 12:27 PM

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

dombrowsky 01-16-2006 02:39 PM

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.

__J 01-16-2006 02:51 PM

have you edited the gcc specs file? (/usr/local/lib/gcc-lib/*/*/specs)

dombrowsky 01-16-2006 10:37 PM

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.

__J 01-17-2006 02:46 AM

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.

dombrowsky 01-17-2006 02:47 PM

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.

dombrowsky 01-17-2006 11:50 PM

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.

dombrowsky 01-18-2006 12:48 AM

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.

dombrowsky 01-20-2006 12:34 AM

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....

dombrowsky 01-20-2006 02:01 PM

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


All times are GMT -5. The time now is 01:48 PM.