Re: libtool 2.2.2, ccache and -all-static

2008-04-22 Thread Richard Purdie
Hi Ralf,

On Tue, 2008-04-22 at 21:43 +0200, Ralf Wildenhues wrote:
> Thanks for the bug report, and especially for providing an example to
> reproduce it!
> 
> > libtool: link: ccache -static gcc -O20 -ffast-math -D_REENTRANT 
> > -fsigned-char -DUSE_MEMORY_H -o decoder_example decoder_example.o  
> > ../lib/.libs/libvorbis.a -lm /usr/lib/libogg.a
> 
> Confirmed.  Fixed as below, committed, put you in THANKS.

I've confirmed the fix, added it to Poky and dropped the hacks I had,
thanks!

Cheers,

Richard





Re: libtool 2.2.2, darwin and target prefixes

2008-05-02 Thread Richard Purdie
On Fri, 2008-05-02 at 01:03 -0500, Peter O'Gorman wrote:
> Peter O'Gorman wrote:
> > Richard Purdie wrote:
> >> Hi,
> >>
> >> As previously mentioned, I've been stress testing libtool 2.2.2 with
> >> Poky a bit.
> >>
> >> I've found one issue when I tested the darwin builds, specifically that
> >> it tried to use "otool" and "otool64" and not the versions with the host
> >> prefix which my setup has. I fixed this with the patch below which is
> >> fine for Poky since its always cross compiling but its a sign a better
> >> fix is probably needed in general.
> > 
> > Thanks,
> > I have pushed this, it also cleans up the sed sed echo ickyness.
> 
> It is always better if quotes get closed. I had tested, honest!
> 
> Pushed this.

I've updated Poky to use the proper fixes, thanks for looking at this!

Cheers,

Richard







[PATCH 00/12] Yocto Project libtool patch queue

2021-10-25 Thread Richard Purdie
Hi,

I saw comments about a possible pending release and decided to take the 
opportunity to send out the bulk of Yocto Project's patch queue
for libtool. We use it in a cross compiling environment and make
extensive use of the sysroot support in the toolchain so most of our
issues are in that area but there are also some reproducubility and
reduction of unnecessary rpaths tweaks here.

We've been using these patches for many years in some cases so it
would be create to reduce our patchset and share the fixes with others.

Some have been on the libtool mailing lists before but I thought it
simpler to send the set out for review together as a set.

Cheers,

Richard

Khem Raj (3):
  libtool.m4: Rename the --with-sysroot option to avoid conflict with
gcc/binutils
  ltmain.in: Add missing sysroot to library path
  libtool: Check for static libs for internal compiler libraries

Marek Vasut (1):
  libtool: Fix support for NIOS2 processor

Mingli Yu (2):
  Makefile.am: make sure autoheader run before autoconf
  Makefile.am: make sure autoheader run before automake

Richard Purdie (6):
  ltmain.in: Handle trailing slashes on install commands correctly
  ltmain.sh: Fix sysroot paths being encoded into RPATHs
  ltmain.in: Don't encode RATHS which match default linker paths
  libtool.m4: Handle "/" as a sysroot correctly
  ltmain.in: Handle prefix-map compiler options correctly
  libtool.m4: For reproducibility stop encoding hostname in libtool
script

 Makefile.am |  4 +--
 build-aux/ltmain.in | 81 +++--
 m4/libtool.m4   | 25 --
 tests/sysroot.at|  6 ++--
 4 files changed, 89 insertions(+), 27 deletions(-)

-- 
2.25.1




[PATCH 02/12] libtool.m4: Rename the --with-sysroot option to avoid conflict with gcc/binutils

2021-10-25 Thread Richard Purdie
From: Khem Raj 

This patch renames the --with-sysroot option to --with-libtool-sysroot
to avoid namespace conflict with binutils, gcc and other toolchain
components since these componets also add that option to configure
and this becomes confusing and conflicting otherwise.

