Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libbacktrace doesn't honor --sysroot at link time when crosscompiling #134

Open
ericriff opened this issue Sep 6, 2024 · 7 comments
Open

Comments

@ericriff
Copy link

ericriff commented Sep 6, 2024

I'm trying to cross-compile this lib for arm32

The final link stage fails with

libtool: link: arm-poky-linux-gnueabi-gcc -shared  -fPIC -DPIC  .libs/atomic.o .libs/dwarf.o .libs/fileline.o .libs/posix.o .libs/print.o .libs/sort.o .libs/state.o .libs/backtrace.o .libs/simple.o .libs/elf.o .libs/mmapio.o .libs/mmap.o    -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard   -Wl,-soname -Wl,libbacktrace.so.0 -o .libs/libbacktrace.so.0.0.0
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find crti.o: No such file or directory
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find crtbeginS.o: No such file or directory
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find -lgcc

Which is a symptom of the linker not seeing the toolchain's sysroot.

I'm exposing it through the LDFLAGS env variable, but it doesn't affect the build.

export LDFLAGS=--sysroot=/opt/arm32-sdk/sysroots/armv7at2hf-neon-poky-linux-gnueabi

I don't know enough about libtool to fix it.

@ianlancetaylor
Copy link
Owner

Exactly how are you building libbacktrace?

You must normally set flags like LDFLAGS in the environment when you run the configure script. Or, you set them on the make command line using something like make LDFLAGS=--sysroot.... Setting LDFLAGS in the environment only when running make but not when running configure may not work.

@ericriff
Copy link
Author

ericriff commented Sep 6, 2024

I'm building through conan, but I also tried to replicate it without conan.
Pretty much I just export CC=arm-poky-linux-gnueabi-gcc, CXX=arm-poky-linux-gnueabi-g++ and some other C|CXX|LD FLAGS
Somehow I don't get the --sysroot=/opt/arm32-sdk/sysroots/armv7at2hf-neon-poky-linux-gnueabi on the libtool: link stage. It does work on some other libraries that use newer versions of libtool, but I have no idea how to bump it for this project.

As I mentioned, I don't have much experience with libtool / autotools.

@ianlancetaylor
Copy link
Owner

I'm sorry, I'm not familiar with conan.

Can you tell me precisely how you built the library without conan? Thanks.

The version of libtool that the project uses is the same as the one used by GCC, as GCC is the upstream source code for this repo.

@ericriff
Copy link
Author

ericriff commented Sep 6, 2024

Sure.

I first set these env variables

export CC="arm-poky-linux-gnueabi-gcc"
export CXX="arm-poky-linux-gnueabi-g++"

export CFLAGS="-march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/arm32-sdk/sysroots/armv7at2hf-neon-poky-linux-gnueabi"
export CXXFLAGS="-march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/arm32-sdk/sysroots/armv7at2hf-neon-poky-linux-gnueabi"
export CPPFLAGS="-march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/arm32-sdk/sysroots/armv7at2hf-neon-poky-linux-gnueabi"

export LDFLAGS="--sysroot=/opt/arm32-sdk/sysroots/armv7at2hf-neon-poky-linux-gnueabi"

Then configure

