Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22272

ld fails to find libc when compiling first pass of (cross?) gcc

$
0
0

I'm preparing a native toolchain for use in a custom build system. I took LFS 8.4 book as a base. The biggest deviation from the book is that I'm not using /tools symlink in system as I don't want to touch the system. I've written the procedure in a shell script:

#!/bin/bash

set -euo pipefail
set -x

# prepare build dir
mkdir toolchain
cd toolchain

# mk dest dirs
mkdir -p root/tools

# Fetch sources
mkdir fetch
cd fetch
wget http://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.xz
wget http://ftp.gnu.org/gnu/gcc/gcc-8.3.0/gcc-8.3.0.tar.xz
wget http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.6.tar.xz
wget http://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.xz
wget http://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
cd ..

export PATH=/achm/toolchain/root/bin:/bin:/usr/bin

# pass1 binutils
mkdir -p binutils/build
cd binutils
tar xaf ../fetch/binutils-*
cd build
../binutils-2.32/configure --prefix=/achm/toolchain/root/tools --with-sysroot=/achm/toolchain/root --with-lib-path=/achm/toolchain/root/tools/lib --target=x86_64-lfs-linux-gnu --disable-nls --disable-werror
make -j8
mkdir /achm/toolchain/root/tools/lib
ln -s lib /achm/toolchain/root/tools/lib64
make install
cd ../..

# pass 1 gcc
mkdir gcc
cd gcc
tar xaf ../fetch/gcc-*
cd gcc-*
tar xaf ../../fetch/mpfr-*
tar xaf ../../fetch/gmp-*
tar xaf ../../fetch/mpc-*
mv mpfr-* mpfr
mv gmp-* gmp
mv mpc-* mpc

for file in gcc/config/{linux,i386/linux{,64}}.h
do
  cp -uv $file{,.orig}
  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/achm/toolchain/root/tools&@g' \
      -e 's@/usr@/achm/toolchain/root/tools@g' $file.orig > $file
  echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/achm/build/toolchain/root/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""'>> $file
  touch $file.orig
done

#sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64 #TODO: This fails probably becouse we are on a 9p fs
cat gcc/config/i386/t-linux64 |sed -e '/m64=/s/lib64/lib/'> tmp.sed
mv tmp.sed gcc/config/i386/t-linux64

mkdir build
cd build
../configure --target=x86_64-lfs-linux-gnu --prefix=/achm/toolchain/root/tools --with-glibc-version=2.11 --with-sysroot=/achm/toolchain/root --with-newlib --without-headers --with-local-prefix=/achm/toolchain/root/tools --with-native-system-header-dir=/achm/toolchain/root/tools/include --disable-nls --disable-shared --disable-multilib --disable-decimal-float --disable-threads --disable-libatomic --disable-libgomp --disable-mpx --disable-libquadmath --disable-libssp --disable-libvtv --disable-libstdcxx --enable-languages=c,c++
make -j1

Questions: 1. In section 5.4 of LFS:

Slightly adjusting the name of the working platform, by changing the "vendor" field target triplet by way of the LFS_TGT variable, ensures that the first build of Binutils and GCC produces a compatible cross-linker and cross-compiler. Instead of producing binaries for another architecture, the cross-linker and cross-compiler will produce binaries compatible with the current hardware. Do I understand correctly that we create a cross-compiler that happens to target the same machine just with a cosmetic difference in the triplet?

  1. When I run the script that I've written it fails when compiling gcc (make). The first stage compiler xgcc calls ld that fails to find files belonging to libc:
