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:
Amaan Qureshi 2026-03-27 18:03:59 -04:00
commit 1539533c54
No known key found for this signature in database
3 changed files with 29 additions and 23 deletions

View file

@ -3,29 +3,14 @@
# it as a post-link step.
# See:
# <https://github.com/rui314/mold?tab=readme-ov-file#how-to-use>
#
# Binary-specific link flags live in microfetch/build.rs via cargo:rustc-link-arg-bin
# so they only affect the final binary and don't break proc-macro or build-script linking.
[target.'cfg(target_os = "linux")']
linker = "scripts/ld-wrapper"
rustflags = [
# No C runtime, we provide _start ourselves
"-C",
"link-arg=-nostartfiles",
# Fully static, no dynamic linker, no .interp/.dynsym/.dynamic overhead
"-C",
"link-arg=-static",
# Static PIE is incompatible with -static :(
"-C",
"relocation-model=static",
# Suppress .eh_frame emission from our own codegen (does not cover compiler_builtins;
# those remnants are removed by the linker wrapper via objcopy post-link)
"-C",
"force-unwind-tables=no",
# Linker flags
"-C",
"link-arg=-Wl,--gc-sections", # remove unreferenced input sections
"-C",
"link-arg=-Wl,--strip-all", # strip all symbol table entries
"-C",
"link-arg=-Wl,--build-id=none", # omit the .note.gnu.build-id section
"-C",
"link-arg=-Wl,-z,norelro", # disable RELRO (removes relro_padding)
]