Skip to content

[DNM] Revert "IRGen: Use llvm.compiler.used instead of llvm.used on ELF" #71373

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

Closed
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
11 changes: 0 additions & 11 deletions lib/Driver/UnixToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,6 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
#else
Arguments.push_back(context.Args.MakeArgString("-fuse-ld=" + Linker));
#endif
// Starting with lld 13, Swift stopped working with the lld --gc-sections
// implementation for ELF, unless -z nostart-stop-gc is also passed to lld:
//
// https://reviews.llvm.org/D96914
if (Linker == "lld" || (Linker.length() > 5 &&
Linker.substr(Linker.length() - 6) == "ld.lld")) {
Arguments.push_back("-Xlinker");
Arguments.push_back("-z");
Arguments.push_back("-Xlinker");
Arguments.push_back("nostart-stop-gc");
}
}

// Configure the toolchain.
Expand Down
9 changes: 0 additions & 9 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,15 +1030,6 @@ bool LinkInfo::isUsed(IRLinkage IRL) {
///
/// This value must have a definition by the time the module is finalized.
void IRGenModule::addUsedGlobal(llvm::GlobalValue *global) {

// As of reviews.llvm.org/D97448 "ELF: Create unique SHF_GNU_RETAIN sections
// for llvm.used global objects" LLVM creates separate sections for globals in
// llvm.used on ELF. Therefore we use llvm.compiler.used on ELF instead.
if (TargetInfo.OutputObjectFormat == llvm::Triple::ELF) {
addCompilerUsedGlobal(global);
return;
}

LLVMUsed.push_back(global);
}

Expand Down
35 changes: 22 additions & 13 deletions stdlib/public/runtime/SwiftRT-ELF-WASM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,39 @@ static const void *__backtraceRef __attribute__((used))
// the linker table section was never constructed.
#if defined(__ELF__)
# define DECLARE_EMPTY_METADATA_SECTION(name) __asm__("\t.section " #name ",\"a\"\n");
# define DECLARE_EMPTY_RETAINED_METADATA_SECTION(name) __asm__("\t.section " #name ",\"aR\"\n");
#elif defined(__wasm__)
# define DECLARE_EMPTY_METADATA_SECTION(name) __asm__("\t.section " #name ",\"\",@\n");
# define DECLARE_EMPTY_RETAINED_METADATA_SECTION(name) DECLAREDECLARE_EMPTY_METADATA_SECTION(name)
#endif

#define DECLARE_SWIFT_SECTION(name) \
DECLARE_EMPTY_METADATA_SECTION(name) \
#define DECLARE_SWIFT_ENCAPSULATION_SYMBOLS(name) \
__attribute__((__visibility__("hidden"),__aligned__(1))) extern const char __start_##name; \
__attribute__((__visibility__("hidden"),__aligned__(1))) extern const char __stop_##name;

#define DECLARE_SWIFT_SECTION(name) \
DECLARE_EMPTY_METADATA_SECTION(name) \
DECLARE_SWIFT_ENCAPSULATION_SYMBOLS(name)

#define DECLARE_SWIFT_RETAINED_SECTION(name) \
DECLARE_EMPTY_RETAINED_METADATA_SECTION(name) \
DECLARE_SWIFT_ENCAPSULATION_SYMBOLS(name)

extern "C" {
DECLARE_SWIFT_SECTION(swift5_protocols)
DECLARE_SWIFT_SECTION(swift5_protocol_conformances)
DECLARE_SWIFT_SECTION(swift5_type_metadata)
DECLARE_SWIFT_RETAINED_SECTION(swift5_protocols)
DECLARE_SWIFT_RETAINED_SECTION(swift5_protocol_conformances)
DECLARE_SWIFT_RETAINED_SECTION(swift5_type_metadata)

DECLARE_SWIFT_SECTION(swift5_typeref)
DECLARE_SWIFT_SECTION(swift5_reflstr)
DECLARE_SWIFT_SECTION(swift5_fieldmd)
DECLARE_SWIFT_SECTION(swift5_assocty)
DECLARE_SWIFT_SECTION(swift5_replace)
DECLARE_SWIFT_SECTION(swift5_replac2)
DECLARE_SWIFT_SECTION(swift5_builtin)
DECLARE_SWIFT_SECTION(swift5_capture)
DECLARE_SWIFT_SECTION(swift5_mpenum)
DECLARE_SWIFT_SECTION(swift5_accessible_functions)
DECLARE_SWIFT_RETAINED_SECTION(swift5_fieldmd)
DECLARE_SWIFT_RETAINED_SECTION(swift5_assocty)
DECLARE_SWIFT_RETAINED_SECTION(swift5_replace)
DECLARE_SWIFT_RETAINED_SECTION(swift5_replac2)
DECLARE_SWIFT_RETAINED_SECTION(swift5_builtin)
DECLARE_SWIFT_RETAINED_SECTION(swift5_capture)
DECLARE_SWIFT_RETAINED_SECTION(swift5_mpenum)
DECLARE_SWIFT_RETAINED_SECTION(swift5_accessible_functions)
DECLARE_SWIFT_SECTION(swift5_runtime_attributes)
}

Expand Down
2 changes: 0 additions & 2 deletions test/Driver/link-time-opt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// CHECK-SIMPLE-THIN-linux-gnu: clang
// CHECK-SIMPLE-THIN-linux-gnu-DAG: -flto=thin
// CHECK-SIMPLE-THIN-linux-gnu-DAG: -fuse-ld=lld
// CHECK-SIMPLE-THIN-linux-gnu-DAG: -Xlinker -z -Xlinker nostart-stop-gc
// CHECK-SIMPLE-THIN-linux-gnu-DAG: [[BITCODEFILE]]
// CHECK-SIMPLE-THIN-linux-gnu-NOT: swift-autolink-extract

Expand All @@ -36,7 +35,6 @@
// CHECK-SIMPLE-FULL-linux-gnu: clang
// CHECK-SIMPLE-FULL-linux-gnu-DAG: -flto=full
// CHECK-SIMPLE-FULL-linux-gnu-DAG: -fuse-ld=lld
// CHECK-SIMPLE-FULL-linux-gnu-DAG: -Xlinker -z -Xlinker nostart-stop-gc
// CHECK-SIMPLE-FULL-linux-gnu-DAG: [[BITCODEFILE]]
// CHECK-SIMPLE-FULL-linux-gnu-NOT: swift-autolink-extract

Expand Down