Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Wl,--as-needed flag for all executable builds #37821

Merged
merged 8 commits into from
Mar 3, 2025
Merged
6 changes: 6 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,9 @@ config("specs_default") {
ldflags = cflags
}
}

config("link_as_needed") {
if (current_os == "linux" && is_clang) {
ldflags = [ "-Wl,--as-needed" ]
}
}
5 changes: 5 additions & 0 deletions build/config/defaults.gni
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ declare_args() {
# Defaults configs for pie.
default_configs_pie = [ "${build_root}/config/compiler:pie_default" ]

# Default configs for GNU ld --as-needed
default_configs_link_as_needed =
[ "${build_root}/config/compiler:link_as_needed" ]

# Defaults configs for warnings.
default_configs_warnings =
[ "${build_root}/config/compiler:warnings_default" ]
Expand Down Expand Up @@ -124,3 +128,4 @@ default_configs += default_configs_extra

executable_default_configs = []
executable_default_configs += default_configs_pie
executable_default_configs += default_configs_link_as_needed
Loading