summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/MC/MCContext.cpp20
-rw-r--r--llvm/lib/MC/MCDwarf.cpp16
-rw-r--r--llvm/lib/MC/MCObjectStreamer.cpp3
3 files changed, 35 insertions, 4 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index e4f90f4987a..b601ab24434 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -535,6 +535,26 @@ MCSubtargetInfo &MCContext::getSubtargetCopy(const MCSubtargetInfo &STI) {
return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
}
+void MCContext::addDebugPrefixMapEntry(const std::string &From,
+ const std::string &To) {
+ DebugPrefixMap.insert(std::make_pair(From, To));
+}
+
+void MCContext::RemapDebugPath(std::string *Path) {
+ for (const auto &Entry : DebugPrefixMap)
+ if (StringRef(*Path).startswith(Entry.first)) {
+ std::string RemappedPath =
+ (Twine(Entry.second) + Path->substr(Entry.first.size())).str();
+ Path->swap(RemappedPath);
+ }
+}
+
+void MCContext::RemapCompilationDir() {
+ std::string CompDir = CompilationDir.str();
+ RemapDebugPath(&CompDir);
+ CompilationDir = CompDir;
+}
+
//===----------------------------------------------------------------------===//
// Dwarf Management
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 37e1263be65..1d33d9947be 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -250,8 +250,11 @@ void MCDwarfLineTable::Emit(MCObjectStreamer *MCOS,
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection());
// Handle the rest of the Compile Units.
- for (const auto &CUIDTablePair : LineTables)
- CUIDTablePair.second.EmitCU(MCOS, Params, LineStr);
+ for (const auto &CUIDTablePair : LineTables) {
+ auto &LineTable = context.getMCDwarfLineTable(CUIDTablePair.first);
+ LineTable.RemapDwarfDirs(MCOS->getContext());
+ LineTable.EmitCU(MCOS, Params, LineStr);
+ }
if (LineStr)
LineStr->emitSection(MCOS);
@@ -394,13 +397,13 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
if (LineStr) {
// Record path strings, emit references here.
LineStr->emitRef(MCOS, CompDir);
- for (auto &Dir : MCDwarfDirs)
+ for (const auto &Dir : MCDwarfDirs)
LineStr->emitRef(MCOS, Dir);
} else {
// The list of directory paths. Compilation directory comes first.
MCOS->EmitBytes(CompDir);
MCOS->EmitBytes(StringRef("\0", 1));
- for (auto &Dir : MCDwarfDirs) {
+ for (const auto &Dir : MCDwarfDirs) {
MCOS->EmitBytes(Dir); // The DirectoryName, and...
MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
}
@@ -631,6 +634,11 @@ MCDwarfLineTableHeader::tryGetFile(StringRef &Directory,
return FileNumber;
}
+void MCDwarfLineTable::RemapDwarfDirs(MCContext &Context) {
+ for (auto &Dir : Header.MCDwarfDirs)
+ Context.RemapDebugPath(&Dir);
+}
+
/// Utility function to emit the encoding to a streamer.
void MCDwarfLineAddr::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
int64_t LineDelta, uint64_t AddrDelta) {
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 432f4c242a8..8122af459b7 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -661,6 +661,9 @@ void MCObjectStreamer::EmitFileDirective(StringRef Filename) {
}
void MCObjectStreamer::FinishImpl() {
+ // Remap the compilation directory before emitting.
+ getContext().RemapCompilationDir();
+
// If we are generating dwarf for assembly source files dump out the sections.
if (getContext().getGenDwarfForAssembly())
MCGenDwarfInfo::Emit(this);
OpenPOWER on IntegriCloud