diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2019-06-22 00:06:51 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2019-06-22 00:06:51 +0000 |
commit | 4608868d2f4c074269fdb766c2d79c9513ed4ae9 (patch) | |
tree | 432485824cef5917d42b40aefeb44dfebf51a4fc /llvm/lib/Target/AArch64/AArch64FrameLowering.cpp | |
parent | 21f0f7170670d8d8d04376ee6309022f8228b796 (diff) | |
download | bcm5719-llvm-4608868d2f4c074269fdb766c2d79c9513ed4ae9.tar.gz bcm5719-llvm-4608868d2f4c074269fdb766c2d79c9513ed4ae9.zip |
AArch64: Prefer FP-relative debug locations in HWASANified functions.
To help produce better diagnostics for stack use-after-return, we'd like
to be able to determine the addresses of each HWASANified function's local
variables given a small amount of information recorded on entry to the
function. Currently we require all HWASANified functions to use frame pointers
and record (PC, FP) on function entry. This works better than recording SP
because FP cannot change during the function, unlike SP which can change
e.g. due to dynamic alloca.
However, most variables currently end up using SP-relative locations in their
debug info. This prevents us from recomputing the address of most variables
because the distance between SP and FP isn't recorded in the debug info. To
address this, make the AArch64 backend prefer FP-relative debug locations
when producing debug info for HWASANified functions.
Differential Revision: https://reviews.llvm.org/D63300
llvm-svn: 364117
Diffstat (limited to 'llvm/lib/Target/AArch64/AArch64FrameLowering.cpp')
-rw-r--r-- | llvm/lib/Target/AArch64/AArch64FrameLowering.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp index 98cfbf813bd..5dbee91bee5 100644 --- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp @@ -1497,7 +1497,11 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF, int AArch64FrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const { - return resolveFrameIndexReference(MF, FI, FrameReg); + return resolveFrameIndexReference( + MF, FI, FrameReg, + /*PreferFP=*/ + MF.getFunction().hasFnAttribute(Attribute::SanitizeHWAddress), + /*ForSimm=*/false); } int AArch64FrameLowering::getNonLocalFrameIndexReference( @@ -1530,7 +1534,8 @@ int AArch64FrameLowering::getSEHFrameIndexOffset(const MachineFunction &MF, int AArch64FrameLowering::resolveFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg, - bool PreferFP) const { + bool PreferFP, + bool ForSimm) const { const auto &MFI = MF.getFrameInfo(); const auto *RegInfo = static_cast<const AArch64RegisterInfo *>( MF.getSubtarget().getRegisterInfo()); @@ -1561,11 +1566,11 @@ int AArch64FrameLowering::resolveFrameIndexReference(const MachineFunction &MF, assert(hasFP(MF) && "Re-aligned stack must have frame pointer"); UseFP = true; } else if (hasFP(MF) && !RegInfo->needsStackRealignment(MF)) { - // If the FPOffset is negative, we have to keep in mind that the - // available offset range for negative offsets is smaller than for - // positive ones. If an offset is - // available via the FP and the SP, use whichever is closest. - bool FPOffsetFits = FPOffset >= -256; + // If the FPOffset is negative and we're producing a signed immediate, we + // have to keep in mind that the available offset range for negative + // offsets is smaller than for positive ones. If an offset is available + // via the FP and the SP, use whichever is closest. + bool FPOffsetFits = !ForSimm || FPOffset >= -256; PreferFP |= Offset > -FPOffset; if (MFI.hasVarSizedObjects()) { |