Skip to content

Commit 5756300

Browse files
authored
Add -Wl,--as-needed flag for all executable builds (project-chip#37821)
* build: Add -Wl,--as-needed flag for all executable builds PR#33628 has added an explicit link to libatomic for all linux-based builds to fix a build issue on mips. This results with a NEEDED record for libatomic.so.1 even when it's not required. One situation when this happens is building on arm64 with clang. Signed-off-by: Maciej Grela <m.grela@samsung.com> * gn: Restrict --as-needed to only Linux builds using clang Signed-off-by: Maciej Grela <m.grela@samsung.com> * typo Signed-off-by: Maciej Grela <m.grela@samsung.com> * gn: Blacklist instead of whitelist, include ios and explanatory comment Signed-off-by: Maciej Grela <m.grela@samsung.com> --------- Signed-off-by: Maciej Grela <m.grela@samsung.com>
1 parent bb1f2db commit 5756300

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

build/config/compiler/BUILD.gn

+7
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,10 @@ config("specs_default") {
671671
ldflags = cflags
672672
}
673673
}
674+
675+
config("link_as_needed") {
676+
# ld64.lld on clang used by Apple does not have a --as-needed option
677+
if (current_os != "mac" && current_os != "ios") {
678+
ldflags = [ "-Wl,--as-needed" ]
679+
}
680+
}

build/config/defaults.gni

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ declare_args() {
6161
# Defaults configs for pie.
6262
default_configs_pie = [ "${build_root}/config/compiler:pie_default" ]
6363

64+
# Default configs for GNU ld --as-needed
65+
default_configs_link_as_needed =
66+
[ "${build_root}/config/compiler:link_as_needed" ]
67+
6468
# Defaults configs for warnings.
6569
default_configs_warnings =
6670
[ "${build_root}/config/compiler:warnings_default" ]
@@ -124,3 +128,4 @@ default_configs += default_configs_extra
124128

125129
executable_default_configs = []
126130
executable_default_configs += default_configs_pie
131+
executable_default_configs += default_configs_link_as_needed

0 commit comments

Comments
 (0)