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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,10 @@ config("specs_default") {
ldflags = cflags
}
}

config("link_as_needed") {
# ld64.lld on clang used by Apple does not have a --as-needed option
if (current_os != "mac" && current_os != "ios") {
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