Skip to content

Commit eab712d

Browse files
authored
Merge pull request #559 from vedantk/cherry
Cherry-pick ptrauth, lldbutil, and lockfilemanager change
2 parents 4f65b63 + 9a2b41a commit eab712d

File tree

13 files changed

+80
-12
lines changed

13 files changed

+80
-12
lines changed

lldb/packages/Python/lldbsuite/test/lldbutil.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# LLDB modules
2121
import lldb
22+
from . import lldbtest_config
2223

2324

2425
# ===================================================
@@ -758,14 +759,20 @@ def run_to_breakpoint_make_target(test, exe_name = "a.out", in_cwd = True):
758759
# Create the target
759760
target = test.dbg.CreateTarget(exe)
760761
test.assertTrue(target, "Target: %s is not valid."%(exe_name))
762+
763+
# Set environment variables for the inferior.
764+
if lldbtest_config.inferior_env:
765+
test.runCmd('settings set target.env-vars {}'.format(
766+
lldbtest_config.inferior_env))
767+
761768
return target
762769

763770
def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None,
764771
only_one_thread = True, extra_images = None):
765772

766773
# Launch the process, and do not stop at the entry point.
767774
if not launch_info:
768-
launch_info = lldb.SBLaunchInfo(None)
775+
launch_info = target.GetLaunchInfo()
769776
launch_info.SetWorkingDirectory(test.get_process_working_directory())
770777

771778
if extra_images and lldb.remote_platform:

lldb/test/API/lit.cfg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ def find_shlibpath_var():
9090
if config.llvm_libs_dir:
9191
dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir]
9292

93+
# Forward ASan-specific environment variables to tests, as a test may load an
94+
# ASan-ified dylib.
95+
for env_var in ('ASAN_OPTIONS', 'DYLD_INSERT_LIBRARIES'):
96+
if env_var in config.environment:
97+
dotest_cmd += ['--inferior-env', env_var + '=' + config.environment[env_var]]
98+
9399
if config.lldb_build_directory:
94100
dotest_cmd += ['--build-dir', config.lldb_build_directory]
95101

llvm/include/llvm/MC/MCInstrDesc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ enum Flag {
168168
Add,
169169
Trap,
170170
VariadicOpsAreDefs,
171+
Authenticated,
171172
};
172173
}
173174

@@ -408,6 +409,15 @@ class MCInstrDesc {
408409
return Flags & (1ULL << MCID::VariadicOpsAreDefs);
409410
}
410411

412+
/// Return true if this instruction authenticates a pointer (e.g. LDRAx/BRAx
413+
/// from ARMv8.3, which perform loads/branches with authentication).
414+
///
415+
/// An authenticated instruction may fail in an ABI-defined manner when
416+
/// operating on an invalid signed pointer.
417+
bool isAuthenticated() const {
418+
return Flags & (1ULL << MCID::Authenticated);
419+
}
420+
411421
//===--------------------------------------------------------------------===//
412422
// Side Effect Analysis
413423
//===--------------------------------------------------------------------===//

