@@ -291,39 +291,41 @@ void llvm::emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV,
291
291
}
292
292
293
293
std::optional<std::string> llvm::getArm64ECMangledFunctionName (StringRef Name) {
294
- bool IsCppFn = Name[0 ] == ' ?' ;
295
- if (IsCppFn && Name.contains (" $$h" ))
296
- return std::nullopt;
297
- if (!IsCppFn && Name[0 ] == ' #' )
298
- return std::nullopt;
294
+ if (Name[0 ] != ' ?' ) {
295
+ // For non-C++ symbols, prefix the name with "#" unless it's already
296
+ // mangled.
297
+ if (Name[0 ] == ' #' )
298
+ return std::nullopt;
299
+ return std::optional<std::string>((" #" + Name).str ());
300
+ }
299
301
300
- StringRef Prefix = " $$h" ;
302
+ // Insert the ARM64EC "$$h" tag after the mangled function name.
303
+ if (Name.contains (" $$h" ))
304
+ return std::nullopt;
301
305
size_t InsertIdx = 0 ;
302
- if (IsCppFn) {
303
- InsertIdx = Name.find (" @@" );
304
- size_t ThreeAtSignsIdx = Name.find (" @@@" );
305
- if (InsertIdx != std::string::npos && InsertIdx != ThreeAtSignsIdx) {
306
- InsertIdx += 2 ;
307
- } else {
308
- InsertIdx = Name.find (" @" );
309
- if (InsertIdx != std::string::npos)
310
- InsertIdx++;
311
- }
306
+ InsertIdx = Name.find (" @@" );
307
+ size_t ThreeAtSignsIdx = Name.find (" @@@" );
308
+ if (InsertIdx != std::string::npos && InsertIdx != ThreeAtSignsIdx) {
309
+ InsertIdx += 2 ;
312
310
} else {
313
- Prefix = " #" ;
311
+ InsertIdx = Name.find (" @" );
312
+ if (InsertIdx != std::string::npos)
313
+ InsertIdx++;
314
314
}
315
315
316
316
return std::optional<std::string>(
317
- (Name.substr (0 , InsertIdx) + Prefix + Name.substr (InsertIdx)).str ());
317
+ (Name.substr (0 , InsertIdx) + " $$h " + Name.substr (InsertIdx)).str ());
318
318
}
319
319
320
320
std::optional<std::string>
321
321
llvm::getArm64ECDemangledFunctionName (StringRef Name) {
322
+ // For non-C++ names, drop the "#" prefix.
322
323
if (Name[0 ] == ' #' )
323
324
return std::optional<std::string>(Name.substr (1 ));
324
325
if (Name[0 ] != ' ?' )
325
326
return std::nullopt;
326
327
328
+ // Drop the ARM64EC "$$h" tag.
327
329
std::pair<StringRef, StringRef> Pair = Name.split (" $$h" );
328
330
if (Pair.second .empty ())
329
331
return std::nullopt;
0 commit comments