Signed-off-by: Richard Purdie 
---
 m4/libtool.m4| 12 ++--
 tests/sysroot.at |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index f2d1f398..de2f1ebf 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -1246,28 +1246,28 @@ _LT_DECL([], [ECHO], [1], [An echo program that 
protects backslashes])
 # 
 AC_DEFUN([_LT_WITH_SYSROOT],
 [AC_MSG_CHECKING([for sysroot])
-AC_ARG_WITH([sysroot],
-[AS_HELP_STRING([--with-sysroot@<:@=DIR@:>@],
+AC_ARG_WITH([libtool-sysroot],
+[AS_HELP_STRING([--with-libtool-sysroot@<:@=DIR@:>@],
   [Search for dependent libraries within DIR (or the compiler's sysroot
if not specified).])],
-[], [with_sysroot=no])
+[], [with_libtool_sysroot=no])
 
 dnl lt_sysroot will always be passed unquoted.  We quote it here
 dnl in case the user passed a directory name.
 lt_sysroot=
-case $with_sysroot in #(
+case $with_libtool_sysroot in #(
  yes)
if test yes = "$GCC"; then
  lt_sysroot=`$CC --print-sysroot 2>/dev/null`
fi
;; #(
  /*)
-   lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"`
+   lt_sysroot=`echo "$with_libtool_sysroot" | sed -e "$sed_quote_subst"`
;; #(
  no|'')
;; #(
  *)
-   AC_MSG_RESULT([$with_sysroot])
+   AC_MSG_RESULT([$with_libtool_sysroot])
AC_MSG_ERROR([The sysroot must be an absolute path.])
;;
 esac
diff --git a/tests/sysroot.at b/tests/sysroot.at
index 05faa13d..7a1f9567 100644
--- a/tests/sysroot.at
+++ b/tests/sysroot.at
@@ -64,7 +64,7 @@ while read file; do
 done])
 
 LDFLAGS="$LDFLAGS --sysroot=$sysroot -no-undefined"
-configure_options="$configure_options --with-sysroot=$sysroot --prefix=$prefix"
+configure_options="$configure_options --with-libtool-sysroot=$sysroot 
--prefix=$prefix"
 
 #???
 if test PATH = "$shlibpath_var"; then
@@ -114,7 +114,7 @@ AM_INIT_AUTOMAKE([foreign])
 AC_PROG_CC
 AC_CONFIG_SRCDIR([lib2.c])
 LT_INIT
-sysroot=$with_sysroot
+sysroot=$with_libtool_sysroot
 AC_SUBST([sysroot])
 AC_OUTPUT(Makefile)
 ]])
@@ -155,7 +155,7 @@ AM_INIT_AUTOMAKE([foreign])
 AC_PROG_CC
 AC_CONFIG_SRCDIR([prog.c])
 LT_INIT
-sysroot=$with_sysroot
+sysroot=$with_libtool_sysroot
 AC_SUBST([sysroot])
 AC_OUTPUT(Makefile)
 ]])
-- 
2.25.1




[PATCH 12/12] libtool.m4: For reproducibility stop encoding hostname in libtool script

2021-10-25 Thread Richard Purdie
For reproducibilty, stop encoding the hostname into the libtool script, this 
isn't
really adding much to debugging and most distros are carrying such a patch now 
as
reproducibility is important.

Signed-off-by: Richard Purdie 
---
 m4/libtool.m4 | 1 -
 1 file changed, 1 deletion(-)

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index 022c1292..1a8a2998 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -728,7 +728,6 @@ _LT_CONFIG_SAVE_COMMANDS([
 cat <<_LT_EOF >> "$cfgfile"
 #! $SHELL
 # Generated automatically by $as_me ($PACKAGE) $VERSION
-# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
 # NOTE: Changes made to this file will be lost: look at ltmain.sh.
 
 # Provide generalized library-building support services.
-- 
2.25.1




[PATCH 08/12] libtool: Check for static libs for internal compiler libraries

2021-10-25 Thread Richard Purdie
From: Khem Raj 

Libtool checks only for libraries linked as -l* when trying to
find internal compiler libraries. Clang, however uses the absolute
path to link its internal libraries e.g. compiler_rt. This patch
handles clang's statically linked libraries when finding internal
compiler libraries.

Signed-off-by: Khem Raj 
Signed-off-by: Richard Purdie 
---
 m4/libtool.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index 180dd9d1..022c1292 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -7560,7 +7560,7 @@ if AC_TRY_EVAL(ac_compile); then
   for p in `eval "$output_verbose_link_cmd"`; do
 case $prev$p in
 
--L* | -R* | -l*)
+-L* | -R* | -l* | */libclang_rt.*.a)
# Some compilers place space between "-{L,R}" and the path.
# Remove the space.
if test x-L = "$p" ||
-- 
2.25.1




[PATCH 07/12] libtool: Fix support for NIOS2 processor

2021-10-25 Thread Richard Purdie
From: Marek Vasut 

The name of the system contains the string "nios2". This string
is caught by the some of the greedy checks for OS/2 in libtool,
in particular the *os2* branches of switch statements match for
the nios2 string, which results in incorrect behavior of libtool.

This patch adds an explicit check for *nios2* before the *os2*
checks to prevent the OS/2 check incorrectly trapping the nios2
as well.

Signed-off-by: Marek Vasut 
Signed-off-by: Richard Purdie 
---
 build-aux/ltmain.in | 20 
 1 file changed, 20 insertions(+)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 6fb58ed2..606f17be 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -519,6 +519,12 @@ libtool_validate_options ()
 test : = "$debug_cmd" || func_append preserve_args " --debug"
 
 case $host in
+  # For NIOS2, we want to make sure that it's not caught by the
+  # more general OS/2 check below. Otherwise, NIOS2 is the same
+  # as the default option.
+  *nios2*)
+opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
+;;
   # Solaris2 added to fix 
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
   # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
   *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
@@ -6246,6 +6252,15 @@ func_mode_link ()
if test -n "$library_names" &&
   { test no = "$use_static_libs" || test -z "$old_library"; }; then
  case $host in
+ *nios2*)
+   # For NIOS2, we want to make sure that it's not caught by the
+   # more general OS/2 check below. Otherwise, NIOS2 is the same
+   # as the default option.
+   if test no = "$installed"; then
+ func_append notinst_deplibs " $lib"
+ need_relink=yes
+   fi
+   ;;
  *cygwin* | *mingw* | *cegcc* | *os2*)
  # No point in relinking DLLs because paths are not encoded
  func_append notinst_deplibs " $lib"
@@ -6316,6 +6331,11 @@ func_mode_link ()
elif test -n "$soname_spec"; then
  # bleh windows
  case $host in
