mirror of
https://github.com/NotAShelf/microfetch.git
synced 2026-06-17 17:36:55 +00:00
build: replace mold with the wild linker
This commit is contained in:
parent
b43d88c749
commit
b42e6f4af9
8 changed files with 53 additions and 66 deletions
5
scripts/clang-wild
Executable file
5
scripts/clang-wild
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env sh
|
||||
# Link via clang+wild. Wild sits behind the linker (not a rustflag) so a
|
||||
# cross-toolchain that overrides the linker drops it instead of choking on
|
||||
# --ld-path. Needs clang and wild on PATH.
|
||||
exec clang --ld-path=wild "$@"
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
# Invoke mold, then strip junk sections from the output binary with objcopy.
|
||||
# This (more or less) removes sections that mold cannot discard itself, such as:
|
||||
# - .eh_frame / .eh_frame_hdr - unwind tables from compiler_builtins
|
||||
# - .dynstr - mold emits this, even for fully static binaries
|
||||
# - .comment - compiler version string
|
||||
#
|
||||
# We forward everything to mold via -fuse-ld, then post-process the output in place.
|
||||
|
||||
set -eu
|
||||
|
||||
# Locate the output file and detect static linking
|
||||
IS_STATIC=0
|
||||
OUTPUT=""
|
||||
prev=""
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
-static) IS_STATIC=1 ;;
|
||||
esac
|
||||
if [ "$prev" = "-o" ]; then
|
||||
OUTPUT="$arg"
|
||||
fi
|
||||
prev="$arg"
|
||||
done
|
||||
|
||||
# Invoke mold via the cc driver, forward all original arguments
|
||||
cc -fuse-ld=mold "$@"
|
||||
|
||||
# Only strip sections from fully static binaries.
|
||||
# Dynamic executables (i.e. build scripts, proc-macros) need .dynstr at runtime.
|
||||
if [ "$IS_STATIC" = 1 ] && [ -n "$OUTPUT" ] && [ -f "$OUTPUT" ]; then
|
||||
objcopy \
|
||||
--remove-section=.eh_frame \
|
||||
--remove-section=.eh_frame_hdr \
|
||||
--remove-section=.dynstr \
|
||||
--remove-section=.comment \
|
||||
"$OUTPUT"
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue