@@ -646,7 +646,8 @@ MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const {
646
646
return TM.getSymbol (GV);
647
647
}
648
648
649
- MCSymbol *AsmPrinter::getSymbolPreferLocal (const GlobalValue &GV) const {
649
+ MCSymbol *AsmPrinter::getSymbolPreferLocal (const GlobalValue &GV,
650
+ bool Force) const {
650
651
// On ELF, use .Lfoo$local if GV is a non-interposable GlobalObject with an
651
652
// exact definion (intersection of GlobalValue::hasExactDefinition() and
652
653
// !isInterposable()). These linkages include: external, appending, internal,
@@ -656,8 +657,8 @@ MCSymbol *AsmPrinter::getSymbolPreferLocal(const GlobalValue &GV) const {
656
657
// assumed it.
657
658
if (TM.getTargetTriple ().isOSBinFormatELF () && GV.canBenefitFromLocalAlias ()) {
658
659
const Module &M = *GV.getParent ();
659
- if (TM.getRelocationModel () != Reloc::Static &&
660
- M.getPIELevel () == PIELevel::Default && GV.isDSOLocal ())
660
+ if (Force || ( TM.getRelocationModel () != Reloc::Static &&
661
+ M.getPIELevel () == PIELevel::Default && GV.isDSOLocal () ))
661
662
return getSymbolWithGlobalValueBase (&GV, " $local" );
662
663
}
663
664
return TM.getSymbol (&GV);
@@ -1008,22 +1009,9 @@ void AsmPrinter::emitFunctionHeader() {
1008
1009
if (MAI->useAssignmentForEHBegin ()) {
1009
1010
MCSymbol *CurPos = OutContext.createTempSymbol ();
1010
1011
OutStreamer->emitLabel (CurPos);
1011
- if (CurrentFnBeginForEH) {
1012
- OutStreamer->emitAssignment (
1013
- CurrentFnBeginForEH, MCSymbolRefExpr::create (CurPos, OutContext));
1014
- if (MAI->hasDotTypeDotSizeDirective ())
1015
- OutStreamer->emitSymbolAttribute (CurrentFnBeginForEH,
1016
- MCSA_ELF_TypeFunction);
1017
- }
1018
1012
OutStreamer->emitAssignment (CurrentFnBegin,
1019
1013
MCSymbolRefExpr::create (CurPos, OutContext));
1020
1014
} else {
1021
- if (CurrentFnBeginForEH) {
1022
- OutStreamer->emitLabel (CurrentFnBeginForEH);
1023
- if (MAI->hasDotTypeDotSizeDirective ())
1024
- OutStreamer->emitSymbolAttribute (CurrentFnBeginForEH,
1025
- MCSA_ELF_TypeFunction);
1026
- }
1027
1015
OutStreamer->emitLabel (CurrentFnBegin);
1028
1016
}
1029
1017
}
@@ -1063,6 +1051,8 @@ void AsmPrinter::emitFunctionHeader() {
1063
1051
}
1064
1052
}
1065
1053
1054
+ static bool needFuncLabelsForEH (const MachineFunction &MF);
1055
+
1066
1056
// / EmitFunctionEntryLabel - Emit the label that is the entrypoint for the
1067
1057
// / function. This can be overridden by targets as required to do custom stuff.
1068
1058
void AsmPrinter::emitFunctionEntryLabel () {
@@ -1077,7 +1067,10 @@ void AsmPrinter::emitFunctionEntryLabel() {
1077
1067
OutStreamer->emitLabel (CurrentFnSym);
1078
1068
1079
1069
if (TM.getTargetTriple ().isOSBinFormatELF ()) {
1080
- MCSymbol *Sym = getSymbolPreferLocal (MF->getFunction ());
1070
+ // For CHERI purecap exception handling, we always have to use a local
1071
+ // alias even if the function is not dso_local.
1072
+ bool ForceLocal = MAI->isCheriPurecapABI () && needFuncLabelsForEH (*MF);
1073
+ MCSymbol *Sym = getSymbolPreferLocal (MF->getFunction (), ForceLocal);
1081
1074
if (Sym != CurrentFnSym) {
1082
1075
cast<MCSymbolELF>(Sym)->setType (ELF::STT_FUNC);
1083
1076
CurrentFnBeginLocal = Sym;
@@ -1850,8 +1843,6 @@ void AsmPrinter::emitFunctionBody() {
1850
1843
MCSymbolRefExpr::create (CurrentFnEnd, OutContext),
1851
1844
MCSymbolRefExpr::create (CurrentFnSymForSize, OutContext), OutContext);
1852
1845
OutStreamer->emitELFSize (CurrentFnSym, SizeExp);
1853
- if (CurrentFnBeginForEH)
1854
- OutStreamer->emitELFSize (CurrentFnBeginForEH, SizeExp);
1855
1846
if (CurrentFnBeginLocal)
1856
1847
OutStreamer->emitELFSize (CurrentFnBeginLocal, SizeExp);
1857
1848
}
@@ -2430,7 +2421,6 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
2430
2421
2431
2422
CurrentFnSymForSize = CurrentFnSym;
2432
2423
CurrentFnBegin = nullptr ;
2433
- CurrentFnBeginForEH = nullptr ;
2434
2424
CurrentFnBeginLocal = nullptr ;
2435
2425
CurrentSectionBeginSym = nullptr ;
2436
2426
MBBSectionRanges.clear ();
@@ -2444,14 +2434,6 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
2444
2434
CurrentFnBegin = createTempSymbol (" func_begin" );
2445
2435
if (NeedsLocalForSize)
2446
2436
CurrentFnSymForSize = CurrentFnBegin;
2447
- // In the pure-capability ABI we have to create dynamic relocations for the
2448
- // landing pads. To avoid creating an (unnecessary and incorrect) dynamic
2449
- // relocation with a non-zero addend, we need to ensure that the target
2450
- // symbol is non-preemptible by creating a local alias for the function.
2451
- // See https://github.com/CTSRD-CHERI/llvm-project/issues/512.
2452
- // TODO: could probably omit this for !F.isInterposable()?
2453
- if (MAI->isCheriPurecapABI () && needFuncLabelsForEH (MF))
2454
- CurrentFnBeginForEH = getSymbolWithGlobalValueBase (&F, " $eh_alias" );
2455
2437
}
2456
2438
2457
2439
ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE ();
0 commit comments