From 4b17c81d5a5d3e0f514026c2b7f9b623d901cc04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eymen=20=C3=9Cnay?= Date: Fri, 8 Sep 2023 09:05:14 +0200 Subject: [jitlink/rtdydl][checker] Add TargetFlag dependent disassembler switching support Some targets such as AArch32 make use of TargetFlags to indicate ISA mode. Depending on the TargetFlag, MCDisassembler and similar target specific objects should be reinitialized with the correct Target Triple. Backends with similar needs can easily extend this implementation for their usecase. The drivers llvm-rtdyld and llvm-jitlink have their SymbolInfo's extended to take TargetFlag into account. RuntimeDyldChecker can now create necessary TargetInfo to reinitialize MCDisassembler and MCInstPrinter. The required triple is obtained from the new getTripleFromTargetFlag function by checking the TargetFlag. In addition, breaking changes for RuntimeDyld COFF Thumb tests are fixed by making the backend emit a TargetFlag. Reviewed By: lhames, sgraenitz Differential Revision: https://reviews.llvm.org/D158280 --- llvm/tools/llvm-jitlink/llvm-jitlink-coff.cpp | 11 +++++++---- llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp | 11 +++++++---- llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp | 13 ++++++++----- llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 14 ++++++-------- 4 files changed, 28 insertions(+), 21 deletions(-) (limited to 'llvm/tools/llvm-jitlink') diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-coff.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-coff.cpp index 415aee7..283e655 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink-coff.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink-coff.cpp @@ -118,7 +118,8 @@ Error registerCOFFGraphInfo(Session &S, LinkGraph &G) { if (Sym->getSize() != 0) { if (auto TS = getCOFFGOTTarget(G, Sym->getBlock())) FileInfo.GOTEntryInfos[TS->getName()] = { - Sym->getSymbolContent(), Sym->getAddress().getValue()}; + Sym->getSymbolContent(), Sym->getAddress().getValue(), + Sym->getTargetFlags()}; else return TS.takeError(); } @@ -130,7 +131,8 @@ Error registerCOFFGraphInfo(Session &S, LinkGraph &G) { if (auto TS = getCOFFStubTarget(G, Sym->getBlock())) FileInfo.StubInfos[TS->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + Sym->getAddress().getValue(), + Sym->getTargetFlags()}; else return TS.takeError(); SectionContainsContent = true; @@ -143,7 +145,8 @@ Error registerCOFFGraphInfo(Session &S, LinkGraph &G) { SectionContainsZeroFill = true; } else { S.SymbolInfos[Sym->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + Sym->getAddress().getValue(), + Sym->getTargetFlags()}; SectionContainsContent = true; } } @@ -164,7 +167,7 @@ Error registerCOFFGraphInfo(Session &S, LinkGraph &G) { else FileInfo.SectionInfos[Sec.getName()] = { ArrayRef(FirstSym->getBlock().getContent().data(), SecSize), - SecAddr.getValue()}; + SecAddr.getValue(), FirstSym->getTargetFlags()}; } return Error::success(); diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp index 5200dbc..7881660 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp @@ -120,7 +120,8 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) { if (Sym->getSize() != 0) { if (auto TS = getELFGOTTarget(G, Sym->getBlock())) FileInfo.GOTEntryInfos[TS->getName()] = { - Sym->getSymbolContent(), Sym->getAddress().getValue()}; + Sym->getSymbolContent(), Sym->getAddress().getValue(), + Sym->getTargetFlags()}; else return TS.takeError(); } @@ -132,7 +133,8 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) { if (auto TS = getELFStubTarget(G, Sym->getBlock())) FileInfo.StubInfos[TS->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + Sym->getAddress().getValue(), + Sym->getTargetFlags()}; else return TS.takeError(); SectionContainsContent = true; @@ -145,7 +147,8 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) { SectionContainsZeroFill = true; } else { S.SymbolInfos[Sym->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + Sym->getAddress().getValue(), + Sym->getTargetFlags()}; SectionContainsContent = true; } } @@ -170,7 +173,7 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) { else FileInfo.SectionInfos[Sec.getName()] = { ArrayRef(FirstSym->getBlock().getContent().data(), SecSize), - SecAddr.getValue()}; + SecAddr.getValue(), FirstSym->getTargetFlags()}; } return Error::success(); diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp index bcb2f25..7dcadd9 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp @@ -117,8 +117,9 @@ Error registerMachOGraphInfo(Session &S, LinkGraph &G) { inconvertibleErrorCode()); if (auto TS = getMachOGOTTarget(G, Sym->getBlock())) - FileInfo.GOTEntryInfos[TS->getName()] = { - Sym->getSymbolContent(), Sym->getAddress().getValue()}; + FileInfo.GOTEntryInfos[TS->getName()] = {Sym->getSymbolContent(), + Sym->getAddress().getValue(), + Sym->getTargetFlags()}; else return TS.takeError(); SectionContainsContent = true; @@ -129,7 +130,8 @@ Error registerMachOGraphInfo(Session &S, LinkGraph &G) { if (auto TS = getMachOStubTarget(G, Sym->getBlock())) FileInfo.StubInfos[TS->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + Sym->getAddress().getValue(), + Sym->getTargetFlags()}; else return TS.takeError(); SectionContainsContent = true; @@ -140,7 +142,8 @@ Error registerMachOGraphInfo(Session &S, LinkGraph &G) { SectionContainsZeroFill = true; } else { S.SymbolInfos[Sym->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + Sym->getAddress().getValue(), + Sym->getTargetFlags()}; SectionContainsContent = true; } } @@ -160,7 +163,7 @@ Error registerMachOGraphInfo(Session &S, LinkGraph &G) { else FileInfo.SectionInfos[Sec.getName()] = { ArrayRef(FirstSym->getBlock().getContent().data(), SecSize), - SecAddr.getValue()}; + SecAddr.getValue(), FirstSym->getTargetFlags()}; } return Error::success(); diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index 00dd520..a8f056e 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -1388,7 +1388,8 @@ static Error addAbsoluteSymbols(Session &S, return Err; // Register the absolute symbol with the session symbol infos. - S.SymbolInfos[Name] = {ArrayRef(), Addr}; + S.SymbolInfos[Name] = {ArrayRef(), Addr, + AbsDef.getFlags().getTargetFlags()}; } return Error::success(); @@ -1856,15 +1857,12 @@ getTargetInfo(const Triple &TT, std::move(MAI), std::move(Ctx), std::move(Disassembler), std::move(MII), std::move(MIA), std::move(InstPrinter)}; } - -static Error runChecks(Session &S) { +static Error runChecks(Session &S, Triple TT, SubtargetFeatures Features) { if (CheckFiles.empty()) return Error::success(); LLVM_DEBUG(dbgs() << "Running checks...\n"); - auto TI = getTargetInfo(S.ES.getTargetTriple(), S.Features); - auto IsSymbolValid = [&S](StringRef Symbol) { return S.isSymbolRegistered(Symbol); }; @@ -1888,7 +1886,7 @@ static Error runChecks(Session &S) { RuntimeDyldChecker Checker( IsSymbolValid, GetSymbolInfo, GetSectionInfo, GetStubInfo, GetGOTInfo, S.ES.getTargetTriple().isLittleEndian() ? support::little : support::big, - TI.Disassembler.get(), TI.InstPrinter.get(), dbgs()); + TT, Features, dbgs()); std::string CheckLineStart = "# " + CheckName + ":"; for (auto &CheckFile : CheckFiles) { @@ -2000,7 +1998,7 @@ int main(int argc, char *argv[]) { auto [TT, Features] = getFirstFileTripleAndFeatures(); ExitOnErr(sanitizeArguments(TT, argv[0])); - auto S = ExitOnErr(Session::Create(std::move(TT), std::move(Features))); + auto S = ExitOnErr(Session::Create(TT, Features)); enableStatistics(*S, !OrcRuntime.empty()); @@ -2036,7 +2034,7 @@ int main(int argc, char *argv[]) { exit(1); } - ExitOnErr(runChecks(*S)); + ExitOnErr(runChecks(*S, std::move(TT), std::move(Features))); int Result = 0; if (!NoExec) { -- cgit v1.1