[PATCH] ldscript: Omit exec_prefix from SEARCH_DIR when sysroot is specified

Mark Goncharov mark.goncharov@syntacore.com
Tue Jul 1 06:05:44 GMT 2025


The libpath value directly influences the SEARCH_DIR entries in the generated linker scripts.
When creating entries with SEARCH_DIR("=/[path]"), the linker automatically substitutes the sysroot path for the '=' symbol.
As a result, when building with the --with-sysroot flag specified, explicitly adding exec_prefix to the library search path becomes incorrectly.

Signed-off-by: Mark Goncharov <mark.goncharov@syntacore.com>
---
 ld/genscripts.sh | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/ld/genscripts.sh b/ld/genscripts.sh
index 77a1fb465ad..c2f230a6434 100755
--- a/ld/genscripts.sh
+++ b/ld/genscripts.sh
@@ -248,9 +248,12 @@ append_to_lib_path()
 # except when LIBPATH=":".
 if [ "${LIB_PATH}" != ":" ] ; then
   libs=
+  if [ "x${use_sysroot}" != "xyes" ] ; then
+    libpath_exec_prefix="${exec_prefix}/"
+  fi
   if [ "x${TOOL_LIB}" = "x" ] ; then
     if [ "x${NATIVE}" = "xyes" ] ; then
-      libs="${exec_prefix}/${target_alias}/lib"
+      libs="${libpath_exec_prefix}/${target_alias}/lib"
     fi
   else
     # For multilib'ed targets, ensure both ${target_alias}/lib${LIBPATH_SUFFIX}
@@ -261,10 +264,10 @@ if [ "${LIB_PATH}" != ":" ] ; then
     for libpath_suffix in ${LIBPATH_SUFFIX}; do
       case "${NATIVE}:${libpath_suffix}:${TOOL_LIB}" in
 	:* | *::* | *:*:*${libpath_suffix}) ;;
-	*) libs="${exec_prefix}/${target_alias}/lib${libpath_suffix}" ;;
+	*) libs="${libpath_exec_prefix}/${target_alias}/lib${libpath_suffix}" ;;
       esac
     done
-    libs="${exec_prefix}/${TOOL_LIB}/lib ${libs}"
+    libs="${libpath_exec_prefix}/${TOOL_LIB}/lib ${libs}"
   fi
   append_to_lib_path ${libs}
 fi
-- 
2.43.0



More information about the Binutils mailing list