diff options
author | Daniil Kovalev <dkovalev@accesssoftek.com> | 2024-12-16 10:24:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-16 10:24:09 +0300 |
commit | f65a21a4ecc2e712c700c59842b6b9a1d2a9a060 (patch) | |
tree | 5980eaf26e610c0e8b669761522236dd82816675 /llvm/lib/CodeGen | |
parent | 54dac27c57d05d3f5c33bd4ec878bcb0a9c7cb71 (diff) | |
download | llvm-f65a21a4ecc2e712c700c59842b6b9a1d2a9a060.zip llvm-f65a21a4ecc2e712c700c59842b6b9a1d2a9a060.tar.gz llvm-f65a21a4ecc2e712c700c59842b6b9a1d2a9a060.tar.bz2 |
[PAC][ELF][AArch64] Support signed personality function pointer (#119361)
Re-apply #113148 after revert in #119331
If function pointer signing is enabled, sign personality function
pointer stored in `.DW.ref.__gxx_personality_v0` section with IA key,
0x7EAD = `ptrauth_string_discriminator("personality")` constant
discriminator and address diversity enabled.
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineModuleInfoImpls.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 11 |
3 files changed, 20 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp index 087ee02..4fac4bb 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp @@ -50,7 +50,8 @@ void DwarfCFIException::endModule() { // Emit indirect reference table for all used personality functions for (const GlobalValue *Personality : Personalities) { MCSymbol *Sym = Asm->getSymbol(Personality); - TLOF.emitPersonalityValue(*Asm->OutStreamer, Asm->getDataLayout(), Sym); + TLOF.emitPersonalityValue(*Asm->OutStreamer, Asm->getDataLayout(), Sym, + Asm->MMI); } Personalities.clear(); } diff --git a/llvm/lib/CodeGen/MachineModuleInfoImpls.cpp b/llvm/lib/CodeGen/MachineModuleInfoImpls.cpp index 9563175..5c5f4b6 100644 --- a/llvm/lib/CodeGen/MachineModuleInfoImpls.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfoImpls.cpp @@ -14,6 +14,8 @@ #include "llvm/CodeGen/MachineModuleInfoImpls.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/Module.h" #include "llvm/MC/MCSymbol.h" using namespace llvm; @@ -59,3 +61,10 @@ MachineModuleInfoImpl::ExprStubListTy MachineModuleInfoImpl::getSortedExprStubs( ExprStubs.clear(); return List; } + +MachineModuleInfoELF::MachineModuleInfoELF(const MachineModuleInfo &MMI) { + const Module *M = MMI.getModule(); + const auto *Flag = mdconst::extract_or_null<ConstantInt>( + M->getModuleFlag("ptrauth-sign-personality")); + HasSignedPersonality = Flag && Flag->getZExtValue() == 1; +} diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index ce50a3c..be243c0 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -413,7 +413,8 @@ MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol( } void TargetLoweringObjectFileELF::emitPersonalityValue( - MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym) const { + MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym, + const MachineModuleInfo *MMI) const { SmallString<64> NameData("DW.ref."); NameData += Sym->getName(); MCSymbolELF *Label = @@ -431,7 +432,13 @@ void TargetLoweringObjectFileELF::emitPersonalityValue( Streamer.emitELFSize(Label, E); Streamer.emitLabel(Label); - Streamer.emitSymbolValue(Sym, Size); + emitPersonalityValueImpl(Streamer, DL, Sym, MMI); +} + +void TargetLoweringObjectFileELF::emitPersonalityValueImpl( + MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym, + const MachineModuleInfo *MMI) const { + Streamer.emitSymbolValue(Sym, DL.getPointerSize()); } const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference( |