GCC not finding runtime files under my OS
Posted: Tue Feb 09, 2016 12:59 pm
I had binutils ported and fully functional under my OS for quite some time, so after some playing around, I managed to build GCC to run natively on my OS, with canonical name x86_64-glidix.
I successfully built it and installed under my OS, so I decided to run a compile the trivial "hello world" C program. If I run:
It successfully creates hello.o without problems, and I can even link it into an executable manually (by running "ld" etc). However, if I try to link using "gcc", it fails to find the runtime files (crt0.o, crtbegin.o, etc). "crtbegin" is actually located in the GCC library directories, while the rest are located under /lib. Also, it says it cannot read "libgcc.a". Here is the full verbose output (undex glidix):
The verbose output looks quite different when I run the cross-compiler under Linux (targetting Glidix):
What could be causing this?
The only thing I can think of that might be causing this is mmap() calls - the filesystem driver does not support memory mapping yet, so when mmap() is called for mapping a file for read-only, the C library maps anonymous memory into the given region, then reads from the file into that memory, and seeks back to the original position in the file. My mmap() returns a different pointer than the "hint" - namely, it returns the hint but page-aligned, which the standard says is acceptable (mmap() is allowed to return a different location than the requested hint).
I successfully built it and installed under my OS, so I decided to run a compile the trivial "hello world" C program. If I run:
Code: Select all
gcc -c hello.c -o hello.o
Code: Select all
mariusz:/home/mariusz$ gcc -v hello.o -o hello
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-glidix/4.9.0/lto-wrapper
Target: x86_64-glidix
Configured with: ../glidix-gcc/configure --target=x86_64-glidix --host=x86_64-glidix --prefix=/usr --enable-languages=c,c++ --disable-nls
Thread model: single
gcc version 4.9.0 (GCC)
COMPILER_PATH=/usr/libexec/gcc/x86_64-glidix/4.9.0/:/usr/libexec/gcc/x86_64-glidix/4.9.0/:/usr/libexec/gcc/x86_64-glidix/:/usr/lib/gcc/x86_64-glidix/4.9.0/:/usr/lib/gcc/x86_64-glidix/:/usr/x86_64-glidix/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-glidix/4.9.0/:/usr/lib/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'hello' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-glidix/4.9.0/collect2 -dynamic-linker /lib/glidixld.so -o hello crt0.o crti.o crtbegin.o -L/usr/lib/gcc/x86_64-glidix/4.9.0 hello.o -lgcc -lc -lgcc crtend.o crtn.o
collect2: error: ld terminated with signal -1 []
/usr/bin/ld: cannot find crt0.o: No such file or directory.
/usr/bin/ld: cannot find crti.o: No such file or directory.
/usr/bin/ld: cannot find crtbegin.o: No such file or directory.
/usr/lib/gcc/x86_64-glidix/4.9.0/libgcc.a: file not recognized: File format not recognized
gcc: internal compiler error: (program collect2)
Invalid memory access
mariusz:/home/mariusz$
Code: Select all
$ x86_64-glidix-gcc -v hello.o -o hello
Using built-in specs.
COLLECT_GCC=x86_64-glidix-gcc
COLLECT_LTO_WRAPPER=/glidix/usr/libexec/gcc/x86_64-glidix/4.9.0/lto-wrapper
Target: x86_64-glidix
Configured with: ../glidix-gcc/configure --target=x86_64-glidix --prefix=/glidix/usr --with-sysroot=/glidix --enable-languages=c,c++
Thread model: single
gcc version 4.9.0 (GCC)
COMPILER_PATH=/glidix/usr/libexec/gcc/x86_64-glidix/4.9.0/:/glidix/usr/libexec/gcc/x86_64-glidix/4.9.0/:/glidix/usr/libexec/gcc/x86_64-glidix/:/glidix/usr/lib/gcc/x86_64-glidix/4.9.0/:/glidix/usr/lib/gcc/x86_64-glidix/:/glidix/usr/lib/gcc/x86_64-glidix/4.9.0/../../../../x86_64-glidix/bin/
LIBRARY_PATH=/glidix/usr/lib/gcc/x86_64-glidix/4.9.0/:/glidix/usr/lib/gcc/x86_64-glidix/4.9.0/../../../../x86_64-glidix/lib/:/glidix/lib/:/glidix/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'hello' '-mtune=generic' '-march=x86-64'
/glidix/usr/libexec/gcc/x86_64-glidix/4.9.0/collect2 -plugin /glidix/usr/libexec/gcc/x86_64-glidix/4.9.0/liblto_plugin.so -plugin-opt=/glidix/usr/libexec/gcc/x86_64-glidix/4.9.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccqQM6YX.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc --sysroot=/glidix -dynamic-linker /lib/glidixld.so -o hello /glidix/lib/crt0.o /glidix/lib/crti.o /glidix/usr/lib/gcc/x86_64-glidix/4.9.0/crtbegin.o -L/glidix/usr/lib/gcc/x86_64-glidix/4.9.0 -L/glidix/usr/lib/gcc/x86_64-glidix/4.9.0/../../../../x86_64-glidix/lib -L/glidix/lib -L/glidix/usr/lib hello.o -lgcc -lc -lgcc /glidix/usr/lib/gcc/x86_64-glidix/4.9.0/crtend.o /glidix/lib/crtn.o
The only thing I can think of that might be causing this is mmap() calls - the filesystem driver does not support memory mapping yet, so when mmap() is called for mapping a file for read-only, the C library maps anonymous memory into the given region, then reads from the file into that memory, and seeks back to the original position in the file. My mmap() returns a different pointer than the "hint" - namely, it returns the hint but page-aligned, which the standard says is acceptable (mmap() is allowed to return a different location than the requested hint).