[sr #111105] libtool use incorrect rpath when using sysroot

2024-08-08 Thread Xuntao Chi
URL:
  <https://savannah.gnu.org/support/?05>

 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 
== 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

T

[sr #111105] libtool use incorrect rpath when using sysroot

2024-08-09 Thread Xuntao Chi
Follow-up Comment #2, sr #05 (group libtool):

I can confirm libtool 2.5.1 has fixed the issue. Thanks for your quick reply
and sorry for not checking the latest version.


___

Reply to this item at:

  

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


signature.asc
Description: PGP signature