[PATCH] D114186: [lld][CMake] Add LLD_DEFAULT_NOSTART_STOP_GC
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 18 12:49:01 PST 2021
MaskRay created this revision.
MaskRay added a reviewer: tstellar.
Herald added subscribers: arichardson, mgorny, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This option is for groups who need time to accomodate the ld.lld -z
nostart-stop-gc default.
This is off by default because we have evidence that very few groups
need the behavior. There are anecdotal or non-anecdotal evidences that
many groups are fine with the -z nostart-stop-gc default (matching GNU
ld<2015-10): Android, Chrome OS (Linux), Fuchsia, Google, Meta, SN
systems, some Gentoo Linux users I asked using -fuse-ld=lld (with or
without using Clang). -z nostart-stop-gc default matches ld64 behavior
for `section\$start` symbols and encourages in-tree and out-tree
developers to think about section based linker garbage collection
prudently.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D114186
Files:
lld/CMakeLists.txt
lld/ELF/Driver.cpp
lld/test/CMakeLists.txt
lld/test/ELF/gc-sections-metadata-startstop.s
lld/test/ELF/gc-sections-startstop.s
lld/test/lit.cfg.py
lld/test/lit.site.cfg.py.in
Index: lld/test/lit.site.cfg.py.in
===================================================================
--- lld/test/lit.site.cfg.py.in
+++ lld/test/lit.site.cfg.py.in
@@ -19,6 +19,7 @@
config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@
config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@
+config.ld_lld_default_nostart_stop_gc = @LLD_DEFAULT_NOSTART_STOP_GC@
# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Index: lld/test/lit.cfg.py
===================================================================
--- lld/test/lit.cfg.py
+++ lld/test/lit.cfg.py
@@ -133,3 +133,6 @@
# ELF tests expect the default target for ld.lld to be ELF.
if config.ld_lld_default_mingw:
config.excludes.append('ELF')
+
+if config.ld_lld_default_nostart_stop_gc:
+ config.available_features.add('default-nostart-stop-gc')
Index: lld/test/ELF/gc-sections-startstop.s
===================================================================
--- lld/test/ELF/gc-sections-startstop.s
+++ lld/test/ELF/gc-sections-startstop.s
@@ -1,6 +1,7 @@
## Check that group members are retained or discarded as a unit.
# REQUIRES: x86
+# UNSUPPORTED: default-nostart-stop-gc
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o --gc-sections -o %t
Index: lld/test/ELF/gc-sections-metadata-startstop.s
===================================================================
--- lld/test/ELF/gc-sections-metadata-startstop.s
+++ lld/test/ELF/gc-sections-metadata-startstop.s
@@ -1,4 +1,5 @@
# REQUIRES: x86
+# UNSUPPORTED: default-nostart-stop-gc
# LINK_ORDER cnamed sections are not kept alive by the __start_* reference.
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
Index: lld/test/CMakeLists.txt
===================================================================
--- lld/test/CMakeLists.txt
+++ lld/test/CMakeLists.txt
@@ -11,6 +11,7 @@
LLVM_ENABLE_ZLIB
LLVM_ENABLE_LIBXML2
LLD_DEFAULT_LD_LLD_IS_MINGW
+ LLD_DEFAULT_NOSTART_STOP_GC
LLVM_HAVE_LIBXAR
)
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -1184,8 +1184,17 @@
config->zSeparate = getZSeparate(args);
config->zShstk = hasZOption(args, "shstk");
config->zStackSize = args::getZOptionValue(args, OPT_z, "stack-size", 0);
+#ifdef LLD_DEFAULT_NOSTART_STOP_GC
+ // -z start-stop-gc default matches GNU ld<2015-10 and ld64 section$start
+ // symbols and can decrease file size for many instrumentations. However,
+ // some users need time to accommodate the -z nostart-stop-gc default, so this
+ // is added as a temporary workaround.
+ config->zStartStopGC =
+ getZFlag(args, "start-stop-gc", "nostart-stop-gc", false);
+#else
config->zStartStopGC =
getZFlag(args, "start-stop-gc", "nostart-stop-gc", true);
+#endif
config->zStartStopVisibility = getZStartStopVisibility(args);
config->zText = getZFlag(args, "text", "notext", true);
config->zWxneeded = hasZOption(args, "wxneeded");
Index: lld/CMakeLists.txt
===================================================================
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -176,6 +176,15 @@
add_definitions("-DLLD_DEFAULT_LD_LLD_IS_MINGW=1")
endif()
+option(LLD_DEFAULT_NOSTART_STOP_GC
+ "Default ld.lld to -z nostart-stop-gc. If ON, C identifier name sections are
+ forced retained by __start_/__stop_ references. This may increase output size
+ for many instrumentations, but is compatible with GNU ld newer than 2015-10"
+ OFF)
+if (LLD_DEFAULT_NOSTART_STOP_GC)
+ add_definitions("-DLLD_DEFAULT_NOSTART_STOP_GC=1")
+endif()
+
if (MSVC)
add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114186.388291.patch
Type: text/x-patch
Size: 4035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211118/d2daa2d6/attachment.bin>
More information about the llvm-commits
mailing list