[llvm-branch-commits] [llvm] da48994 - [llvm-dwp] Automatically set the target triple
Philip Pfaffe via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jan 25 03:04:21 PST 2021
Author: Philip Pfaffe
Date: 2021-01-25T11:58:54+01:00
New Revision: da489946a9d8385826defa91441c7e8e6e1ee8e4
URL: https://github.com/llvm/llvm-project/commit/da489946a9d8385826defa91441c7e8e6e1ee8e4
DIFF: https://github.com/llvm/llvm-project/commit/da489946a9d8385826defa91441c7e8e6e1ee8e4.diff
LOG: [llvm-dwp] Automatically set the target triple
The llvm-dwp tool hard-codes the target triple to x86. Instead, deduce the
target triple from the object files being read.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D93749
Added:
llvm/test/tools/llvm-dwp/WebAssembly/lit.local.cfg
llvm/test/tools/llvm-dwp/WebAssembly/simple_dwo.s
Modified:
llvm/tools/llvm-dwp/llvm-dwp.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-dwp/WebAssembly/lit.local.cfg b/llvm/test/tools/llvm-dwp/WebAssembly/lit.local.cfg
new file mode 100644
index 000000000000..5ea762c84049
--- /dev/null
+++ b/llvm/test/tools/llvm-dwp/WebAssembly/lit.local.cfg
@@ -0,0 +1,4 @@
+if not 'WebAssembly' in config.root.targets:
+ config.unsupported = True
+
+config.suffixes = ['.s']
diff --git a/llvm/test/tools/llvm-dwp/WebAssembly/simple_dwo.s b/llvm/test/tools/llvm-dwp/WebAssembly/simple_dwo.s
new file mode 100644
index 000000000000..f3e88c97d581
--- /dev/null
+++ b/llvm/test/tools/llvm-dwp/WebAssembly/simple_dwo.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc %s -filetype obj -triple wasm32-unknown-unknown -o %t.o \
+# RUN: -split-dwarf-file=%t.dwo -dwarf-version=5
+# RUN: llvm-dwp %t.dwo -o %t.dwp
+# RUN: llvm-dwarfdump -v %t.dwp | FileCheck %s
+
+# This test checks whether llvm-dwp is able to emit object files of the same
+# triple as its inputs.
+
+# CHECK: file format WASM
+
+# Empty file, we just care about the file type.
diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp
index 7bd7575dab41..9aed3526b0aa 100644
--- a/llvm/tools/llvm-dwp/llvm-dwp.cpp
+++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp
@@ -696,6 +696,14 @@ static int error(const Twine &Error, const Twine &Context) {
return 1;
}
+static Expected<Triple> readTargetTriple(StringRef FileName) {
+ auto ErrOrObj = object::ObjectFile::createObjectFile(FileName);
+ if (!ErrOrObj)
+ return ErrOrObj.takeError();
+
+ return ErrOrObj->getBinary()->makeTriple();
+}
+
int main(int argc, char **argv) {
InitLLVM X(argc, argv);
@@ -706,17 +714,36 @@ int main(int argc, char **argv) {
llvm::InitializeAllTargets();
llvm::InitializeAllAsmPrinters();
+ std::vector<std::string> DWOFilenames = InputFiles;
+ for (const auto &ExecFilename : ExecFilenames) {
+ auto DWOs = getDWOFilenames(ExecFilename);
+ if (!DWOs) {
+ logAllUnhandledErrors(DWOs.takeError(), WithColor::error());
+ return 1;
+ }
+ DWOFilenames.insert(DWOFilenames.end(),
+ std::make_move_iterator(DWOs->begin()),
+ std::make_move_iterator(DWOs->end()));
+ }
+
+ if (DWOFilenames.empty())
+ return 0;
+
std::string ErrorStr;
StringRef Context = "dwarf streamer init";
- Triple TheTriple("x86_64-linux-gnu");
+ auto ErrOrTriple = readTargetTriple(DWOFilenames.front());
+ if (!ErrOrTriple) {
+ logAllUnhandledErrors(ErrOrTriple.takeError(), WithColor::error());
+ return 1;
+ }
// Get the target.
const Target *TheTarget =
- TargetRegistry::lookupTarget("", TheTriple, ErrorStr);
+ TargetRegistry::lookupTarget("", *ErrOrTriple, ErrorStr);
if (!TheTarget)
return error(ErrorStr, Context);
- std::string TripleName = TheTriple.getTriple();
+ std::string TripleName = ErrOrTriple->getTriple();
// Create all the MC Objects.
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
@@ -731,7 +758,7 @@ int main(int argc, char **argv) {
MCObjectFileInfo MOFI;
MCContext MC(MAI.get(), MRI.get(), &MOFI);
- MOFI.InitMCObjectFileInfo(TheTriple, /*PIC*/ false, MC);
+ MOFI.InitMCObjectFileInfo(*ErrOrTriple, /*PIC*/ false, MC);
std::unique_ptr<MCSubtargetInfo> MSTI(
TheTarget->createMCSubtargetInfo(TripleName, "", ""));
@@ -766,25 +793,13 @@ int main(int argc, char **argv) {
}
std::unique_ptr<MCStreamer> MS(TheTarget->createMCObjectStreamer(
- TheTriple, MC, std::unique_ptr<MCAsmBackend>(MAB),
+ *ErrOrTriple, MC, std::unique_ptr<MCAsmBackend>(MAB),
MAB->createObjectWriter(*OS), std::unique_ptr<MCCodeEmitter>(MCE), *MSTI,
MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible,
/*DWARFMustBeAtTheEnd*/ false));
if (!MS)
return error("no object streamer for target " + TripleName, Context);
- std::vector<std::string> DWOFilenames = InputFiles;
- for (const auto &ExecFilename : ExecFilenames) {
- auto DWOs = getDWOFilenames(ExecFilename);
- if (!DWOs) {
- logAllUnhandledErrors(DWOs.takeError(), WithColor::error());
- return 1;
- }
- DWOFilenames.insert(DWOFilenames.end(),
- std::make_move_iterator(DWOs->begin()),
- std::make_move_iterator(DWOs->end()));
- }
-
if (auto Err = write(*MS, DWOFilenames)) {
logAllUnhandledErrors(std::move(Err), WithColor::error());
return 1;
More information about the llvm-branch-commits
mailing list