Skip to content

Commit 6cb4568

Browse files
authored
Allow running tests when stdlib is built with LTO by working around autolinking (#34975)
1 parent db90ea2 commit 6cb4568

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

test/lit.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,21 @@ if run_vendor == 'apple':
945945
config.resource_dir_opt = "-resource-dir %s" % new_resource_dir
946946
lit_config.note('Using freestanding resource dir: ' + new_resource_dir)
947947

948+
# Auto-linking does not work when stdlib is built with LTO, because linked
949+
# libraries are discovered too late (after optimizations are applied). Let's
950+
# explicitly link all libraries needed in tests.
951+
#
952+
# Note that this won't work on Linux (without LLD). The autolinking
953+
# mechanism on Linux will fail due to needing -L arguments to the path even
954+
# with this forced linking as the extracted commands will force the linker
955+
# to look up the linking by name as well.
956+
if "stdlib_lto" in config.available_features:
957+
for library in ["swiftCore", "swiftStdlibUnittest",
958+
"swiftSwiftPrivateLibcExtras", "swiftSwiftPrivate",
959+
"swiftDarwin", "swiftSwiftPrivateThreadExtras",
960+
"swiftSwiftOnoneSupport"]:
961+
swift_execution_tests_extra_flags += ' -Xlinker -l%s'% library
962+
948963
xcrun_prefix = (
949964
"xcrun --toolchain %s --sdk %r" %
950965
(config.darwin_xcrun_toolchain, config.variant_sdk))

test/lit.site.cfg.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ if '@SWIFT_TOOLS_ENABLE_LTO@'.lower() in ['full', 'thin']:
8181
else:
8282
config.available_features.add('no_lto')
8383

84+
if '@SWIFT_STDLIB_ENABLE_LTO@'.lower() in ['full', 'thin']:
85+
config.available_features.add('stdlib_lto')
86+
8487
if "@LLVM_ENABLE_ASSERTIONS@" == "TRUE":
8588
config.available_features.add('asserts')
8689
else:

0 commit comments

Comments
 (0)