mirror of
https://github.com/NotAShelf/microfetch.git
synced 2026-04-12 12:57:41 +00:00
build: move link flags to build.rs
Binary-specific link flags (-nostartfiles, -static, section stripping) now use cargo:rustc-link-arg-bin so they don't break proc-macro or build-script linking. ld-wrapper only strips sections from static binaries.
This commit is contained in:
parent
c426e88d99
commit
1539533c54
3 changed files with 29 additions and 23 deletions
|
|
@ -2,20 +2,23 @@
|
|||
# Invoke mold, then strip junk sections from the output binary with objcopy.
|
||||
# This (more or less) removes sections that mold cannot discard itself, suck as:
|
||||
# - .eh_frame / .eh_frame_hdr - unwind tables from compiler_builtins
|
||||
# - dynstr - mold emits this, even for fully static binaries
|
||||
# - .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
|
||||
# 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"
|
||||
break
|
||||
fi
|
||||
prev="$arg"
|
||||
done
|
||||
|
|
@ -23,8 +26,9 @@ done
|
|||
# Invoke mold via the cc driver, forward all original arguments
|
||||
cc -fuse-ld=mold "$@"
|
||||
|
||||
# Remove sections that mold cannot discard
|
||||
if [ -n "$OUTPUT" ] && [ -f "$OUTPUT" ]; then
|
||||
# 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 \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue