URL:
  <https://savannah.gnu.org/support/?111105>

                 Summary: libtool use incorrect rpath when using sysroot
                   Group: GNU Libtool
               Submitter: chitaotao
               Submitted: Fri 09 Aug 2024 03:30:35 AM UTC
                Category: None
                Priority: 5 - Normal
                Severity: 4 - Important
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
        Operating System: GNU/Linux


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Fri 09 Aug 2024 03:30:35 AM UTC By: Xuntao Chi <chitaotao>
== Brief ==
When cross compiling, after specifying rpath and sysroot, libtool (install
node) generated relink compile command including '-L rpath', which does not
include sysroot, casuing linker to incorrectly link host library.

== Detail problem explanation ==
I was cross compiling [https://github.com/libimobiledevice/libplist libplist]
with Android NDK (clang and ld.lld), and found out when installing
(relinking), libtool does not prepend sysroot to rpath for '-L' options,
causing lld trying to link host libraries and fail. GNU Binutils ld ignores
incompatible libraries in this case but not lld.
This problem does not limit to Android NDK but everything that use lld, or any
linker that does not handle incompatible libraries.
This is the generated .la file for the library:

# libplist++-2.0.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4.7
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libplist++-2.0.so.4'

# Names of this library.
library_names='libplist++-2.0.so.4.3.0 libplist++-2.0.so.4 libplist++-2.0.so'

# The name of the static archive.
old_library='libplist++-2.0.a'

# Linker flags that cannot go in dependency_libs.
inherited_linker_flags=' -pthread'

# Libraries that this one depends upon.
dependency_libs=' /home/chi/ddev/android/cross/bc/src/libplist-2.0.la
-lpthread'

# Names of additional weak libraries provided by this library
weak_library_names=''

# Version information for libplist++-2.0.
current=7
age=3
revision=0

# Is this an already installed library?
installed=no

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/lib'
relink_command="(cd /home/chi/ddev/android/cross/bc/src; /bin/sh
\"/home/chi/ddev/android/cross/bc/libtool\"  --silent --tag CXX --mode=relink
clang++ -fuse-ld=lld --target=aarch64-linux-gnu
--sysroot=/usr/aarch64-linux-gnu -g -O2 -lpthread -version-info 7:0:3
-no-undefined -o libplist++-2.0.la -rpath /lib Node.lo Structure.lo Array.lo
Boolean.lo Data.lo Date.lo Dictionary.lo Integer.lo Key.lo Real.lo String.lo
Uid.lo libplist-2.0.la -lm -lpthread @inst_prefix_dir@)"

