Skip to content

Cherry-pick ptrauth, lldbutil, and lockfilemanager change #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lldb/packages/Python/lldbsuite/test/lldbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# LLDB modules
import lldb
from . import lldbtest_config


# ===================================================
Expand Down Expand Up @@ -758,14 +759,20 @@ def run_to_breakpoint_make_target(test, exe_name = "a.out", in_cwd = True):
# Create the target
target = test.dbg.CreateTarget(exe)
test.assertTrue(target, "Target: %s is not valid."%(exe_name))

# Set environment variables for the inferior.
if lldbtest_config.inferior_env:
test.runCmd('settings set target.env-vars {}'.format(
lldbtest_config.inferior_env))

return target

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

# Launch the process, and do not stop at the entry point.
if not launch_info:
launch_info = lldb.SBLaunchInfo(None)
launch_info = target.GetLaunchInfo()
launch_info.SetWorkingDirectory(test.get_process_working_directory())

if extra_images and lldb.remote_platform:
Expand Down
6 changes: 6 additions & 0 deletions lldb/test/API/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ def find_shlibpath_var():
if config.llvm_libs_dir:
dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir]

# Forward ASan-specific environment variables to tests, as a test may load an
# ASan-ified dylib.
for env_var in ('ASAN_OPTIONS', 'DYLD_INSERT_LIBRARIES'):
if env_var in config.environment:
dotest_cmd += ['--inferior-env', env_var + '=' + config.environment[env_var]]

if config.lldb_build_directory:
dotest_cmd += ['--build-dir', config.lldb_build_directory]

Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/MC/MCInstrDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ enum Flag {
Add,
Trap,
VariadicOpsAreDefs,
Authenticated,
};
}

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

/// Return true if this instruction authenticates a pointer (e.g. LDRAx/BRAx
/// from ARMv8.3, which perform loads/branches with authentication).
///
/// An authenticated instruction may fail in an ABI-defined manner when
/// operating on an invalid signed pointer.
bool isAuthenticated() const {
return Flags & (1ULL << MCID::Authenticated);
}

