dslm4515 / Musl-LFS

Linux From Scratch using Musl as Libc
GNU General Public License v3.0
170 stars 21 forks source link

Error when building file-5.40 : relocation against symbol cannot be used #60

Closed LostGhost1 closed 2 years ago

LostGhost1 commented 2 years ago

Compilation log for file-5.40

mlfs chroot) root:/tmp/file-5.40# ./configure --prefix=/usr
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /tools/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for builtin ELF support... yes
checking for ELF core file support... yes
checking for zlib support... 
checking for bzlib support... 
checking for xzlib support... 
checking for libseccomp support... 
checking for file formats in man section 5... no
checking build system type... x86_64-pc-linux-musl
checking host system type... x86_64-pc-linux-musl
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for gcc option to accept ISO C99... none needed
checking for gcc option to accept ISO Standard C... (cached) none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /tools/bin/grep
checking for egrep... /tools/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking whether byte ordering is bigendian... no
checking whether ln -s works... yes
checking how to print strings... printf
checking for a sed that does not truncate output... /tools/bin/sed
checking for fgrep... /tools/bin/grep -F
checking for ld used by gcc... /tools/x86_64-mlfs-linux-musl/bin/ld
checking if the linker (/tools/x86_64-mlfs-linux-musl/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /tools/bin/nm -B
checking the name lister (/tools/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 32768
checking how to convert x86_64-pc-linux-musl file names to x86_64-pc-linux-musl format... func_convert_file_noop
checking how to convert x86_64-pc-linux-musl file names to toolchain format... func_convert_file_noop
checking for /tools/x86_64-mlfs-linux-musl/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /tools/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
./configure: line 7783: /usr/bin/file: No such file or directory
checking for mt... no
checking if : is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/tools/x86_64-mlfs-linux-musl/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking whether the -Werror option is usable... yes
checking for simple visibility declarations... yes
checking for ANSI C header files... (cached) yes
checking whether sys/types.h defines makedev... no
checking sys/mkdev.h usability... no
checking sys/mkdev.h presence... no
checking for sys/mkdev.h... no
checking sys/sysmacros.h usability... yes
checking sys/sysmacros.h presence... yes
checking for sys/sysmacros.h... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for stdint.h... (cached) yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for inttypes.h... (cached) yes
checking for unistd.h... (cached) yes
checking utime.h usability... yes
checking utime.h presence... yes
checking for utime.h... yes
checking wchar.h usability... yes
checking wchar.h presence... yes
checking for wchar.h... yes
checking wctype.h usability... yes
checking wctype.h presence... yes
checking for wctype.h... yes
checking getopt.h usability... yes
checking getopt.h presence... yes
checking for getopt.h... yes
checking err.h usability... yes
checking err.h presence... yes
checking for err.h... yes
checking xlocale.h usability... no
checking xlocale.h presence... no
checking for xlocale.h... no
checking sys/mman.h usability... yes
checking sys/mman.h presence... yes
checking for sys/mman.h... yes
checking for sys/stat.h... (cached) yes
checking for sys/types.h... (cached) yes
checking sys/utime.h usability... no
checking sys/utime.h presence... no
checking for sys/utime.h... no
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for sys/sysmacros.h... (cached) yes
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
checking bzlib.h usability... yes
checking bzlib.h presence... yes
checking for bzlib.h... yes
checking lzma.h usability... yes
checking lzma.h presence... yes
checking for lzma.h... yes
checking for sig_t... yes
checking for off_t... yes
checking for size_t... yes
checking for struct stat.st_rdev... yes
checking for struct tm.tm_gmtoff... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for struct tm.tm_zone... yes
checking for tm_zone in struct tm... yes
checking whether tzname is declared... yes
checking for tzname... yes
checking for tm_isdst in struct tm... yes
checking whether daylight is declared... yes
checking for daylight... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking for _LARGEFILE_SOURCE value needed for large files... no
checking for mbstate_t... yes
checking for struct option in getopt... yes
checking for pid_t... yes
checking for uint8_t... yes
checking for uint16_t... yes
checking for uint32_t... yes
checking for int32_t... yes
checking for uint64_t... yes
checking for int64_t... yes
checking for intptr_t... yes
checking for uintptr_t... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... yes
checking for getpagesize... yes
checking for working mmap... yes
checking vfork.h usability... no
checking vfork.h presence... no
checking for vfork.h... no
checking for fork... yes
checking for vfork... yes
checking for working fork... yes
checking for working vfork... (cached) yes
checking whether mbrtowc and mbstate_t are properly declared... yes
checking for gcc compiler warnings... yes
checking for strndup... yes
checking for mkstemp... yes
checking for mkostemp... yes
checking for utimes... yes
checking for utime... yes
checking for wcwidth... yes
checking for strtof... yes
checking for newlocale... yes
checking for uselocale... yes
checking for freelocale... yes
checking for memmem... yes
checking for pipe2... yes
checking for getopt_long... yes
checking for asprintf... yes
checking for vasprintf... yes
checking for strlcpy... yes
checking for strlcat... yes
checking for getline... yes
checking for ctime_r... yes
checking for asctime_r... yes
checking for localtime_r... yes
checking for gmtime_r... yes
checking for pread... yes
checking for strcasestr... yes
checking for fmtcheck... no
checking for dprintf... yes
checking for gzopen in -lz... no
checking for BZ2_bzCompressInit in -lbz2... yes
checking for lzma_stream_decoder in -llzma... yes
checking for seccomp_init in -lseccomp... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating magic/Makefile
config.status: creating tests/Makefile
config.status: creating doc/Makefile
config.status: creating python/Makefile
config.status: creating libmagic.pc
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
(mlfs chroot) root:/tmp/file-5.40# 
(mlfs chroot) root:/tmp/file-5.40# # Build and install
(mlfs chroot) root:/tmp/file-5.40# make -j4 && make install
make  all-recursive
make[1]: Entering directory '/tmp/file-5.40'
Making all in src
make[2]: Entering directory '/tmp/file-5.40/src'
sed -e "s/X.YY/$(echo 5.40 | tr -d .)/" < ../src/magic.h.in > magic.h
make  all-am
make[3]: Entering directory '/tmp/file-5.40/src'
  CC       file.o
  CC       seccomp.o
  CC       buffer.lo
  CC       magic.lo
  CC       apprentice.lo
  CC       softmagic.lo
  CC       ascmagic.lo
  CC       encoding.lo
  CC       compress.lo
  CC       is_csv.lo
  CC       is_json.lo
  CC       is_tar.lo
  CC       readelf.lo
  CC       print.lo
  CC       fsmagic.lo
  CC       funcs.lo
  CC       apptype.lo
  CC       der.lo
  CC       cdf.lo
  CC       cdf_time.lo
  CC       readcdf.lo
  CC       fmtcheck.lo
  CCLD     libmagic.la
/tools/lib/gcc/x86_64-mlfs-linux-musl/10.3.1/../../../../x86_64-mlfs-linux-musl/bin/ld: /tools/lib/libbz2.a(bzlib.o): relocation R_X86_64_32S against symbol `BZ2_crc32Table' can not be used when making a shared object; recompile with -fPIC
/tools/lib/gcc/x86_64-mlfs-linux-musl/10.3.1/../../../../x86_64-mlfs-linux-musl/bin/ld: /tools/lib/libbz2.a(compress.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/tools/lib/gcc/x86_64-mlfs-linux-musl/10.3.1/../../../../x86_64-mlfs-linux-musl/bin/ld: /tools/lib/libbz2.a(decompress.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tools/lib/gcc/x86_64-mlfs-linux-musl/10.3.1/../../../../x86_64-mlfs-linux-musl/bin/ld: /tools/lib/libbz2.a(blocksort.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/tools/lib/gcc/x86_64-mlfs-linux-musl/10.3.1/../../../../x86_64-mlfs-linux-musl/bin/ld: /tools/lib/libbz2.a(blocksort.o): warning: relocation against `stderr' in read-only section `.text'
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:499: libmagic.la] Error 1
make[3]: Leaving directory '/tmp/file-5.40/src'
make[2]: *** [Makefile:380: all] Error 2
make[2]: Leaving directory '/tmp/file-5.40/src'
make[1]: *** [Makefile:459: all-recursive] Error 1
make[1]: Leaving directory '/tmp/file-5.40'
make: *** [Makefile:368: all] Error 2
(mlfs chroot) root:/tmp/file-5.40# 

Stage 3, final system, step 014. Haven't had any issues during the previous steps. Any ideas?

dslm4515 commented 2 years ago

/tools/lib/gcc/x86_64-mlfs-linux-musl/10.3.1/../../../../

based on above, looks like file-5.40 is being built with gcc from /tools and not GCC installed in /usr

LostGhost1 commented 2 years ago

Right, because compiling GCC for the final system is step 23, and I'm on step 14. Or am I missing something? @dslm4515

dslm4515 commented 2 years ago

Sorry, i forgot its file before system gcc.

Its an issue with bzip2 built in /tools. Try rebuilding bzip2 while in chroot:

patch -Np1 -i ../patches/bzip2-void/install_docs-1.patch
patch -Np0 -i ../patches/bzip2-void/soname.patch
sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile
sed -i "s@(PREFIX)/man@(PREFIX)/share/man@g" Makefile
CFLAGS="-fPIC" make -f Makefile-libbz2_so && make clean
CFLAGS="-fPIC" make
cp -v libbz2.so.1.0.8 /tools/lib/
dslm4515 commented 2 years ago

Clear Linux has patches to convert the build system of bzip2 from Makefile to autotools (i.e. configure script)... I may add those patches to make it easier to build and install bzip2

LostGhost1 commented 2 years ago

Rebuilt bzip2 without any issues, but when I try recompiling file 5.40 (after make clean, from scratch) same issue. However, if I configure it with --disable-shared it starts complaining about there being no lzma instead, if that's worth anything. Is file that essential, can I build it later?


make[3]: Entering directory '/tmp/file-5.40/src'
  CCLD     libmagic.la
  CCLD     file
make[3]: Leaving directory '/tmp/file-5.40/src'
make[2]: Leaving directory '/tmp/file-5.40/src'
Making all in magic
make[2]: Entering directory '/tmp/file-5.40/magic'
../src/file -C -m magic
Error loading shared library liblzma.so.5: No such file or directory (needed by ../src/file)
Error relocating ../src/file: lzma_end: symbol not found
Error relocating ../src/file: lzma_code: symbol not found
Error relocating ../src/file: lzma_auto_decoder: symbol not found
make[2]: *** [Makefile:843: magic.mgc] Error 127
make[2]: Leaving directory '/tmp/file-5.40/magic'
make[1]: *** [Makefile:459: all-recursive] Error 1
make[1]: Leaving directory '/tmp/file-5.40'
make: *** [Makefile:368: all] Error 2

This to be precise

dslm4515 commented 2 years ago

I'm not sure. File is used in build scripts for some packages.

Even after rebuilding the bzip2 library, same exact error when building file-5.40?

LostGhost1 commented 2 years ago

Yup. Tried reconfiguring with CFLAGS="-fPIC" LDFLAGS="-fPIC", same issue

dslm4515 commented 2 years ago

check the symbols for libbz2.so.1.0.8. Does it match below? Below is from a 32-bit machine

$ readelf -s libbz2.so.1.0.8  | grep BZ2_crc32Table
    58: 00011020  1024 OBJECT  GLOBAL DEFAULT   20 BZ2_crc32Table
   171: 00011020  1024 OBJECT  GLOBAL DEFAULT   20 BZ2_crc32Table
LostGhost1 commented 2 years ago
(mlfs chroot) root:/tools/lib# readelf -s libbz2.so.1.0.8  | grep BZ2_crc32Table
    57: 00000000000191c0  1024 OBJECT  GLOBAL DEFAULT   21 BZ2_crc32Table
   114: 00000000000191c0  1024 OBJECT  GLOBAL DEFAULT   21 BZ2_crc32Table
(mlfs chroot) root:/tools/lib# 
dslm4515 commented 2 years ago

oops. i meant to rebuild libbz2.a....but copying libbz2.so.1.0.8 should work too.

rebuild bzip2 like above but copy libbz2.a to /tools/lib

a correctly built bzip2 library should look like this:


$ readelf -s /tools/lib/libbz2.a | grep BZ2_crc32Table
     1: 0000000000000000  1024 OBJECT  GLOBAL DEFAULT    2 BZ2_crc32Table
    12: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND BZ2_crc32Table

$ readelf -s /tools/lib/libbz2.so.1.0.8 | grep BZ2_crc32Table
    58: 0000000000219060  1024 OBJECT  GLOBAL DEFAULT   20 BZ2_crc32Table
   105: 0000000000219060  1024 OBJECT  GLOBAL DEFAULT   20 BZ2_crc32Table
dslm4515 commented 2 years ago

hmmm.... in a chroot environment, it should be clean.... what is your output if you run env ?

For me:

$ env
PWD=/sources/linux-5.13.0
HOME=/root
TERM=xterm
SHLVL=1
PS1=(mlfs chroot) \u:\w\$ 
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin
OLDPWD=/
_=/bin/env
LostGhost1 commented 2 years ago
(mlfs chroot) root:/# env
PWD=/
HOME=/root
TERM=xterm-256color
SHLVL=1
PS1=(mlfs chroot) \u:\w\$ 
EXTRA_CONFIG= --enable-targets=x86_64-pep
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin
OLDPWD=/tools/lib
_=/tools/bin/env
(mlfs chroot) root:/# 
dslm4515 commented 2 years ago

I forgot to ask, what distro are you using?

dslm4515 commented 2 years ago

Closing due to inactivity.