Skip to content

Commit 837e331

Browse files
committed
IRGen: handle ASAN better with importing on ELF
ELF's lack of linker directives is worked around by a custom section (`.swift1_autolink_entries`). This is metadata that is not intended to be emitted into the linked binary. A previous change introduced the use of a module (global) assembly gadget to discard the section. However, this interacts poorly with ASAN which would instrument the section, resulting in a strong reference. This reference would persist to a discarded symbol. lld would object to this. Blacklist the symbol to ensure that ASAN + autolinking can co-exist.
1 parent 90d94c8 commit 837e331

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "llvm/Support/MD5.h"
5151

5252
#include "ConformanceDescription.h"
53+
#include "GenDecl.h"
5354
#include "GenEnum.h"
5455
#include "GenIntegerLiteral.h"
5556
#include "GenType.h"
@@ -1190,6 +1191,7 @@ void IRGenModule::emitAutolinkInfo() {
11901191
var->setSection(".swift1_autolink_entries");
11911192
var->setAlignment(getPointerAlignment().getValue());
11921193

1194+
disableAddressSanitizer(*this, var);
11931195
addUsedGlobal(var);
11941196
}
11951197

test/IRGen/ELF-remove-autolink-section.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,15 @@
1313
print("Hi from Swift!")
1414

1515
// ELF: module asm ".section .swift1_autolink_entries,\220x80000000\22"
16+
17+
// Find the metadata entry for the blacklisting of the metadata symbol
18+
// Ensure that it is in the ASAN metadata
19+
20+
// ELF-DAG: !llvm.asan.globals = !{
21+
// ELF-SAME: [[MD:![0-9]+]]
22+
// ELF-SAME: }
23+
24+
// ELF-DAG: [[MD]] = !{[37 x i8]* @_swift1_autolink_entries, null, null, i1 false, i1 true}
25+
1626
// SECTION: .swift1_autolink_entries
1727
// NOSECTION-NOT: .swift1_autolink_entries

0 commit comments

Comments
 (0)