aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/tools/llvm-dwp/llvm-dwp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/tools/llvm-dwp/llvm-dwp.cpp')
-rw-r--r--contrib/llvm-project/llvm/tools/llvm-dwp/llvm-dwp.cpp56
1 files changed, 36 insertions, 20 deletions
diff --git a/contrib/llvm-project/llvm/tools/llvm-dwp/llvm-dwp.cpp b/contrib/llvm-project/llvm/tools/llvm-dwp/llvm-dwp.cpp
index d5ebe5ab0a57..d495bd3d4cab 100644
--- a/contrib/llvm-project/llvm/tools/llvm-dwp/llvm-dwp.cpp
+++ b/contrib/llvm-project/llvm/tools/llvm-dwp/llvm-dwp.cpp
@@ -377,7 +377,8 @@ writeIndex(MCStreamer &Out, MCSection *Section,
&DWARFUnitIndex::Entry::SectionContribution::Length);
}
-std::string buildDWODescription(StringRef Name, StringRef DWPName, StringRef DWOName) {
+static std::string buildDWODescription(StringRef Name, StringRef DWPName,
+ StringRef DWOName) {
std::string Text = "\'";
Text += Name;
Text += '\'';
@@ -525,8 +526,8 @@ getDWOFilenames(StringRef ExecFilename) {
std::string DWOCompDir =
dwarf::toString(Die.find(dwarf::DW_AT_comp_dir), "");
if (!DWOCompDir.empty()) {
- SmallString<16> DWOPath;
- sys::path::append(DWOPath, DWOCompDir, DWOName);
+ SmallString<16> DWOPath(std::move(DWOName));
+ sys::fs::make_absolute(DWOCompDir, DWOPath);
DWOPaths.emplace_back(DWOPath.data(), DWOPath.size());
} else {
DWOPaths.push_back(std::move(DWOName));
@@ -695,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);
@@ -705,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));
@@ -730,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, "", ""));
@@ -765,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;