$ ./toolchain.sh
(...)
make[3]: Leaving directory '/achm/toolchain/gcc/gcc-8.3.0/build/x86_64-lfs-linux-gnu/libgcc'
make[2]: Leaving directory '/achm/toolchain/gcc/gcc-8.3.0/build/x86_64-lfs-linux-gnu/libgcc'
Checking multilib configuration for libmpx...
mkdir -p -- x86_64-lfs-linux-gnu/libmpx
Configuring in x86_64-lfs-linux-gnu/libmpx
configure: creating cache ./config.cache
checking for --enable-version-specific-runtime-libs... no
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-lfs-linux-gnu
checking target system type... x86_64-lfs-linux-gnu
checking for target support for Intel MPX runtime library... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for x86_64-lfs-linux-gnu-strip... /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... mawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for x86_64-lfs-linux-gnu-gcc... /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/xgcc -B/achm/toolchain/gcc/gcc-8.3.0/build/./gcc/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib/ -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/include -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/sys-include   
checking for C compiler default output file name... 
configure: error: in `/achm/toolchain/gcc/gcc-8.3.0/build/x86_64-lfs-linux-gnu/libmpx':
configure: error: C compiler cannot create executables
See `config.log' for more details.
make[1]: *** [Makefile:12021: configure-target-libmpx] Error 1
make[1]: Leaving directory '/achm/toolchain/gcc/gcc-8.3.0/build'
make: *** [Makefile:891: all] Error 2
$ /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/xgcc -B/achm/toolchain/gcc/gcc-8.3.0/build/./gcc/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib/ -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/include -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/sys-include
xgcc: fatal error: no input files
compilation terminated.
$ cat hello_world.c 
#include <stdio.h>
int main()
{
    printf("hello\n");
    return 0;
}
$ /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/xgcc -B/achm/toolchain/gcc/gcc-8.3.0/build/./gcc/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib/ -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/include -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/sys-include hello_world.c 
hello_world.c:1:10: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
          ^~~~~~~~~
compilation terminated.
$ cat minimal.c 
int main()
{
    return 0;
}
$ /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/xgcc -B/achm/toolchain/gcc/gcc-8.3.0/build/./gcc/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib/ -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/include -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/sys-include minimal.c     
/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory
/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ld: cannot find crti.o: No such file or directory
/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ld: cannot find -lc
/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
$ /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/xgcc -B/achm/toolchain/gcc/gcc-8.3.0/build/./gcc/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ -B/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib/ -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/include -isystem /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/sys-include minimal.c -Wl,--verbose
GNU ld (GNU Binutils) 2.32
(...)
SEARCH_DIR("=/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib64"); SEARCH_DIR("/achm/toolchain/root/tools/lib"); SEARCH_DIR("=/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib");
(...)
/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ld: mode elf_x86_64
attempt to open crt1.o failed
attempt to open crti.o failed
attempt to open /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/crtbegin.o succeeded
/achm/toolchain/gcc/gcc-8.3.0/build/./gcc/crtbegin.o
attempt to open /tmp/cceUDM0P.o succeeded
/tmp/cceUDM0P.o
attempt to open /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/libgcc.so failed
attempt to open /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/libgcc.a succeeded
/achm/toolchain/gcc/gcc-8.3.0/build/./gcc/libgcc.a
attempt to open /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/libc.so failed
attempt to open /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/libc.a failed
attempt to open /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/libc.so failed
attempt to open /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/libc.a failed
attempt to open /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib/libc.so failed
attempt to open /achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib/libc.a failed
attempt to open /achm/toolchain/root/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib64/libc.so failed
attempt to open /achm/toolchain/root/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib64/libc.a failed
attempt to open /achm/toolchain/root/tools/lib/libc.so failed
attempt to open /achm/toolchain/root/tools/lib/libc.a failed
attempt to open /achm/toolchain/root/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib/libc.so failed
attempt to open /achm/toolchain/root/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/lib/libc.a failed
attempt to open /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/libgcc.so failed
attempt to open /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/libgcc.a succeeded
/achm/toolchain/gcc/gcc-8.3.0/build/./gcc/libgcc.a
attempt to open /achm/toolchain/gcc/gcc-8.3.0/build/./gcc/crtend.o succeeded
/achm/toolchain/gcc/gcc-8.3.0/build/./gcc/crtend.o
attempt to open crtn.o failed
/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory
/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ld: cannot find crti.o: No such file or directory
/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ld: cannot find -lc
/achm/toolchain/root/tools/x86_64-lfs-linux-gnu/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

Those files are part of libc. Since libc has not been compiled host's one should be used but if I understand correctly we are making a cross compiler.

  1. Should I just copy the libc to /achm/toolchain/root/tools/lib/, add some flag to make linker look in host's lib directories or am I doing something wrong?

Viewing all articles
Browse latest Browse all 22272

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>