Skip to content

Commit 76f01c0

Browse files
authored
Merge pull request #26552 from SameerAsal/remove-autolink-section
Remove .swift1_autolink_entries from the final linked binary
2 parents fc9840f + fa13be2 commit 76f01c0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,13 @@ void IRGenModule::emitAutolinkInfo() {
11661166
}
11671167
auto EntriesConstant = llvm::ConstantDataArray::getString(
11681168
LLVMContext, EntriesString, /*AddNull=*/false);
1169-
1169+
// Mark the swift1_autolink_entries section with the SHF_EXCLUDE attribute
1170+
// to get the linker to drop it in the final linked binary.
1171+
// LLVM doesn't provide an interface to specify section attributs in the IR
1172+
// so we pass the attribute with inline assembly.
1173+
if (TargetInfo.OutputObjectFormat == llvm::Triple::ELF)
1174+
Module.appendModuleInlineAsm(".section .swift1_autolink_entries,"
1175+
"\"0x80000000\"");
11701176
auto var =
11711177
new llvm::GlobalVariable(*getModule(), EntriesConstant->getType(), true,
11721178
llvm::GlobalValue::PrivateLinkage,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %swiftc_driver -emit-ir %s -o - | %FileCheck %s -check-prefix ELF
2+
3+
// Check that the swift auto link section is available in the object file.
4+
// RUN: %swiftc_driver -c %s -o %t
5+
// RUN: llvm-readelf %t -S | %FileCheck %s -check-prefix SECTION
6+
7+
// Checks that the swift auto link section is removed from the final binary.
8+
// RUN: %swiftc_driver -emit-executable %s -o %t
9+
// RUN: llvm-readelf %t -S | %FileCheck %s -check-prefix NOSECTION
10+
11+
// REQUIRES: OS=linux-gnu
12+
13+
print("Hi from Swift!")
14+
15+
// ELF: module asm ".section .swift1_autolink_entries,\220x80000000\22"
16+
// SECTION: .swift1_autolink_entries
17+
// NOSECTION-NOT: .swift1_autolink_entries

0 commit comments

Comments
 (0)