+ *nios2*)
+   # For NIOS2, we want to make sure that it's not caught by the
+   # more general OS/2 check below. Otherwise, NIOS2 is the same
+   # as the default option.
+   ;;
  *cygwin* | mingw* | *cegcc* | *os2*)
func_arith $current - $age
major=$func_arith_result
-- 
2.25.1




[PATCH 11/12] ltmain.in: Handle prefix-map compiler options correctly

2021-10-25 Thread Richard Purdie
If lto is enabled, we need the prefix-map variables to be passed to the linker.
Add these to the list of options libtool passes through.

Signed-off-by: Richard Purdie 
---
 build-aux/ltmain.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 606f17be..7dc2e897 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -5392,10 +5392,11 @@ func_mode_link ()
   # -stdlib=*select c++ std lib with clang
   # -fsanitize=* Clang/GCC memory and address sanitizer
   # -fuse-ld=*   Linker select flags for GCC
+  # -f*-prefix-map*  needed for lto linking
   -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
   
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
   
-O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
-  -specs=*|-fsanitize=*|-fuse-ld=*)
+  -specs=*|-fsanitize=*|-fuse-ld=*|-f*-prefix-map*)
 func_quote_arg pretty "$arg"
arg=$func_quote_arg_result
 func_append compile_command " $arg"
-- 
2.25.1




[PATCH 10/12] Makefile.am: make sure autoheader run before automake

2021-10-25 Thread Richard Purdie
From: Mingli Yu 

When use automake to generate Makefile.in from Makefile.am, there
comes below race:
 | configure.ac:45: error: required file 'config-h.in' not found

It is because the file config-h.in in updating process by autoheader,
so make automake run after autoheader to avoid the above race.

Signed-off-by: Mingli Yu 
Signed-off-by: Richard Purdie 
---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 84795d87..8c9949ed 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -333,7 +333,7 @@ EXTRA_DIST += $(lt_aclocal_m4) \
  $(lt_obsolete_m4) \
  $(stamp_mk)
 
-$(lt_Makefile_in): $(lt_Makefile_am) $(lt_aclocal_m4)
+$(lt_Makefile_in): $(lt_Makefile_am) $(lt_aclocal_m4) $(lt_config_h_in)
$(AM_V_GEN)cd '$(srcdir)/$(ltdl_dir)' && $(AUTOMAKE) Makefile
 
 # Don't let unused scripts leak into the libltdl Makefile
-- 
2.25.1




[PATCH 03/12] ltmain.in: Add missing sysroot to library path

2021-10-25 Thread Richard Purdie
From: Khem Raj 

When using a sysroot we should append it to libdir, which is helpful in
cross builds as the system is staged in the sysroot. For normal builds,
i.e. when lt_sysroot is not set, it will still behave the same and add
-L/usr/lib to the relink command.

Signed-off-by: Richard Purdie 
---
 build-aux/ltmain.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 3d5dcd0a..2c994612 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -6475,7 +6475,7 @@ func_mode_link ()
  fi
else
  # We cannot seem to hardcode it, guess we'll fake it.
- add_dir=-L$libdir
+ add_dir="-L$lt_sysroot$libdir"
  # Try looking first in the location we're being installed to.
  if test -n "$inst_prefix_dir"; then
case $libdir in
-- 
2.25.1




[PATCH 05/12] ltmain.in: Don't encode RATHS which match default linker paths

2021-10-25 Thread Richard Purdie
We don't want to add RPATHS which match default linker search paths, they're
a waste of space. This patch filters libtools list of paths to encoode and
removes the ones we don't need.

Libtool may be passed link paths of the form "/usr/lib/../lib" so normalize
the paths before comparision.

Signed-off-by: Richard Purdie 
---
 build-aux/ltmain.in | 34 --
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 96238350..6fb58ed2 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -7672,8 +7672,16 @@ EOF
  esac
fi
  else
-   eval flag=\"$hardcode_libdir_flag_spec\"
-   func_append dep_rpath " $flag"
+# We only want to hardcode in an rpath if it isn't in the
+# default dlsearch path.
+func_normal_abspath "$libdir"
+libdir_norm=$func_normal_abspath_result
+   case " $sys_lib_dlsearch_path " in
+   *" $libdir_norm "*) ;;
+   *) eval flag=\"$hardcode_libdir_flag_spec\"
+   func_append dep_rpath " $flag"
+   ;;
+   esac
  fi
elif test -n "$runpath_var"; then
  case "$perm_rpath " in
@@ -8406,8 +8414,16 @@ EOF
  esac
fi
  else
-   eval flag=\"$hardcode_libdir_flag_spec\"
-   func_append rpath " $flag"
+# We only want to hardcode in an rpath if it isn't in the
+# default dlsearch path.
+func_normal_abspath "$libdir"
+libdir_norm=$func_normal_abspath_result
+   case " $sys_lib_dlsearch_path " in
+   *" $libdir_norm "*) ;;
+   *) eval flag=\"$hardcode_libdir_flag_spec\"
+   rpath+=" $flag"
+   ;;
+   esac
  fi
elif test -n "$runpath_var"; then
  case "$perm_rpath " in
@@ -8461,8 +8477,14 @@ EOF
  esac
fi
  else
