aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCDwarf.cpp
diff options
context:
space:
mode:
authorPaul Robinson <paul.robinson@sony.com>2018-03-06 22:37:45 +0000
committerPaul Robinson <paul.robinson@sony.com>2018-03-06 22:37:45 +0000
commit4428e90efa31df7b288b170330dc7ec941ea72f8 (patch)
treef22c88ca283c4e5c7e19c2d1c52637d340b4612a /llvm/lib/MC/MCDwarf.cpp
parentca38c762e46c22566f09e41712c2ea3ea2e1240a (diff)
downloadllvm-4428e90efa31df7b288b170330dc7ec941ea72f8.zip
llvm-4428e90efa31df7b288b170330dc7ec941ea72f8.tar.gz
llvm-4428e90efa31df7b288b170330dc7ec941ea72f8.tar.bz2
Reapply "[DWARFv5] Emit file 0 to the line table."
Fixes the bug found by asan. Also XFAIL the new test for Darwin, which is stuck on DWARF v2, and fix up other tests so they stop failing on Windows. llvm-svn: 326839
Diffstat (limited to 'llvm/lib/MC/MCDwarf.cpp')
-rw-r--r--llvm/lib/MC/MCDwarf.cpp61
1 files changed, 34 insertions, 27 deletions
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 685b46a..ee675ac 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -346,6 +346,34 @@ void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const {
MCOS->EmitIntValue(0, 1); // Terminate the file list.
}
+static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
+ bool HasMD5, bool HasSource,
+ Optional<MCDwarfLineStr> &LineStr) {
+ assert(!DwarfFile.Name.empty());
+ if (LineStr)
+ LineStr->emitRef(MCOS, DwarfFile.Name);
+ else {
+ MCOS->EmitBytes(DwarfFile.Name); // FileName and...
+ MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
+ }
+ MCOS->EmitULEB128IntValue(DwarfFile.DirIndex); // Directory number.
+ if (HasMD5) {
+ MD5::MD5Result *Cksum = DwarfFile.Checksum;
+ MCOS->EmitBinaryData(
+ StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()),
+ Cksum->Bytes.size()));
+ }
+ if (HasSource) {
+ if (LineStr)
+ LineStr->emitRef(MCOS, DwarfFile.Source.getValueOr(StringRef()));
+ else {
+ MCOS->EmitBytes(
+ DwarfFile.Source.getValueOr(StringRef())); // Source and...
+ MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
+ }
+ }
+}
+
void MCDwarfLineTableHeader::emitV5FileDirTables(
MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const {
// The directory format, which is just a list of the directory paths. In a
@@ -394,33 +422,12 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
: dwarf::DW_FORM_string);
}
- // Then the list of file names. These start at 1.
- MCOS->EmitULEB128IntValue(MCDwarfFiles.size() - 1);
- for (unsigned i = 1; i < MCDwarfFiles.size(); ++i) {
- assert(!MCDwarfFiles[i].Name.empty());
- if (LineStr)
- LineStr->emitRef(MCOS, MCDwarfFiles[i].Name);
- else {
- MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName and...
- MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
- }
- MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex); // Directory number.
- if (HasMD5) {
- MD5::MD5Result *Cksum = MCDwarfFiles[i].Checksum;
- MCOS->EmitBinaryData(
- StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()),
- Cksum->Bytes.size()));
- }
- if (HasSource) {
- if (LineStr)
- LineStr->emitRef(MCOS, MCDwarfFiles[i].Source.getValueOr(StringRef()));
- else {
- MCOS->EmitBytes(
- MCDwarfFiles[i].Source.getValueOr(StringRef())); // Source and...
- MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
- }
- }
- }
+ // Then the counted list of files. The root file is file #0, then emit the
+ // files as provide by .file directives.
+ MCOS->EmitULEB128IntValue(MCDwarfFiles.size());
+ emitOneV5FileEntry(MCOS, RootFile, HasMD5, HasSource, LineStr);
+ for (unsigned i = 1; i < MCDwarfFiles.size(); ++i)
+ emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasMD5, HasSource, LineStr);
}
std::pair<MCSymbol *, MCSymbol *>