aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/MCContext.cpp39
-rw-r--r--llvm/lib/MC/MCDwarf.cpp14
-rw-r--r--llvm/lib/MC/MCParser/ELFAsmParser.cpp3
3 files changed, 33 insertions, 23 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 322ed8e23eb6..062246f9c7ee 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -855,30 +855,35 @@ void MCContext::addDebugPrefixMapEntry(const std::string &From,
DebugPrefixMap.insert(std::make_pair(From, To));
}
+void MCContext::remapDebugPath(SmallVectorImpl<char> &Path) {
+ for (const auto &V : DebugPrefixMap)
+ if (llvm::sys::path::replace_path_prefix(Path, V.first, V.second))
+ break;
+}
+
void MCContext::RemapDebugPaths() {
const auto &DebugPrefixMap = this->DebugPrefixMap;
if (DebugPrefixMap.empty())
return;
- const auto RemapDebugPath = [&DebugPrefixMap](std::string &Path) {
- SmallString<256> P(Path);
- for (const auto &Entry : DebugPrefixMap) {
- if (llvm::sys::path::replace_path_prefix(P, Entry.first, Entry.second)) {
- Path = P.str().str();
- break;
- }
+ // Remap compilation directory.
+ remapDebugPath(CompilationDir);
+
+ // Remap MCDwarfDirs and RootFile.Name in all compilation units.
+ SmallString<256> P;
+ for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
+ for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
+ P = Dir;
+ remapDebugPath(P);
+ Dir = std::string(P);
}
- };
- // Remap compilation directory.
- std::string CompDir = std::string(CompilationDir.str());
- RemapDebugPath(CompDir);
- CompilationDir = CompDir;
-
- // Remap MCDwarfDirs in all compilation units.
- for (auto &CUIDTablePair : MCDwarfLineTablesCUMap)
- for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs())
- RemapDebugPath(Dir);
+ // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
+ // DW_AT_decl_file for DWARF v5 generated for assembly source.
+ P = CUIDTablePair.second.getRootFile().Name;
+ remapDebugPath(P);
+ CUIDTablePair.second.getRootFile().Name = std::string(P);
+ }
}
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 4cbb9981fde2..cc1a662da87e 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -266,7 +266,7 @@ void MCDwarfLineTable::emit(MCStreamer *MCOS, MCDwarfLineTableParams Params) {
// In a v5 non-split line table, put the strings in a separate section.
Optional<MCDwarfLineStr> LineStr;
if (context.getDwarfVersion() >= 5)
- LineStr = MCDwarfLineStr(context);
+ LineStr.emplace(context);
// Switch to the section where the table will be emitted into.
MCOS->switchSection(context.getObjectFileInfo()->getDwarfLineSection());
@@ -416,9 +416,15 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
: dwarf::DW_FORM_string);
MCOS->emitULEB128IntValue(MCDwarfDirs.size() + 1);
// Try not to emit an empty compilation directory.
- const StringRef CompDir = CompilationDir.empty()
- ? MCOS->getContext().getCompilationDir()
- : StringRef(CompilationDir);
+ SmallString<256> Dir;
+ StringRef CompDir = MCOS->getContext().getCompilationDir();
+ if (!CompilationDir.empty()) {
+ Dir = CompilationDir;
+ MCOS->getContext().remapDebugPath(Dir);
+ CompDir = Dir.str();
+ if (LineStr)
+ CompDir = LineStr->getSaver().save(CompDir);
+ }
if (LineStr) {
// Record path strings, emit references here.
LineStr->emitRef(MCOS, CompDir);
diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index 563d3487ef50..38977b7641a0 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -566,8 +566,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
}
if (getLexer().isNot(AsmToken::String)) {
- if (!getContext().getAsmInfo()->usesSunStyleELFSectionSwitchSyntax()
- || getLexer().isNot(AsmToken::Hash))
+ if (getLexer().isNot(AsmToken::Hash))
return TokError("expected string in directive");
extraFlags = parseSunStyleSectionFlags();
} else {