Skip to content

Commit b317763

Browse files
authored
Merge pull request swiftlang#34983 from compnerd/decoration
IRGen: correct decoration handling for x86
2 parents af8cf15 + 5bd27db commit b317763

10 files changed

+31
-23
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,11 +2972,19 @@ static llvm::GlobalVariable *createGOTEquivalent(IRGenModule &IGM,
29722972

29732973
if (IGM.Triple.getObjectFormat() == llvm::Triple::COFF) {
29742974
if (cast<llvm::GlobalValue>(global)->hasDLLImportStorageClass()) {
2975+
// Add the user label prefix *prior* to the introduction of the linker
2976+
// synthetic marker `__imp_`.
2977+
// Failure to do so will re-decorate the generated symbol and miss the
2978+
// user label prefix, generating e.g. `___imp_$sBoW` instead of
2979+
// `__imp__$sBoW`.
2980+
if (auto prefix = IGM.DataLayout.getGlobalPrefix())
2981+
globalName = (llvm::Twine(prefix) + globalName).str();
2982+
// Indicate to LLVM that the symbol should not be re-decorated.
29752983
llvm::GlobalVariable *GV =
29762984
new llvm::GlobalVariable(IGM.Module, global->getType(),
29772985
/*Constant=*/true,
2978-
llvm::GlobalValue::ExternalLinkage,
2979-
nullptr, llvm::Twine("__imp_") + globalName);
2986+
llvm::GlobalValue::ExternalLinkage, nullptr,
2987+
"\01__imp_" + globalName);
29802988
GV->setExternallyInitialized(true);
29812989
return GV;
29822990
}

test/IRGen/class_resilience.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
// -- field offset vector offset:
5959
// CHECK-SAME: i32 0,
6060
// -- superclass:
61-
// CHECK-SAME: @"{{got.|__imp_}}$s15resilient_class22ResilientOutsideParentCMn"
61+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s15resilient_class22ResilientOutsideParentCMn"
6262
// -- singleton metadata initialization cache:
6363
// CHECK-SAME: @"$s16class_resilience14ResilientChildCMl"
6464
// -- resilient pattern:
@@ -69,17 +69,17 @@
6969
// CHECK-SAME: i32 2,
7070
// CHECK-SAME: %swift.method_override_descriptor {
7171
// -- base class:
72-
// CHECK-SAME: @"{{got.|__imp_}}$s15resilient_class22ResilientOutsideParentCMn"
72+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s15resilient_class22ResilientOutsideParentCMn"
7373
// -- base method:
74-
// CHECK-SAME: @"{{got.|__imp_}}$s15resilient_class22ResilientOutsideParentC8getValueSiyFTq"
74+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s15resilient_class22ResilientOutsideParentC8getValueSiyFTq"
7575
// -- implementation:
7676
// CHECK-SAME: @"$s16class_resilience14ResilientChildC8getValueSiyF"
7777
// CHECK-SAME: }
7878
// CHECK-SAME: %swift.method_override_descriptor {
7979
// -- base class:
80-
// CHECK-SAME: @"{{got.|__imp_}}$s15resilient_class22ResilientOutsideParentCMn"
80+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s15resilient_class22ResilientOutsideParentCMn"
8181
// -- base method:
82-
// CHECK-SAME: @"{{got.|__imp_}}$s15resilient_class22ResilientOutsideParentCACycfCTq"
82+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s15resilient_class22ResilientOutsideParentCACycfCTq"
8383
// -- implementation:
8484
// CHECK-SAME: @"$s16class_resilience14ResilientChildCACycfC"
8585
// CHECK-SAME: }

test/IRGen/dllimport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public func g() {
4646
// CHECK-NO-OPT-DAG: declare dllimport void @swift_deallocClassInstance(%swift.refcounted*, i32, i32)
4747

4848
// CHECK-OPT-DAG: declare dllimport %swift.refcounted* @swift_retain(%swift.refcounted* returned) local_unnamed_addr
49-
// CHECK-OPT-DAG: @"__imp_$s9dllexport1pMp" = external externally_initialized constant %swift.protocol*
49+
// CHECK-OPT-DAG: @"\01__imp_{{_?}}$s9dllexport1pMp" = external externally_initialized constant %swift.protocol*
5050
// CHECK-OPT-DAG: declare dllimport swiftcc i8* @"$s9dllexport2ciAA1cCvau"()
5151
// CHECK-OPT-DAG: declare dllimport void @swift_deallocClassInstance(%swift.refcounted*, i32, i32)
5252
// CHECK-OPT-DAG: declare dllimport swiftcc %swift.refcounted* @"$s9dllexport1cCfd"(%T9dllexport1cC* swiftself)

test/IRGen/keypath_witness_overrides.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import protocol_overrides
66

77
// CHECK: @keypath = private global
8-
// CHECK-SAME: %swift.method_descriptor** @"{{got.|__imp_}}$s18protocol_overrides14OriginalGetterPy7ElementQz5IndexQzcigTq"
8+
// CHECK-SAME: %swift.method_descriptor** @"{{got.|\\01__imp__?}}$s18protocol_overrides14OriginalGetterPy7ElementQz5IndexQzcigTq"
99
public func getWritableKeyPath<OS: OverridesSetter>(_ c: OS, index: OS.Index) -> AnyKeyPath
1010
where OS.Index: Hashable {
1111
let keypath = \OS.[index]

test/IRGen/keypaths.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ sil_vtable C2 {}
171171
// CHECK-SAME: <i32 0x8000_000c>,
172172
// -- computed, get-only, identified by (indirected) function pointer, no args
173173
// CHECK-SAME: <i32 0x0200_0002>,
174-
// CHECK-SAME: @{{got.|__imp_}}k_id
174+
// CHECK-SAME: @{{got.|"\\01__imp__?}}k_id
175175
// CHECK-SAME: void (%TSi*, %T8keypaths1SV*)* {{.*}}@k_get{{.*}}
176176

177177
// -- %l: computed

test/IRGen/keypaths_external.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ sil @s_equals : $@convention(thin) <A: Hashable, B: Hashable> (UnsafeRawPointer,
4141
sil @s_hash : $@convention(thin) <A: Hashable, B: Hashable> (UnsafeRawPointer) -> Int
4242

4343
// -- %t
44-
// CHECK: [[KP_T:@keypath(\..*)?]] = private global <{ {{.*}} }> <{ {{.*}} i32 1, {{.*}} @"{{got.|__imp_}}$s23keypaths_external_other1GV1xxvpMV"
44+
// CHECK: [[KP_T:@keypath(\..*)?]] = private global <{ {{.*}} }> <{ {{.*}} i32 1, {{.*}} @"{{got.|\\01__imp__?}}$s23keypaths_external_other1GV1xxvpMV"
4545
// CHECK-SAME: @"symbolic x"
4646
// -- computed get-only property, identified by indirect pointer
4747
// CHECK-SAME: <i32 0x0208_0002>
4848

4949
// -- %u
50-
// CHECK: [[KP_U:@keypath(\..*)?]] = private global <{ {{.*}} }> <{ {{.*}} i32 3, {{.*}} @"{{got.|__imp_}}$s23keypaths_external_other1GVyxqd__cSHRd__luipMV"
50+
// CHECK: [[KP_U:@keypath(\..*)?]] = private global <{ {{.*}} }> <{ {{.*}} i32 3, {{.*}} @"{{got.|\\01__imp__?}}$s23keypaths_external_other1GVyxqd__cSHRd__luipMV"
5151
// CHECK-SAME: @"symbolic q_"
5252
// CHECK-SAME: @"symbolic x"
5353
// CHECK-SAME: @"get_witness_table

test/IRGen/property_descriptor.sil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sil_property #ExternalGeneric.rw <T: Comparable> (
5454
// CHECK: @"$s19property_descriptor15ExternalGenericV10computedROxvpMV" =
5555
// -- 0x0108_0000 - computed, readonly, has arguments, identified by indirect
5656
// CHECK-SAME: <{ <i32 0x0208_0002>,
57-
// CHECK-SAME: @{{got.|__imp_}}id_computed
57+
// CHECK-SAME: @{{got.|"\\01__imp__?}}id_computed
5858
// CHECK-SAME: [[GET_COMPUTEDRO:@keypath_get[.0-9]*]]{{(\.ptrauth)?}}
5959
// CHECK-SAME: [[GET_ARG_LAYOUT_COMPUTEDRO:@keypath_get_arg_layout[.0-9]*]]{{(\.ptrauth)?}}
6060
// -- default witness table
@@ -68,7 +68,7 @@ sil_property #ExternalGeneric.computedRO <T: Comparable> (
6868
// CHECK: @"$s19property_descriptor15ExternalGenericV10computedRWxvpMV" =
6969
// -- 0x01c8_0000 - computed, settable, mutating, has arguments, indirect id
7070
// CHECK-SAME: <{ <i32 0x02c8_0002>,
71-
// CHECK-SAME: @{{got.|__imp_}}id_computed
71+
// CHECK-SAME: @{{got.|"\\01__imp__?}}id_computed
7272
// CHECK-SAME: [[GET_COMPUTEDRW:@keypath_get[.0-9]*]]{{(\.ptrauth)?}}
7373
// CHECK-SAME: [[SET_COMPUTEDRW:@keypath_set[.0-9]*]]{{(\.ptrauth)?}}
7474
// CHECK-SAME: [[GET_ARG_LAYOUT_COMPUTEDRW:@keypath_get_arg_layout[.0-9]*]]{{(\.ptrauth)?}}
@@ -83,7 +83,7 @@ sil_property #ExternalGeneric.computedRW <T: Comparable> (
8383
// CHECK: @"$s19property_descriptor15ExternalGenericVyxqd__cSHRd__luipMV" =
8484
// -- 0x01c8_0000 - computed, settable, mutating, has arguments, indirect id
8585
// CHECK-SAME: <{ <i32 0x02c8_0002>,
86-
// CHECK-SAME: @{{got.|__imp_}}id_computed
86+
// CHECK-SAME: @{{got.|"\\01__imp__?}}id_computed
8787
// CHECK-SAME: [[GET_SUBSCRIPT:@keypath_get[.0-9]*]]{{(\.ptrauth)?}}
8888
// CHECK-SAME: [[SET_SUBSCRIPT:@keypath_set[.0-9]*]]{{(\.ptrauth)?}}
8989
// CHECK-SAME: [[GET_ARG_LAYOUT_SUBSCRIPT:@keypath_get_arg_layout[.0-9]*]]{{(\.ptrauth)?}}

test/IRGen/protocol_conformance_records.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public struct NativeGenericType<T>: Runcible {
5757
// -- protocol descriptor
5858
// CHECK-SAME: [[RUNCIBLE]]
5959
// -- type metadata
60-
// CHECK-SAME: @"{{got.|__imp_}}$sSiMn"
60+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$sSiMn"
6161
// -- witness table
6262
// CHECK-SAME: @"$sSi28protocol_conformance_records8RuncibleAAWP"
6363
// -- reserved
@@ -73,7 +73,7 @@ extension Int: Runcible {
7373
// -- protocol descriptor
7474
// CHECK-SAME: [[RUNCIBLE]]
7575
// -- nominal type descriptor
76-
// CHECK-SAME: @"{{got.|__imp_}}$s16resilient_struct4SizeVMn"
76+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s16resilient_struct4SizeVMn"
7777
// -- witness table
7878
// CHECK-SAME: @"$s16resilient_struct4SizeV28protocol_conformance_records8RuncibleADWP"
7979
// -- reserved
@@ -132,9 +132,9 @@ extension NativeGenericType : Spoon where T: Spoon {
132132
// Retroactive conformance
133133
// CHECK-LABEL: @"$sSi18resilient_protocol22OtherResilientProtocol0B20_conformance_recordsMc" ={{ dllexport | protected | }}constant
134134
// -- protocol descriptor
135-
// CHECK-SAME: @"{{got.|__imp_}}$s18resilient_protocol22OtherResilientProtocolMp"
135+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s18resilient_protocol22OtherResilientProtocolMp"
136136
// -- nominal type descriptor
137-
// CHECK-SAME: @"{{got.|__imp_}}$sSiMn"
137+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$sSiMn"
138138
// -- witness table pattern
139139
// CHECK-SAME: i32 0,
140140
// -- flags

test/IRGen/protocol_resilience.sil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ protocol InternalProtocol {
116116
// CHECK-SAME: i32 3,
117117

118118
// -- type metadata for associated type
119-
// CHECK-SAME: @"{{got.|__imp_}}$s1T18resilient_protocol24ProtocolWithRequirementsPTl"
119+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s1T18resilient_protocol24ProtocolWithRequirementsPTl"
120120
// CHECK-SAME: @"symbolic Si"
121121

122-
// CHECK-SAME: @"{{got.|__imp_}}$s18resilient_protocol24ProtocolWithRequirementsP5firstyyFTq"
122+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s18resilient_protocol24ProtocolWithRequirementsP5firstyyFTq"
123123
// CHECK-SAME: @firstWitness
124124

125-
// CHECK-SAME: @"{{got.|__imp_}}$s18resilient_protocol24ProtocolWithRequirementsP6secondyyFTq"
125+
// CHECK-SAME: @"{{got.|\\01__imp__?}}$s18resilient_protocol24ProtocolWithRequirementsP6secondyyFTq"
126126
// CHECK-SAME: @secondWitness
127127

128128
// -- number of witness table entries

test/IRGen/protocol_resilience_descriptors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import resilient_protocol
4646
// Resilient witness tables
4747
// ----------------------------------------------------------------------------
4848
// CHECK-USAGE-LABEL: $s31protocol_resilience_descriptors34ConformsToProtocolWithRequirementsVyxG010resilient_A00fgH0AAMc" =
49-
// CHECK-USAGE-SAME: {{got.|__imp_}}$s1T18resilient_protocol24ProtocolWithRequirementsPTl
49+
// CHECK-USAGE-SAME: {{got.|\\01__imp__?}}$s1T18resilient_protocol24ProtocolWithRequirementsPTl
5050
// CHECK-USAGE-SAME: @"symbolic x"
5151
public struct ConformsToProtocolWithRequirements<Element>
5252
: ProtocolWithRequirements {

0 commit comments

Comments
 (0)