* [musl] [PATCH] musl-clang: handle user's -fuse-ld
@ 2025-02-09 5:21 remph
0 siblings, 0 replies; only message in thread
From: remph @ 2025-02-09 5:21 UTC (permalink / raw)
To: musl; +Cc: remph
musl-clang takes advantage of clang's -fuse-ld option to hijack the
linking process via ld.musl-clang and filter out non-musl system search
paths. However, if the user tries to pass a -fuse-ld of their own,
ld.musl-clang is not called and the linking typically errors out.
---
tools/ld.musl-clang.in | 5 ++++-
tools/musl-clang.in | 28 ++++++++++++++++++----------
2 files changed, 22 insertions(+), 11 deletions(-)
mode change 100644 => 100755 tools/ld.musl-clang.in
mode change 100644 => 100755 tools/musl-clang.in
diff --git a/tools/ld.musl-clang.in b/tools/ld.musl-clang.in
old mode 100644
new mode 100755
index 93763d6b..f87c5742
--- a/tools/ld.musl-clang.in
+++ b/tools/ld.musl-clang.in
@@ -26,6 +26,9 @@ for x ; do
-l-user-end)
userlink=
;;
+ -fuse-ld=*)
+ use_ld=.${x#*=} # Passed through by musl-clang
+ ;;
crtbegin*.o|crtend*.o)
set -- "$@" $($cc -print-file-name=$x)
;;
@@ -48,4 +51,4 @@ for x ; do
esac
done
-exec $($cc -print-prog-name=ld) -nostdlib "$@" -lc -dynamic-linker "$ldso"
+exec "$($cc -print-prog-name=ld$use_ld)" -nostdlib "$@" -lc -dynamic-linker "$ldso"
diff --git a/tools/musl-clang.in b/tools/musl-clang.in
old mode 100644
new mode 100755
index 623de6f6..985b31e3
--- a/tools/musl-clang.in
+++ b/tools/musl-clang.in
@@ -5,19 +5,27 @@ libc_inc="@INCDIR@"
libc_lib="@LIBDIR@"
thisdir="`cd "$(dirname "$0")"; pwd`"
-# prevent clang from running the linker (and erroring) on no input.
-sflags=
-eflags=
+input= cleared= sflags= eflags=
for x ; do
+ test "$cleared" || set -- ; cleared=1
+
+ # prevent clang from running the linker (and erroring) on no input.
+ if test -z "$input" ; then
+ case "$x" in
+ -l*)
+ input=1
+ sflags="-l-user-start"
+ eflags="-l-user-end"
+ ;;
+ esac
+ fi
+
+ # Preserve the user's -fuse-ld
case "$x" in
- -l*) input=1 ;;
- *) input= ;;
+ -fuse-ld=*) x=-Wl,$x ;; # Pass through to ld.musl-clang
esac
- if test "$input" ; then
- sflags="-l-user-start"
- eflags="-l-user-end"
- break
- fi
+
+ set -- "$@" "$x"
done
exec $cc \
--
2.48.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-02-09 5:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-09 5:21 [musl] [PATCH] musl-clang: handle user's -fuse-ld remph
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).