//===--------------------------------------------------------------------===//
// Side Effect Analysis
//===--------------------------------------------------------------------===//
Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/Support/LockFileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class LockFileManager {
operator LockFileState() const { return getState(); }

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

/// Remove the lock file. This may delete a different lock file than
/// the one previously read if there is a race.
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Target/Target.td
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ class Instruction : InstructionEncoding {
bit hasCtrlDep = 0; // Does this instruction r/w ctrl-flow chains?
bit isNotDuplicable = 0; // Is it unsafe to duplicate this instruction?
bit isConvergent = 0; // Is this instruction convergent?
bit isAuthenticated = 0; // Does this instruction authenticate a pointer?
bit isAsCheapAsAMove = 0; // As cheap (or cheaper) than a move instruction.
bit hasExtraSrcRegAllocReq = 0; // Sources have special regalloc requirement?
bit hasExtraDefRegAllocReq = 0; // Defs have special regalloc requirement?
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Support/LockFileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ LockFileManager::~LockFileManager() {
sys::DontRemoveFileOnSignal(UniqueLockFileName);
}

LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() {
LockFileManager::WaitForUnlockResult
LockFileManager::waitForUnlock(const unsigned MaxSeconds) {
if (getState() != LFS_Shared)
return Res_Success;

Expand All @@ -301,9 +302,6 @@ LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() {
Interval.tv_sec = 0;
Interval.tv_nsec = 1000000;
#endif
// Don't wait more than 40s per iteration. Total timeout for the file
// to appear is ~1.5 minutes.
const unsigned MaxSeconds = 40;
do {
// Sleep for the designated interval, to allow the owning process time to
// finish up and remove the lock file.
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/AArch64/AArch64InstrFormats.td
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,7 @@ class RCPCLoad<bits<2> sz, string asm, RegisterClass RC>
class AuthBase<bits<1> M, dag oops, dag iops, string asm, string operands,
list<dag> pattern>
: I<oops, iops, asm, operands, "", pattern>, Sched<[]> {
let isAuthenticated = 1;
let Inst{31-25} = 0b1101011;
let Inst{20-11} = 0b1111100001;
let Inst{10} = M;
Expand Down Expand Up @@ -1529,6 +1530,7 @@ class BaseAuthLoad<bit M, bit W, dag oops, dag iops, string asm,
bits<10> offset;
bits<5> Rn;
bits<5> Rt;
let isAuthenticated = 1;
let Inst{31-24} = 0b11111000;
let Inst{23} = M;
let Inst{22} = offset{9};
Expand Down
18 changes: 12 additions & 6 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -841,20 +841,26 @@ def AArch64authtcret: SDNode<"AArch64ISD::AUTH_TC_RETURN",
let Uses = [LR], Defs = [LR] in {
def PACIAZ : SystemNoOperands<0b000, "paciaz">;
def PACIBZ : SystemNoOperands<0b010, "pacibz">;
def AUTIAZ : SystemNoOperands<0b100, "autiaz">;
def AUTIBZ : SystemNoOperands<0b110, "autibz">;
let isAuthenticated = 1 in {
def AUTIAZ : SystemNoOperands<0b100, "autiaz">;
def AUTIBZ : SystemNoOperands<0b110, "autibz">;
}
}
let Uses = [LR, SP], Defs = [LR] in {
def PACIASP : SystemNoOperands<0b001, "paciasp">;
def PACIBSP : SystemNoOperands<0b011, "pacibsp">;
def AUTIASP : SystemNoOperands<0b101, "autiasp">;
def AUTIBSP : SystemNoOperands<0b111, "autibsp">;
let isAuthenticated = 1 in {
def AUTIASP : SystemNoOperands<0b101, "autiasp">;
def AUTIBSP : SystemNoOperands<0b111, "autibsp">;
}
}
let Uses = [X16, X17], Defs = [X17], CRm = 0b0001 in {
def PACIA1716 : SystemNoOperands<0b000, "pacia1716">;
def PACIB1716 : SystemNoOperands<0b010, "pacib1716">;
def AUTIA1716 : SystemNoOperands<0b100, "autia1716">;
def AUTIB1716 : SystemNoOperands<0b110, "autib1716">;
let isAuthenticated = 1 in {
def AUTIA1716 : SystemNoOperands<0b100, "autia1716">;
def AUTIB1716 : SystemNoOperands<0b110, "autib1716">;
}
}

let Uses = [LR], Defs = [LR], CRm = 0b0000 in {
Expand Down
32 changes: 32 additions & 0 deletions llvm/unittests/Target/AArch64/InstSizes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,38 @@ void runChecks(

} // anonymous namespace

TEST(InstSizes, Authenticated) {
std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
ASSERT_TRUE(TM);
std::unique_ptr<AArch64InstrInfo> II = createInstrInfo(TM.get());

auto isAuthInst = [](AArch64InstrInfo &II, MachineFunction &MF) {
auto I = MF.begin()->begin();
EXPECT_EQ(4u, II.getInstSizeInBytes(*I));
EXPECT_TRUE(I->getDesc().isAuthenticated());
};

runChecks(TM.get(), II.get(), "",
" \n"
" BLRAA $x10, $x9\n",
isAuthInst);

runChecks(TM.get(), II.get(), "",
" \n"
" RETAB implicit $lr, implicit $sp, implicit killed $x0\n",
isAuthInst);

runChecks(TM.get(), II.get(), "",
" \n"
" frame-destroy AUTIASP implicit-def $lr, implicit killed $lr, implicit $sp\n",
isAuthInst);

runChecks(TM.get(), II.get(), "",
" \n"
" frame-destroy AUTIBSP implicit-def $lr, implicit killed $lr, implicit $sp\n",
isAuthInst);
}

TEST(InstSizes, STACKMAP) {
std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
ASSERT_TRUE(TM);
Expand Down
1 change: 1 addition & 0 deletions llvm/utils/TableGen/CodeGenInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ CodeGenInstruction::CodeGenInstruction(Record *R)
hasNoSchedulingInfo = R->getValueAsBit("hasNoSchedulingInfo");
FastISelShouldIgnore = R->getValueAsBit("FastISelShouldIgnore");
variadicOpsAreDefs = R->getValueAsBit("variadicOpsAreDefs");
isAuthenticated = R->getValueAsBit("isAuthenticated");

bool Unset;
mayLoad = R->getValueAsBitOrUnset("mayLoad", Unset);
Expand Down
1 change: 1 addition & 0 deletions llvm/utils/TableGen/CodeGenInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ template <typename T> class ArrayRef;
bool hasChain : 1;
bool hasChain_Inferred : 1;
bool variadicOpsAreDefs : 1;
bool isAuthenticated : 1;

std::string DeprecatedReason;
bool HasComplexDeprecationPredicate;
Expand Down
1 change: 1 addition & 0 deletions llvm/utils/TableGen/InstrDocsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) {
FLAG(isConvergent)
FLAG(hasNoSchedulingInfo)
FLAG(variadicOpsAreDefs)
FLAG(isAuthenticated)
if (!FlagStrings.empty()) {
OS << "Flags: ";
bool IsFirst = true;
Expand Down
1 change: 1 addition & 0 deletions llvm/utils/TableGen/InstrInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
if (Inst.isInsertSubreg) OS << "|(1ULL<<MCID::InsertSubreg)";
if (Inst.isConvergent) OS << "|(1ULL<<MCID::Convergent)";
if (Inst.variadicOpsAreDefs) OS << "|(1ULL<<MCID::VariadicOpsAreDefs)";
if (Inst.isAuthenticated) OS << "|(1ULL<<MCID::Authenticated)";

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