aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCDwarf.cpp
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2023-11-29 16:01:37 -0800
committerAdrian Prantl <aprantl@apple.com>2023-11-30 15:09:24 -0800
commit87e22bdd2bd6d77d782f9d64b3e3ae5bdcd5080d (patch)
tree1cd110330886181e7da47a83b76f493450d2d61e /llvm/lib/MC/MCDwarf.cpp
parent4e724c2a214cc62fd024237f0bdf903ed8fbf45b (diff)
downloadllvm-87e22bdd2bd6d77d782f9d64b3e3ae5bdcd5080d.zip
llvm-87e22bdd2bd6d77d782f9d64b3e3ae5bdcd5080d.tar.gz
llvm-87e22bdd2bd6d77d782f9d64b3e3ae5bdcd5080d.tar.bz2
Allow for mixing source/no-source DIFiles in one CU
The DWARF proposal that the DW_LNCT_LLVM_source extension is based on (https://dwarfstd.org/issues/180201.1.html) allows to mix source and non-source files in the same CU by storing an empty string as a sentinel value. This patch implements this feature. Review in https://github.com/llvm/llvm-project/pull/73877
Diffstat (limited to 'llvm/lib/MC/MCDwarf.cpp')
-rw-r--r--llvm/lib/MC/MCDwarf.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 7925fba..f94fc48 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -386,7 +386,7 @@ void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const {
}
static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
- bool EmitMD5, bool HasSource,
+ bool EmitMD5, bool HasAnySource,
std::optional<MCDwarfLineStr> &LineStr) {
assert(!DwarfFile.Name.empty());
if (LineStr)
@@ -401,7 +401,7 @@ static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
MCOS->emitBinaryData(
StringRef(reinterpret_cast<const char *>(Cksum.data()), Cksum.size()));
}
- if (HasSource) {
+ if (HasAnySource) {
if (LineStr)
LineStr->emitRef(MCOS, DwarfFile.Source.value_or(StringRef()));
else {
@@ -452,7 +452,7 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
uint64_t Entries = 2;
if (HasAllMD5)
Entries += 1;
- if (HasSource)
+ if (HasAnySource)
Entries += 1;
MCOS->emitInt8(Entries);
MCOS->emitULEB128IntValue(dwarf::DW_LNCT_path);
@@ -464,7 +464,7 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
MCOS->emitULEB128IntValue(dwarf::DW_LNCT_MD5);
MCOS->emitULEB128IntValue(dwarf::DW_FORM_data16);
}
- if (HasSource) {
+ if (HasAnySource) {
MCOS->emitULEB128IntValue(dwarf::DW_LNCT_LLVM_source);
MCOS->emitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
: dwarf::DW_FORM_string);
@@ -479,9 +479,9 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
assert((!RootFile.Name.empty() || MCDwarfFiles.size() >= 1) &&
"No root file and no .file directives");
emitOneV5FileEntry(MCOS, RootFile.Name.empty() ? MCDwarfFiles[1] : RootFile,
- HasAllMD5, HasSource, LineStr);
+ HasAllMD5, HasAnySource, LineStr);
for (unsigned i = 1; i < MCDwarfFiles.size(); ++i)
- emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasAllMD5, HasSource, LineStr);
+ emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasAllMD5, HasAnySource, LineStr);
}
std::pair<MCSymbol *, MCSymbol *>
@@ -598,7 +598,7 @@ MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, StringRef &FileName,
// If any files have embedded source, they all must.
if (MCDwarfFiles.empty()) {
trackMD5Usage(Checksum.has_value());
- HasSource = (Source != std::nullopt);
+ HasAnySource |= Source.has_value();
}
if (DwarfVersion >= 5 && isRootFile(RootFile, Directory, FileName, Checksum))
return 0;
@@ -625,11 +625,6 @@ MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, StringRef &FileName,
return make_error<StringError>("file number already allocated",
inconvertibleErrorCode());
- // If any files have embedded source, they all must.
- if (HasSource != (Source != std::nullopt))
- return make_error<StringError>("inconsistent use of embedded source",
- inconvertibleErrorCode());
-
if (Directory.empty()) {
// Separate the directory part from the basename of the FileName.
StringRef tFileName = sys::path::filename(FileName);
@@ -662,8 +657,8 @@ MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, StringRef &FileName,
File.Checksum = Checksum;
trackMD5Usage(Checksum.has_value());
File.Source = Source;
- if (Source)
- HasSource = true;
+ if (Source.has_value())
+ HasAnySource = true;
// return the allocated FileNumber.
return FileNumber;