Skip to content

Commit 9d9efb1

Browse files
MaskRaytstellar
authored andcommitted
[lld][CMake] Add LLD_DEFAULT_NOSTART_STOP_GC
This option is for groups who need time to accomodate the ld.lld -z start-stop-gc default. This is a modified version of https://reviews.llvm.org/D114186 that enables this option by default.
1 parent 52a400d commit 9d9efb1

8 files changed

+26
-0
lines changed

lld/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ if (LLD_DEFAULT_LD_LLD_IS_MINGW)
176176
add_definitions("-DLLD_DEFAULT_LD_LLD_IS_MINGW=1")
177177
endif()
178178

179+
option(LLD_DEFAULT_NOSTART_STOP_GC
180+
"Default ld.lld to -z nostart-stop-gc. If ON, C identifier name sections are
181+
forced retained by __start_/__stop_ references. This may increase output size
182+
for many instrumentations, but is compatible with GNU ld newer than 2015-10"
183+
ON)
184+
if (LLD_DEFAULT_NOSTART_STOP_GC)
185+
add_definitions("-DLLD_DEFAULT_NOSTART_STOP_GC=1")
186+
endif()
187+
179188
if (MSVC)
180189
add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
181190
add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.

lld/ELF/Driver.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,17 @@ static void readConfigs(opt::InputArgList &args) {
11931193
config->zSeparate = getZSeparate(args);
11941194
config->zShstk = hasZOption(args, "shstk");
11951195
config->zStackSize = args::getZOptionValue(args, OPT_z, "stack-size", 0);
1196+
#ifdef LLD_DEFAULT_NOSTART_STOP_GC
1197+
// -z start-stop-gc default matches GNU ld<2015-10 and ld64 section$start
1198+
// symbols and can decrease file size for many instrumentations. However,
1199+
// some users need time to accommodate the -z nostart-stop-gc default, so this
1200+
// is added as a temporary workaround.
1201+
config->zStartStopGC =
1202+
getZFlag(args, "start-stop-gc", "nostart-stop-gc", false);
1203+
#else
11961204
config->zStartStopGC =
11971205
getZFlag(args, "start-stop-gc", "nostart-stop-gc", true);
1206+
#endif
11981207
config->zStartStopVisibility = getZStartStopVisibility(args);
11991208
config->zText = getZFlag(args, "text", "notext", true);
12001209
config->zWxneeded = hasZOption(args, "wxneeded");

lld/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ llvm_canonicalize_cmake_booleans(
1111
LLVM_ENABLE_ZLIB
1212
LLVM_ENABLE_LIBXML2
1313
LLD_DEFAULT_LD_LLD_IS_MINGW
14+
LLD_DEFAULT_NOSTART_STOP_GC
1415
LLVM_HAVE_LIBXAR
1516
)
1617

lld/test/ELF/gc-sections-metadata-startstop.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# REQUIRES: x86
2+
# UNSUPPORTED: default-nostart-stop-gc
23
# LINK_ORDER cnamed sections are not kept alive by the __start_* reference.
34

45
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o

lld/test/ELF/gc-sections-startstop-hint.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# REQUIRES: x86
2+
# UNSUPPORTED: default-nostart-stop-gc
23
## Some projects may not work with GNU ld<2015-10 (ld.lld 13.0.0) --gc-sections behavior.
34
## Give a hint.
45

lld/test/ELF/gc-sections-startstop.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Check that group members are retained or discarded as a unit.
22

33
# REQUIRES: x86
4+
# UNSUPPORTED: default-nostart-stop-gc
45

56
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
67
# RUN: ld.lld %t.o --gc-sections -o %t

lld/test/lit.cfg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@
118118
# ELF tests expect the default target for ld.lld to be ELF.
119119
if config.ld_lld_default_mingw:
120120
config.excludes.append('ELF')
121+
122+
if config.ld_lld_default_nostart_stop_gc:
123+
config.available_features.add('default-nostart-stop-gc')

lld/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ config.have_libxar = @LLVM_HAVE_LIBXAR@
1919
config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
2020
config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@
2121
config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@
22+
config.ld_lld_default_nostart_stop_gc = @LLD_DEFAULT_NOSTART_STOP_GC@
2223

2324
# Support substitution of the tools and libs dirs with user parameters. This is
2425
# used when we can't determine the tool dir at configuration time.

0 commit comments

Comments
 (0)