-   eval flag=\"$hardcode_libdir_flag_spec\"
-   func_append rpath " $flag"
+# We only want to hardcode in an rpath if it isn't in the
+# default dlsearch path.
+   case " $sys_lib_dlsearch_path " in
+   *" $libdir "*) ;;
+   *) eval flag=\"$hardcode_libdir_flag_spec\"
+   func_append rpath " $flag"
+   ;;
+   esac
  fi
elif test -n "$runpath_var"; then
  case "$finalize_perm_rpath " in
-- 
2.25.1




[PATCH 06/12] libtool.m4: Handle "/" as a sysroot correctly

2021-10-25 Thread Richard Purdie
Update libtool.m4 to resolve a problem with lt_sysroot not being properly
updated if the option '--with[-libtool]-sysroot' is not provided when
running the 'configure' script for a package so that "/" as a sysroot
is handled correctly by libtool.

Signed-off-by: Richard Purdie 
---
 m4/libtool.m4 | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index de2f1ebf..180dd9d1 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -1256,16 +1256,20 @@ dnl lt_sysroot will always be passed unquoted.  We 
quote it here
 dnl in case the user passed a directory name.
 lt_sysroot=
 case $with_libtool_sysroot in #(
- yes)
+ no)
if test yes = "$GCC"; then
  lt_sysroot=`$CC --print-sysroot 2>/dev/null`