llvm/include/llvm/Support/LockFileManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class LockFileManager {
7777
operator LockFileState() const { return getState(); }
7878

7979
/// For a shared lock, wait until the owner releases the lock.
80-
WaitForUnlockResult waitForUnlock();
80+
/// Total timeout for the file to appear is ~1.5 minutes.
81+
/// \param MaxSeconds the maximum wait time per iteration in seconds.
82+
WaitForUnlockResult waitForUnlock(const unsigned MaxSeconds = 40);
8183

8284
/// Remove the lock file. This may delete a different lock file than
8385
/// the one previously read if there is a race.

llvm/include/llvm/Target/Target.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ class Instruction : InstructionEncoding {
530530
bit hasCtrlDep = 0; // Does this instruction r/w ctrl-flow chains?
531531
bit isNotDuplicable = 0; // Is it unsafe to duplicate this instruction?
532532
bit isConvergent = 0; // Is this instruction convergent?
533+
bit isAuthenticated = 0; // Does this instruction authenticate a pointer?
533534
bit isAsCheapAsAMove = 0; // As cheap (or cheaper) than a move instruction.
534535
bit hasExtraSrcRegAllocReq = 0; // Sources have special regalloc requirement?
535536
bit hasExtraDefRegAllocReq = 0; // Defs have special regalloc requirement?

llvm/lib/Support/LockFileManager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ LockFileManager::~LockFileManager() {
290290
sys::DontRemoveFileOnSignal(UniqueLockFileName);
291291
}
292292

293-
LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() {
293+
LockFileManager::WaitForUnlockResult
294+
LockFileManager::waitForUnlock(const unsigned MaxSeconds) {
294295
if (getState() != LFS_Shared)
295296
return Res_Success;
296297

@@ -301,9 +302,6 @@ LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() {
301302
Interval.tv_sec = 0;
302303
Interval.tv_nsec = 1000000;
303304
#endif
304-
// Don't wait more than 40s per iteration. Total timeout for the file
305-
// to appear is ~1.5 minutes.
306-
const unsigned MaxSeconds = 40;
307305
do {
308306
// Sleep for the designated interval, to allow the owning process time to
309307
// finish up and remove the lock file.

llvm/lib/Target/AArch64/AArch64InstrFormats.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ class RCPCLoad<bits<2> sz, string asm, RegisterClass RC>
14901490
class AuthBase<bits<1> M, dag oops, dag iops, string asm, string operands,
14911491
list<dag> pattern>
14921492
: I<oops, iops, asm, operands, "", pattern>, Sched<[]> {
1493+
let isAuthenticated = 1;
14931494
let Inst{31-25} = 0b1101011;
14941495
let Inst{20-11} = 0b1111100001;
14951496
let Inst{10} = M;
@@ -1529,6 +1530,7 @@ class BaseAuthLoad<bit M, bit W, dag oops, dag iops, string asm,
15291530
bits<10> offset;
15301531
bits<5> Rn;
15311532
bits<5> Rt;
1533+
let isAuthenticated = 1;
15321534
let Inst{31-24} = 0b11111000;
15331535
let Inst{23} = M;
15341536
let Inst{22} = offset{9};

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -841,20 +841,26 @@ def AArch64authtcret: SDNode<"AArch64ISD::AUTH_TC_RETURN",
841841
let Uses = [LR], Defs = [LR] in {
842842
def PACIAZ : SystemNoOperands<0b000, "paciaz">;
843843
def PACIBZ : SystemNoOperands<0b010, "pacibz">;
844-
def AUTIAZ : SystemNoOperands<0b100, "autiaz">;
845-
def AUTIBZ : SystemNoOperands<0b110, "autibz">;
844+
let isAuthenticated = 1 in {
845+
def AUTIAZ : SystemNoOperands<0b100, "autiaz">;
846+
def AUTIBZ : SystemNoOperands<0b110, "autibz">;
847+
}
846848
}
847849
let Uses = [LR, SP], Defs = [LR] in {
848850
def PACIASP : SystemNoOperands<0b001, "paciasp">;
849851
def PACIBSP : SystemNoOperands<0b011, "pacibsp">;
850-
def AUTIASP : SystemNoOperands<0b101, "autiasp">;
851-
def AUTIBSP : SystemNoOperands<0b111, "autibsp">;
852+
let isAuthenticated = 1 in {
853+
def AUTIASP : SystemNoOperands<0b101, "autiasp">;
854+
def AUTIBSP : SystemNoOperands<0b111, "autibsp">;
855+
}
852856
}
853857
let Uses = [X16, X17], Defs = [X17], CRm = 0b0001 in {
854858
def PACIA1716 : SystemNoOperands<0b000, "pacia1716">;
855859
def PACIB1716 : SystemNoOperands<0b010, "pacib1716">;
856-
def AUTIA1716 : SystemNoOperands<0b100, "autia1716">;
857-
def AUTIB1716 : SystemNoOperands<0b110, "autib1716">;
860+
let isAuthenticated = 1 in {
861+
def AUTIA1716 : SystemNoOperands<0b100, "autia1716">;
862+
def AUTIB1716 : SystemNoOperands<0b110, "autib1716">;
863+
}
858864
}
859865

860866
let Uses = [LR], Defs = [LR], CRm = 0b0000 in {

llvm/unittests/Target/AArch64/InstSizes.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,38 @@ void runChecks(
7878

7979
} // anonymous namespace
8080

81+
TEST(InstSizes, Authenticated) {
82+
std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
83+
ASSERT_TRUE(TM);
84+
std::unique_ptr<AArch64InstrInfo> II = createInstrInfo(TM.get());
85+
86+
auto isAuthInst = [](AArch64InstrInfo &II, MachineFunction &MF) {
87+
auto I = MF.begin()->begin();
88+
EXPECT_EQ(4u, II.getInstSizeInBytes(*I));
89+
EXPECT_TRUE(I->getDesc().isAuthenticated());
90+
};
91+
92+
runChecks(TM.get(), II.get(), "",
93+
" \n"
94+
" BLRAA $x10, $x9\n",
95+
isAuthInst);
96+
97+
runChecks(TM.get(), II.get(), "",
98+
" \n"
99+
" RETAB implicit $lr, implicit $sp, implicit killed $x0\n",
100+
isAuthInst);
101+
102+
runChecks(TM.get(), II.get(), "",
103+
" \n"
104+
" frame-destroy AUTIASP implicit-def $lr, implicit killed $lr, implicit $sp\n",
105+
isAuthInst);
106+
107+
runChecks(TM.get(), II.get(), "",
108+
" \n"
109+
" frame-destroy AUTIBSP implicit-def $lr, implicit killed $lr, implicit $sp\n",
110+
isAuthInst);
111+
}
112+
81113
TEST(InstSizes, STACKMAP) {
82114
std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
83115
ASSERT_TRUE(TM);

llvm/utils/TableGen/CodeGenInstruction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ CodeGenInstruction::CodeGenInstruction(Record *R)
396396
hasNoSchedulingInfo = R->getValueAsBit("hasNoSchedulingInfo");
397397
FastISelShouldIgnore = R->getValueAsBit("FastISelShouldIgnore");
398398
variadicOpsAreDefs = R->getValueAsBit("variadicOpsAreDefs");
399+
isAuthenticated = R->getValueAsBit("isAuthenticated");
399400

400401
bool Unset;
401402
mayLoad = R->getValueAsBitOrUnset("mayLoad", Unset);

llvm/utils/TableGen/CodeGenInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ template <typename T> class ArrayRef;
278278
bool hasChain : 1;
279279
bool hasChain_Inferred : 1;
280280
bool variadicOpsAreDefs : 1;
281+
bool isAuthenticated : 1;
281282

282283
std::string DeprecatedReason;
283284
bool HasComplexDeprecationPredicate;

llvm/utils/TableGen/InstrDocsEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) {
138138
FLAG(isConvergent)
139139
FLAG(hasNoSchedulingInfo)
140140
FLAG(variadicOpsAreDefs)
141+
FLAG(isAuthenticated)
141142
if (!FlagStrings.empty()) {
142143
OS << "Flags: ";
143144
bool IsFirst = true;

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
703703
if (Inst.isInsertSubreg) OS << "|(1ULL<<MCID::InsertSubreg)";
704704
if (Inst.isConvergent) OS << "|(1ULL<<MCID::Convergent)";
705705
if (Inst.variadicOpsAreDefs) OS << "|(1ULL<<MCID::VariadicOpsAreDefs)";
706+
if (Inst.isAuthenticated) OS << "|(1ULL<<MCID::Authenticated)";
706707

707708
// Emit all of the target-specific flags...
708709
BitsInit *TSF = Inst.TheDef->getValueAsBitsInit("TSFlags");

0 commit comments

Comments
 (0)