This is the generated command, it can be seen that '/usr/aarch64-linux-gnu/`
is not added to `-L/usr/local/lib'

clang++ -fuse-ld=lld --target=aarch64-linux-gnu
--sysroot=/usr/aarch64-linux-gnu -fPIC -DPIC -shared -nostdlib
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/../../../../aarch64-linux-gnu/lib/crti.o
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/crtbeginS.o .libs/Node.o
.libs/Structure.o .libs/Array.o .libs/Boolean.o .libs/Data.o .libs/Date.o
.libs/Dictionary.o .libs/Integer.o .libs/Key.o .libs/Real.o .libs/String.o
.libs/Uid.o -L/tmp/123123123/lib -L/lib -lplist-2.0 -lpthread
-L/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0
-L/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/../../../../aarch64-linux-gnu/lib/../lib64
-L/usr/aarch64-linux-gnu/lib/../lib64
-L/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/../../../../aarch64-linux-gnu/lib
-L/usr/aarch64-linux-gnu/lib -lstdc++ -lm -lc -lgcc_s -lgcc
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/crtendS.o
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/../../../../aarch64-linux-gnu/lib/crtn.o
-fuse-ld=lld --sysroot=/usr/aarch64-linux-gnu -g -O2 -pthread -Wl,-soname
-Wl,libplist++-2.0.so.4 -o .libs/libplist++-2.0.so.4.3.0


== Version ==
Project uses libtool (GNU libtool) 2.4.7
config.guess is x86_64-pc-linux-gnu

== Additional infomation ==
Here is the configure command for testing

export TARGET=aarch64-linux-gnu
../libplist-2.3.0/configure --host=$TARGET
--with-sysroot=/usr/aarch64-linux-gnu --prefix= --without-cython CC="clang
--target=$TARGET -fuse-ld=lld --sysroot=/usr/aarch64-linux-gnu" CXX="clang++
-fuse-ld=lld --target=$TARGET --sysroot=/usr/aarch64-linux-gnu" AR=llvm-ar
AS=llvm-as STRIP=llvm-strip NM=llvm-nm RANLIB=llvm-ranlib OBJDUMP=llvm-objdump
OBJCOPY=llvm-objcopy

This is my error log:

make DESTDIR=/tmp/123123123 install V=1
Making install in libcnary
make[1]: Entering directory '/home/chi/ddev/android/cross/bc/libcnary'
make[2]: Entering directory '/home/chi/ddev/android/cross/bc/libcnary'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/home/chi/ddev/android/cross/bc/libcnary'
make[1]: Leaving directory '/home/chi/ddev/android/cross/bc/libcnary'
Making install in src
make[1]: Entering directory '/home/chi/ddev/android/cross/bc/src'
make[2]: Entering directory '/home/chi/ddev/android/cross/bc/src'
 /usr/bin/mkdir -p '/tmp/123123123/lib'
 /bin/sh ../libtool   --mode=install /usr/bin/install -c   libplist-2.0.la
libplist++-2.0.la '/tmp/123123123/lib'
libtool: install: /usr/bin/install -c .libs/libplist-2.0.so.4.3.0
/tmp/123123123/lib/libplist-2.0.so.4.3.0
libtool: install: (cd /tmp/123123123/lib && { ln -s -f libplist-2.0.so.4.3.0
libplist-2.0.so.4 || { rm -f libplist-2.0.so.4 && ln -s libplist-2.0.so.4.3.0
libplist-2.0.so.4; }; })
libtool: install: (cd /tmp/123123123/lib && { ln -s -f libplist-2.0.so.4.3.0
libplist-2.0.so || { rm -f libplist-2.0.so && ln -s libplist-2.0.so.4.3.0
libplist-2.0.so; }; })
libtool: install: /usr/bin/install -c .libs/libplist-2.0.lai
/tmp/123123123/lib/libplist-2.0.la
libtool: warning: relinking 'libplist++-2.0.la'
libtool: install: (cd /home/chi/ddev/android/cross/bc/src; /bin/sh
"/home/chi/ddev/android/cross/bc/libtool"  --silent --tag CXX --mode=relink
clang++ -fuse-ld=lld --target=aarch64-linux-gnu
--sysroot=/usr/aarch64-linux-gnu -g -O2 -lpthread -version-info 7:0:3
-no-undefined -o libplist++-2.0.la -rpath /lib Node.lo Structure.lo Array.lo
Boolean.lo Data.lo Date.lo Dictionary.lo Integer.lo Key.lo Real.lo String.lo
Uid.lo libplist-2.0.la -lm -lpthread -inst-prefix-dir /tmp/123123123)
clang++: warning: argument unused during compilation: '-pthread'
[-Wunused-command-line-argument]
ld.lld: error:
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/../../../../aarch64-linux-gnu/lib/crti.o
is incompatible with elf64-x86-64
ld.lld: error: /usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/crtbeginS.o is
incompatible with elf64-x86-64
ld.lld: error: .libs/Node.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Structure.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Array.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Boolean.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Data.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Date.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Dictionary.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Integer.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Key.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Real.o is incompatible with elf64-x86-64
ld.lld: error: .libs/String.o is incompatible with elf64-x86-64
ld.lld: error: .libs/Uid.o is incompatible with elf64-x86-64
ld.lld: error: /tmp/123123123/lib/libplist-2.0.so is incompatible with
elf64-x86-64
ld.lld: error:
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/libgcc.a(cas_1_1.o) is
incompatible with elf64-x86-64
ld.lld: error:
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/libgcc.a(cas_2_1.o) is
incompatible with elf64-x86-64
ld.lld: error:
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/libgcc.a(cas_4_1.o) is
incompatible with elf64-x86-64
ld.lld: error:
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/libgcc.a(cas_8_1.o) is
incompatible with elf64-x86-64
ld.lld: error:
/usr/bin/../lib64/gcc/aarch64-linux-gnu/14.1.0/libgcc.a(cas_16_1.o) is
incompatible with elf64-x86-64
ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to
see all errors)
clang++: error: linker command failed with exit code 1 (use -v to see
invocation)
libtool:   error: error: relink 'libplist++-2.0.la' with the above command
before installing it
make[2]: *** [Makefile:516: install-libLTLIBRARIES] Error 1
make[2]: Leaving directory '/home/chi/ddev/android/cross/bc/src'
make[1]: *** [Makefile:760: install-am] Error 2
make[1]: Leaving directory '/home/chi/ddev/android/cross/bc/src'
make: *** [Makefile:448: install-recursive] Error 1


This problem possibly relates to sr #107416 .

Thank you so much for you time and efforts, I would be glad to provide
additional information if needed.







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/support/?111105>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to