+ # Treat "/" the same a an unset sysroot.
+ if test "$lt_sysroot" = /; then
+   lt_sysroot=
+ fi
fi
;; #(
+ yes|''|/)
+   ;; #(
  /*)
lt_sysroot=`echo "$with_libtool_sysroot" | sed -e "$sed_quote_subst"`
;; #(
- no|'')
-   ;; #(
  *)
AC_MSG_RESULT([$with_libtool_sysroot])
AC_MSG_ERROR([The sysroot must be an absolute path.])
-- 
2.25.1




[PATCH 09/12] Makefile.am: make sure autoheader run before autoconf

2021-10-25 Thread Richard Purdie
From: Mingli Yu 

autoheader will update ../libtool-2.4.6/libltdl/config-h.in which
autoconf needs, so there comes a race sometimes as below:
 | configure.ac:45: error: required file 'config-h.in' not found
 | touch '../libtool-2.4.6/libltdl/config-h.in'

So make sure autoheader run before autoconf to avoid this race.

Signed-off-by: Mingli Yu 
Signed-off-by: Richard Purdie 
---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 6b546092..84795d87 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -370,7 +370,7 @@ lt_configure_deps = $(lt_aclocal_m4) $(lt_aclocal_m4_deps)
 $(lt_aclocal_m4): $(lt_aclocal_m4_deps)
$(AM_V_GEN)cd '$(srcdir)/$(ltdl_dir)' && $(ACLOCAL) -I ../m4
 
-$(lt_configure): $(lt_configure_deps)
+$(lt_configure): $(lt_configure_deps) $(lt_config_h_in)
$(AM_V_GEN)cd '$(srcdir)/$(ltdl_dir)' && $(AUTOCONF)
 
 $(lt_config_h_in): $(lt_configure_deps)
-- 
2.25.1




[PATCH 04/12] ltmain.sh: Fix sysroot paths being encoded into RPATHs

2021-10-25 Thread Richard Purdie
There is a bug where RPATHs could end up containing sysroot values when
cross compiling which is obviously incorrect. Strip out sysroot components
from libdir when building RPATH values to avoid this.

Signed-off-by: Richard Purdie 
---
 build-aux/ltmain.in | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 2c994612..96238350 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -7654,9 +7654,11 @@ EOF
  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
  for libdir in $rpath; do
if test -n "$hardcode_libdir_flag_spec"; then
+ func_replace_sysroot "$libdir"
+ libdir=$func_replace_sysroot_result
+ func_stripname '=' '' "$libdir"
+ libdir=$func_stripname_result
  if test -n "$hardcode_libdir_separator"; then
-   func_replace_sysroot "$libdir"
-   libdir=$func_replace_sysroot_result
if test -z "$hardcode_libdirs"; then
  hardcode_libdirs=$libdir
else
@@ -8386,6 +8388,10 @@ EOF
   hardcode_libdirs=
   for libdir in $compile_rpath $finalize_rpath; do
if test -n "$hardcode_libdir_flag_spec"; then
+ func_replace_sysroot "$libdir"
+ libdir=$func_replace_sysroot_result
+ func_stripname '=' '' "$libdir"
+ libdir=$func_stripname_result
  if test -n "$hardcode_libdir_separator"; then
if test -z "$hardcode_libdirs"; then
  hardcode_libdirs=$libdir
@@ -8437,6 +8443,10 @@ EOF
   hardcode_libdirs=
   for libdir in $finalize_rpath; do
if test -n "$hardcode_libdir_flag_spec"; then
+ func_replace_sysroot "$libdir"
+ libdir=$func_replace_sysroot_result
+ func_stripname '=' '' "$libdir"
+ libdir=$func_stripname_result
  if test -n "$hardcode_libdir_separator"; then
if test -z "$hardcode_libdirs"; then
  hardcode_libdirs=$libdir
-- 
2.25.1




[PATCH 01/12] ltmain.in: Handle trailing slashes on install commands correctly

2021-10-25 Thread Richard Purdie
A command like:

libtool --mode=install /usr/bin/install -c gck-roots-store-standalone.la 
'/image/usr/lib/gnome-keyring/standalone/'

where the path ends with a trailing slash currently fails. This occurs in
software like gnome-keyring or pulseaudio and is because the comparision
code doesn't see the paths as equal. Strip both paths to ensure this works
reliably.

Signed-off-by: Richard Purdie 
---
 build-aux/ltmain.in | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 96b37003..3d5dcd0a 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -2378,8 +2378,14 @@ func_mode_install ()
func_append dir "$objdir"
 
if test -n "$relink_command"; then
+ # Strip any trailing slash from the destination.
+ func_stripname '' '/' "$libdir"
+ destlibdir=$func_stripname_result
+ func_stripname '' '/' "$destdir"
+ s_destdir=$func_stripname_result
+
  # Determine the prefix the user has applied to our future dir.
- inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
+ inst_prefix_dir=`$ECHO "X$s_destdir" | $Xsed -e "s%$destlibdir\$%%"`
 
  # Don't allow the user to place us outside of our expected
  # location b/c this prevents finding dependent libraries that
-- 
2.25.1




Re: [PATCH v2 01/12] ltmain.sh: Fix sysroot paths being encoded into RPATHs

2022-04-20 Thread Richard Purdie
On Wed, 2022-04-20 at 01:12 +0100, Sam James wrote:
> 
> > On 17 Apr 2022, at 05:55, Alex Ameen  wrote:
> > 
> > This was all green down the line on the test suite on multiple systems (
> > don't get too excited yet ) until I found bugs in the testsuite...
> > 
> > I see how this flew under the radar previously though - currently there are
> > no tests which attempt to check RPATH or RUNPATH entries. I'll definitely be
> > working on that... I'm going to be working out some M4 macros to abstract
> > some functions like `lt_read_pheader([BIN], [ENTRY])',
> > `lt_read_rpath([BIN])', and `lt_read_runpath([BIN])', so that those can be
> > abstracted for handling non-ELF binaries.
> > 
> > I'll make a test case to the effect of `readelf -d -W BIN|grep -v
> > "$sysroot/";', if you have any additional input on new test cases let me
> > know.
> > 
> > You also helped me catch some bad regex in the existing sysroot tests that
> > would cause them to never be run on a system which used '/' as their GCC
> > sysroot ( all of dpkg's  cross compilers seem to... ).
> 
> Nice! I've found a *lot* of things don't respect this case, actually.
> 
> > 
> > So a big thank you for helping to catch all of these places that the tool
> > can be improved.
> > 
> > Naturally now that test cases aren't skipped they're red, so once I sanity
> > check that they fail on the mainline branch I can move forward. I'm ~99%
> > sure this patch will have no effect on those results.
> > 
> > 
> 
> FWIW, given the comments on the main libtool ML, I at least am happy to drop
> this one for now, and revisit later. Richard might feel differently though.

I think this one is ok, it would be "ltmain.in: Don't encode RATHS which match
default linker paths" which is being questioned. We see a awful lot of it and I
don't think we need them but I can see the concern others are raising even if it
what I think should be a more unusual use case. It may be something that could
be configured ultimately?

> I like incremental progress so the more easy stuff in, the better, even if it
> means we have to come back to some of the harder ones.

Definitely agreed. I'd rather we make progress on the things we can agree on
that block on that.

Cheers,

Richard




Re: [PATCH v2 00/12] Rebased version of Yocto patches

2022-11-20 Thread Richard Purdie
On Sat, 2022-11-19 at 18:32 +, Sam James wrote:
> 
> > On 16 Apr 2022, at 18:58, Sam James  wrote:
> > 
> > Done after discussion w/ Alex (thanks!). Rebased on master after
> > 2.4.7 release.
> 
> Ping. Could we maybe get the easy ones in and then revisit
> the bits which received comments (unclear to me what we need
> to do for those)?

I'd second that, I'd love to get the easy ones sorted and am happy to
try and help with the others, just not quite sure where we stand at the
moment.

Cheers,

Richard



Re: [PATCH 02/12] libtool.m4: Rename the --with-sysroot option to avoid conflict with gcc/binutils

2024-01-16 Thread Richard Purdie





Re: [PATCH 02/12] libtool.m4: Rename the --with-sysroot option to avoid conflict with gcc/binutils

2024-01-16 Thread Richard Purdie
Somehow my original reply ended up blank, sorry. I've retyped it from
memory as best I can.

On Mon, 2024-01-15 at 20:08 -0500, Mike Frysinger wrote:
> On 25 Oct 2021 15:33, Richard Purdie wrote:
> > This patch renames the --with-sysroot option to --with-libtool-sysroot
> > to avoid namespace conflict with binutils, gcc and other toolchain
> > components since these componets also add that option to configure
> > and this becomes confusing and conflicting otherwise.
> 
> we're talking like 3 projects ?  libtool is used & included in way more
> projects than that.  it seems like --with-sysroot as a standard name to
> propagate out into the wider ecosystem makes more sense.

You're saying binutils and gcc should change? I'm fairly sure they'll
decline to do that. Their options are encoded into quite a few cross
compiling documents and build systems.

> i agree there's confusion between "use this path as a sysroot to compile
> and link against" and "have the compile tools target this sysroot".  the
> same problem exists with host selection which is why we have the build,
> host, and target options.  sounds like we want names that can align with
> these somehow.

FWIW gcc and binutils have gone with --with-sysroot and --with-build-
sysroot to differentiate. Unfortunately that doesn't really help
libtool (see below).

> --with-libtool-sysroot doesn't make sense as it isn't an internal libtool
> setting, it's changing how executables are linked, and users (who run the
> configure scripts) don't know or care about this "libtool" thing.

I think it partly depends upon how you view it. Most of the time
libtool uses `$CC --print-sysroot` to set this and therefore most users
wouldn't use the commandline option. In general you do want the
compiler/linker and libtool to be working the same way.

The challenge is that binutils/gcc and libtool have adopted different
meanings for the same option and if/as/where the commandline options
get passed around, things can become quite broken when cross compiling.

My ask is to try and find a way to avoid the confusion (and the need
for Yocto Project to have to patch one set of components to make things
work).

The options as I see it are:

a) Use a libtool specific option (as per the patch under review)

b) Stop providing a commandline option for libtool and rely on the
compiler query.

c) Switch to --with-build-sysroot

d) Switch to --sysroot

e) Ask gcc/binutils to change


I can't see gcc/binutils changing. Using c/d would likely have a
different set of issues. For example in some cases you do want the
build sysroot and sometimes the target with libtool so c swaps one set
of problems for another. 

Since most of the time users never need to care about setting this
option and we couldn't find an alternative, changing it as per the
patch seemed like the least worst solution and  was why we end up with
a).

Would:

--with-sysroot-libtool

be any better?

I'm open to other ideas.

Cheers,

Richard






[PATCH 3/3] libtool: Fix support for NIOS2 processor

2024-01-16 Thread Richard Purdie
The name of the system contains the string "nios2". This string
is caught by the some of the greedy checks for OS/2 in libtool,
in particular the *os2* branches of switch statements match for
the nios2 string, which results in incorrect behavior of libtool.

Switch to use $host_os instead of $host and tweak the patterns to
match to avoid this problem for nios2.

* build-aux/ltmain.in: Fix NIOS2 support
---
 build-aux/ltmain.in | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index cf6dc13a..ac11b7ae 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -517,10 +517,10 @@ libtool_validate_options ()
 # preserve --debug
 test : = "$debug_cmd" || func_append preserve_args " --debug"
 
-case $host in
+case $host_os in
   # Solaris2 added to fix 
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
   # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
-  *cygwin* | *mingw* | *windows* | *pw32* | *cegcc* | *solaris2* | *os2*)
+  cygwin* | mingw* | windows* | pw32* | cegcc* | solaris2* | os2*)
 # don't eliminate duplications in $postdeps and $predeps
 opt_duplicate_compiler_generated_deps=:
 ;;
@@ -6279,8 +6279,8 @@ func_mode_link ()
fi
if test -n "$library_names" &&
   { test no = "$use_static_libs" || test -z "$old_library"; }; then
- case $host in
- *cygwin* | *mingw* | *windows* | *cegcc* | *os2*)
+ case $host_os in
+ cygwin* | mingw* | windows* | cegcc* | os2*)
  # No point in relinking DLLs because paths are not encoded
  func_append notinst_deplibs " $lib"
  need_relink=no
@@ -6349,8 +6349,8 @@ func_mode_link ()
  soname=$dlname
elif test -n "$soname_spec"; then
  # bleh windows
- case $host in
- *cygwin* | mingw* | *windows* | *cegcc* | *os2*)
+ case $host_os in
+ cygwin* | mingw* | windows* | cegcc* | os2*)
func_arith $current - $age
major=$func_arith_result
versuffix=-$major
-- 
2.39.2




[PATCH 2/3] ltmain.in: Parse additional clang options

2024-01-16 Thread Richard Purdie
clang uses -rtlib and --unwindlib to select proper compiler runtime in
some cases. Therefore pass these options to linker when found in
ldflags

* build-aux/ltmain.in: Handle clang linker options
---
 build-aux/ltmain.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 34784c8c..cf6dc13a 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -5412,12 +5412,14 @@ func_mode_link ()
   # -shared-libsan   Link with shared sanitizer runtimes (Clang)
   # -static-libsan   Link with static sanitizer runtimes (Clang)
   # -fuse-ld=*   Linker select flags for GCC
+  # -rtlib=* select c runtime lib with clang
+  # --unwindlib=*select unwinder library with clang
   # -f{file|debug|macro}-prefix-map* needed for lto linking
   # -Wa,*Pass flags directly to the assembler
   # -Werror, -Werror=*   Report (specified) warnings as errors
   -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
   
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
-  
-O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
+  
-O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*|-rtlib=*|--unwindlib=*|
 \
   -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \
   -ffile-prefix-map*|-fdebug-prefix-map*|-fmacro-prefix-map*| \
   -fdiagnostics-color*|-frecord-gcc-switches| \
-- 
2.39.2




[PATCH 1/3] ltmain.in: Handle prefix-map compiler options correctly

2024-01-16 Thread Richard Purdie
If lto is enabled, we need the prefix-map variables to be passed to the linker
to correctly link the objects using correctly mapped paths.

Add these to the list of options libtool passes through.

* build-aux/ltmain.in: Handle prefix-map compiler options
---
 build-aux/ltmain.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index d5157a8d..34784c8c 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -7,7 +7,6 @@
 # Copyright (C) 1996-2019, 2021-2024 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.
-
 # GNU Libtool is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or
@@ -5413,12 +5412,14 @@ func_mode_link ()
   # -shared-libsan   Link with shared sanitizer runtimes (Clang)
   # -static-libsan   Link with static sanitizer runtimes (Clang)
   # -fuse-ld=*   Linker select flags for GCC
+  # -f{file|debug|macro}-prefix-map* needed for lto linking
   # -Wa,*Pass flags directly to the assembler
   # -Werror, -Werror=*   Report (specified) warnings as errors
   -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
   
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
   
-O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
   -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \
+  -ffile-prefix-map*|-fdebug-prefix-map*|-fmacro-prefix-map*| \
   -fdiagnostics-color*|-frecord-gcc-switches| \
   -fuse-ld=*|-Wa,*|-Werror|-Werror=*)
 func_quote_arg pretty "$arg"
-- 
2.39.2




Re: [PATCH 05/12] ltmain.in: Don't encode RATHS which match default linker paths

2024-01-16 Thread Richard Purdie
On Mon, 2024-01-15 at 20:10 -0500, Mike Frysinger wrote:
> On 25 Oct 2021 15:33, Richard Purdie wrote:
> > We don't want to add RPATHS which match default linker search paths, they're
> > a waste of space. This patch filters libtools list of paths to encoode and
> > removes the ones we don't need.
> 
> how are you defining "linker" ?  are you talking about the runtime linker
> (i.e. ld.so) or the build time linker (i.e. `ld`) ?

I meant the runtime linker/loader ld.so.

> the commit message also doesn't really explain in concrete details the
> scenario you're running into.

We were seeing binaries with RPATHS like /usr/lib in them which
basically doesn't do anything useful since it is a default for ld.so.
We were therefore trying to remove those to improve the efficiency of
the binaries slightly.

Cheers,

Richard





[PATCH] libtool.m4: Handle "/" as a sysroot more correctly

2024-01-16 Thread Richard Purdie
If $CC has --sysroot=/, it is a valid configuration however libtool will
then set lt_sysroot to "/".

This means references like $lt_sysroot$libdir become //usr/lib instead
of the more normally expected /usr/lib. This may or may not break something
but certainly is confusing to the user and gives confusing output. Making
"/" simply unset lt_sysroot is much cleaner.

* m4/libtool.m4: Improve '/' sysroot handling
---
 m4/libtool.m4 | 4 
 1 file changed, 4 insertions(+)

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index 695ccac4..1c8ea182 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -1256,6 +1256,10 @@ case $with_sysroot in #(
  yes)
if test yes = "$GCC"; then
  lt_sysroot=`$CC --print-sysroot 2>/dev/null`
+ # Treat "/" the same a an unset sysroot to avoid ugly // expansion for 
$lt_sysroot$libdir
+ if test "$lt_sysroot" = /; then
+   lt_sysroot=
+ fi
fi
;; #(
  /*)
-- 
2.39.2




Re: [PATCH 06/12] libtool.m4: Handle "/" as a sysroot correctly

2024-01-16 Thread Richard Purdie
On Mon, 2024-01-15 at 17:00 -0500, Mike Frysinger wrote:
> On 25 Oct 2021 15:33, Richard Purdie wrote:
> > Update libtool.m4 to resolve a problem with lt_sysroot not being properly
> > updated if the option '--with[-libtool]-sysroot' is not provided when
> > running the 'configure' script for a package so that "/" as a sysroot
> > is handled correctly by libtool.
> 
> this is a long sentence, and there's no concrete examples, so i'm having a
> bit of trouble extrapolating the bug.  can you tweak this a bit to make it
> more clear ?

I've resent with part of that patch and a clearer explanation of what
the issue is. I need to look into what the other bit of the patch is
doing, it looks a bit like two different changes became intertwined.

Cheers,

Richard






Re: [PATCH 1/3] ltmain.in: Handle prefix-map compiler options correctly

2024-01-17 Thread Richard Purdie
On Tue, 2024-01-16 at 20:47 -0500, Mike Frysinger wrote:
> On 16 Jan 2024 15:14, Richard Purdie wrote:
> > --- a/build-aux/ltmain.in
> > +++ b/build-aux/ltmain.in
> > @@ -7,7 +7,6 @@
> >  # Copyright (C) 1996-2019, 2021-2024 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.
> > -
> >  # GNU Libtool is free software; you can redistribute it and/or modify
> >  # it under the terms of the GNU General Public License as published by
> >  # the Free Software Foundation; either version 2 of the License, or
> 
> let's leave unrelated changes out please

Sorry.

> 
> > @@ -5413,12 +5412,14 @@ func_mode_link ()
> ># -shared-libsan   Link with shared sanitizer runtimes (Clang)
> ># -static-libsan   Link with static sanitizer runtimes (Clang)
> ># -fuse-ld=*   Linker select flags for GCC
> > +  # -f{file|debug|macro}-prefix-map* needed for lto linking
> 
> these take the form of -ffile-prefix-map=xxx right ?

Yes. There was talk of a 'read from file' version but that doesn't look
like it was merged anywhere.

> so we'd want to put a = before the glob at the end ?

Sure. I'll also add profile-prefix-map for completeness since it looks
like the naming debate was settled on that one and it was merged (I
personally don't need it).

Cheers,

Richard



[PATCH 3/3] libtool.m4: Cleanup sysroot trailing "/"

2024-01-17 Thread Richard Purdie
If $CC has --sysroot=/, it is a valid configuration however libtool will
then set lt_sysroot to "/".

This means references like $lt_sysroot$libdir become //usr/lib instead
of the more normally expected /usr/lib. This may or may not break something
but certainly is confusing to the user and gives confusing output. Making
"/" simply unset lt_sysroot is much cleaner.

Whilst here, trim any trailing '/' from sysroot paths to drop the duplication
and result in cleaner/consistent output.

* m4/libtool.m4: Cleanup sysroot trailing '/' handling
---
 m4/libtool.m4 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index ed572bb3..f2532f0e 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -1255,7 +1255,9 @@ lt_sysroot=
 case $with_sysroot in #(
  yes)
if test yes = "$GCC"; then
- lt_sysroot=`$CC --print-sysroot 2>/dev/null`
+ # Trim trailing / since we'll always append absolute paths and we want
+ # to avoid //, if only for less confusing output for the user.
+ lt_sysroot=`$CC --print-sysroot 2>/dev/null | $SED 's:/\+$::'`
fi
;; #(
  /*)
-- 
2.39.2




[PATCH 1/3] ltmain.in: Handle prefix-map compiler options correctly

2024-01-17 Thread Richard Purdie
If lto is enabled, we need the prefix-map variables to be passed to the linker
to correctly link the objects using correctly mapped paths.

Add these to the list of options libtool passes through.

* build-aux/ltmain.in: Handle prefix-map compiler options
---
 build-aux/ltmain.in | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 830b3982..5b59d959 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -5413,12 +5413,14 @@ func_mode_link ()
   # -shared-libsan   Link with shared sanitizer runtimes (Clang)
   # -static-libsan   Link with static sanitizer runtimes (Clang)
   # -fuse-ld=*   Linker select flags for GCC
+  # -f{file|debug|macro|profile}-prefix-map* needed for lto linking
   # -Wa,*Pass flags directly to the assembler
   # -Werror, -Werror=*   Report (specified) warnings as errors
   -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
   
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
   
-O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
   -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \
+  
-ffile-prefix-map=*|-fdebug-prefix-map=*|-fmacro-prefix-map=*|-fprofile-prefix-map=*|
 \
   -fdiagnostics-color*|-frecord-gcc-switches| \
   -fuse-ld=*|-Wa,*|-Werror|-Werror=*)
 func_quote_arg pretty "$arg"
-- 
2.39.2




[PATCH 2/3] ltmain.in: Parse additional clang options

2024-01-17 Thread Richard Purdie
clang uses -rtlib and --unwindlib to select proper compiler runtime in
some cases. Therefore pass these options to linker when found in
ldflags

* build-aux/ltmain.in: Handle clang linker options
---
 build-aux/ltmain.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 5b59d959..8a832a47 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -5413,12 +5413,14 @@ func_mode_link ()
   # -shared-libsan   Link with shared sanitizer runtimes (Clang)
   # -static-libsan   Link with static sanitizer runtimes (Clang)
   # -fuse-ld=*   Linker select flags for GCC
+  # -rtlib=* select c runtime lib with clang
+  # --unwindlib=*select unwinder library with clang
   # -f{file|debug|macro|profile}-prefix-map* needed for lto linking
   # -Wa,*Pass flags directly to the assembler
   # -Werror, -Werror=*   Report (specified) warnings as errors
   -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
   
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
-  
-O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
+  
-O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*|-rtlib=*|--unwindlib=*|
 \
   -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \
   
-ffile-prefix-map=*|-fdebug-prefix-map=*|-fmacro-prefix-map=*|-fprofile-prefix-map=*|
 \
   -fdiagnostics-color*|-frecord-gcc-switches| \
-- 
2.39.2




[PATCH] libtool.m4: Fix AC_CHECK_PROG usage

2024-06-02 Thread Richard Purdie
In commit:

https://git.savannah.gnu.org/cgit/libtool.git/commit/m4/libtool.m4?id=64bef5ba65f6820cd5f88e5249324b4f5955ee25

AC_CHECK_TOOL was changed to AC_CHECK_PROG however the arguments are
different and this result is a value of ":". Change this to match the
original intent.

The lack of FILECMD was causing failures for mips64 builds as -m elf was
being passed to LD which isn't supported on our targets.

Signed-off-by: Richard Purdie 
---
 m4/libtool.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index c5be6436..bbf2d21f 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -8216,7 +8216,7 @@ AC_SUBST([DLLTOOL])
 # 
 # Check for a file(cmd) program that can be used to detect file type and magic
 m4_defun([_LT_DECL_FILECMD],
-[AC_CHECK_PROG([FILECMD], [file], [:])
+[AC_CHECK_PROG([FILECMD], [file], [file], [:])
 _LT_DECL([], [FILECMD], [1], [A file(cmd) program that detects file types])
 ])# _LD_DECL_FILECMD