./configure --enable-shared --disable-static --host=arm-linux-gnueabihf --build=x86_64-linux-gnu
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-unknown-linux-gnueabihf
checking target system type... arm-unknown-linux-gnueabihf
checking for arm-linux-gnueabihf-gcc... arm-poky-linux-gnueabi-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... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-poky-linux-gnueabi-gcc accepts -g... yes
checking for arm-poky-linux-gnueabi-gcc option to accept ISO C89... none needed
checking whether arm-poky-linux-gnueabi-gcc understands -c and -o together... yes
checking how to run the C preprocessor... arm-poky-linux-gnueabi-gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/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 for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-gnueabihf-strip... no
checking for strip... strip
configure: WARNING: using cross tools not prefixed with host triplet
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for arm-linux-gnueabihf-gcc... (cached) arm-poky-linux-gnueabi-gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether arm-poky-linux-gnueabi-gcc accepts -g... (cached) yes
checking for arm-poky-linux-gnueabi-gcc option to accept ISO C89... (cached) none needed
checking whether arm-poky-linux-gnueabi-gcc understands -c and -o together... (cached) yes
checking for arm-linux-gnueabihf-ranlib... no
checking for ranlib... ranlib
checking for gawk... (cached) mawk
checking for dwz... no
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by arm-poky-linux-gnueabi-gcc... /opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/ld
checking if the linker (/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... no
checking for arm-linux-gnueabihf-dumpbin... no
checking for arm-linux-gnueabihf-link... no
checking for dumpbin... no
checking for link... link -dump
checking the name lister (nm) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/ld option to reload object files... -r
checking for arm-linux-gnueabihf-objdump... no
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for arm-linux-gnueabihf-ar... no
checking for ar... ar
checking for arm-linux-gnueabihf-strip... strip
checking for arm-linux-gnueabihf-ranlib... ranlib
checking command to parse nm output from arm-poky-linux-gnueabi-gcc object... ok
checking for dlfcn.h... yes
checking for objdir... .libs
checking if arm-poky-linux-gnueabi-gcc supports -fno-rtti -fno-exceptions... no
checking for arm-poky-linux-gnueabi-gcc option to produce PIC... -fPIC -DPIC
checking if arm-poky-linux-gnueabi-gcc PIC flag -fPIC -DPIC works... yes
checking if arm-poky-linux-gnueabi-gcc static flag -static works... no
checking if arm-poky-linux-gnueabi-gcc supports -c -o file.o... yes
checking if arm-poky-linux-gnueabi-gcc supports -c -o file.o... (cached) yes
checking whether the arm-poky-linux-gnueabi-gcc linker (/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/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 for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
checking unwind.h usability... yes
checking unwind.h presence... yes
checking for unwind.h... yes
checking for _Unwind_Backtrace... yes
checking for -funwind-tables option... yes
checking for -frandom-seed=string option... yes
checking whether arm-poky-linux-gnueabi-gcc supports -W... yes
checking whether arm-poky-linux-gnueabi-gcc supports -Wall... yes
checking whether arm-poky-linux-gnueabi-gcc supports -Wwrite-strings... yes
checking whether arm-poky-linux-gnueabi-gcc supports -Wstrict-prototypes... yes
checking whether arm-poky-linux-gnueabi-gcc supports -Wmissing-prototypes... yes
checking whether arm-poky-linux-gnueabi-gcc supports -Wold-style-definition... yes
checking whether arm-poky-linux-gnueabi-gcc supports -Wmissing-format-attribute... yes
checking whether arm-poky-linux-gnueabi-gcc supports -Wcast-qual... yes
checking whether arm-poky-linux-gnueabi-gcc supports -Wattributes... yes
checking whether arm-poky-linux-gnueabi-gcc supports -Wunknown-attributes... no
checking whether arm-poky-linux-gnueabi-gcc supports -Wpointer-arith... yes
checking for _Unwind_GetIPInfo... yes
checking __sync extensions... yes
checking __atomic extensions... yes
checking output filetype... elf32
checking sys/mman.h usability... yes
checking sys/mman.h presence... yes
checking for sys/mman.h... yes
checking for mmap... yes
checking link.h usability... yes
checking link.h presence... yes
checking for link.h... yes
checking sys/link.h usability... no
checking sys/link.h presence... no
checking for sys/link.h... no
checking for dl_iterate_phdr... yes
checking mach-o/dyld.h usability... no
checking mach-o/dyld.h presence... no
checking for mach-o/dyld.h... no
checking sys/ldr.h usability... no
checking sys/ldr.h presence... no
checking for sys/ldr.h... no
checking windows.h usability... no
checking windows.h presence... no
checking for windows.h... no
checking for tlhelp32.h... no
checking for fcntl... yes
checking whether strnlen is declared... yes
checking whether getpagesize is declared... yes
checking for lstat... yes
checking for readlink... yes
checking for getexecname... no
checking whether _pgmptr is declared... no
checking for KERN_PROC... no
checking for KERN_PROG_ARGS... no
checking for clock_gettime... yes
checking whether -pthread is supported... yes
checking whether -gdwarf-5 is supported... yes
checking for compress in -lz... yes
checking whether --build-id is supported... yes
checking whether --compress-debug-sections=zlib-gnu is supported... yes
checking whether --compress-debug-sections=zlib-gabi is supported... yes
checking for ZSTD_compress in -lzstd... yes
checking whether --compress-debug-sections=zstd is supported... no
checking for objcopy... objcopy
checking for readelf... readelf
checking whether objcopy supports debuglink... yes
checking for dsymutil... dsymutil
checking for nm... nm
checking for xz... xz
checking for comm... comm
checking for lzma_auto_decoder in -llzma... yes
checking whether tests can run... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating backtrace-supported.h
config.status: creating install-debuginfo-for-buildid.sh
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands
config.status: executing default commands

And then build

make all

The problem is that at link time, we I don't get the --sysroot flag

libtool: link: arm-poky-linux-gnueabi-gcc -shared  -fPIC -DPIC  .libs/atomic.o .libs/dwarf.o .libs/fileline.o .libs/posix.o .libs/print.o .libs/sort.o .libs/state.o .libs/backtrace.o .libs/simple.o .libs/elf.o .libs/mmapio.o .libs/mmap.o    -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z -Wl,relro -Wl,-z -Wl,now   -Wl,-soname -Wl,libbacktrace.so.0 -o .libs/libbacktrace.so.0.0.0
opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find crti.o: No such file or directory
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find crtbeginS.o: No such file or directory
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find -lgcc
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find -lgcc_s
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find -lc
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find -lgcc
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find -lgcc_s
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find crtendS.o: No such file or directory
/opt/arm32-sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.3.0/real-ld: cannot find crtn.o: No such file or directory

If I manually run that step but adding --sysroot=<path> it works

@ericriff
Copy link
Author

ericriff commented Sep 6, 2024

I can work around this by changing how I expose the compiler

export CC="arm-poky-linux-gnueabi-gcc <flags> <sysroot>"
export CXX="arm-poky-linux-gnueabi-g++ <flags> <sysroot>"

But this breaks some other libraries. I need an uniform build env for many libraries.

@ericriff
Copy link
Author

ericriff commented Sep 6, 2024

/libbacktrace$ ./libtool --version
libtool (GNU libtool 1.3134 2009-11-29) 2.2.7a
Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996

This project uses a really old version of libtool. The changelog says they added sysroot support on 2.4 (2010) if I read it correctly
https://git.savannah.gnu.org/cgit/libtool.git/tree/NEWS

@ericriff ericriff changed the title libbacktrace doesn't honor LDFLAGS at link time libbacktrace doesn't honor --sysroot at link time when crosscompiling Sep 6, 2024
@ericriff
Copy link
Author

ericriff commented Sep 6, 2024

Update:
I ran this

autoreconf --install --force

And re-configured. Now the sysroot is properly set and I can crosscompile.
I now have libtool 2.4.6

./libtool --version
libtool (GNU libtool) 2.4.6
Written by Gordon Matzigkeit, 1996

Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Would it be possible to update this repo with this? I've no idea what the implications are, as I said, I'm not familiar with this build system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants