aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCCodeView.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-12-21 21:13:02 -0800
committerFangrui Song <i@maskray.me>2024-12-21 21:13:02 -0800
commit6c42d0d7df55f28084e41b482dd7c25d4e7bcd10 (patch)
treeda4651bcaa6790074ba77765340085e7750a72b1 /llvm/lib/MC/MCCodeView.cpp
parent49ecd665fcc311f7cd61e81d3f7a112cd287e292 (diff)
downloadllvm-6c42d0d7df55f28084e41b482dd7c25d4e7bcd10.zip
llvm-6c42d0d7df55f28084e41b482dd7c25d4e7bcd10.tar.gz
llvm-6c42d0d7df55f28084e41b482dd7c25d4e7bcd10.tar.bz2
[MC,CodeView] Postpone MCDataFragment creation to finish time
`StrTabFragment` created due to `.cv_stringtable` is not placed directly into a section. This requires a funky ~CodeViewContext and does not fit well with the future that moves MCFragment storage out-of-line.
Diffstat (limited to 'llvm/lib/MC/MCCodeView.cpp')
-rw-r--r--llvm/lib/MC/MCCodeView.cpp37
1 files changed, 11 insertions, 26 deletions
diff --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp
index 9e4a69e..e78f5a0 100644
--- a/llvm/lib/MC/MCCodeView.cpp
+++ b/llvm/lib/MC/MCCodeView.cpp
@@ -25,11 +25,9 @@
using namespace llvm;
using namespace llvm::codeview;
-CodeViewContext::~CodeViewContext() {
- // If someone inserted strings into the string table but never actually
- // emitted them somewhere, clean up the fragment.
- if (!InsertedStrTabFragment && StrTabFragment)
- StrTabFragment->destroy();
+void CodeViewContext::finish() {
+ if (StrTabFragment)
+ StrTabFragment->setContents(StrTab);
}
/// This is a valid number for use with .cv_loc if we've already seen a .cv_file
@@ -133,26 +131,15 @@ void CodeViewContext::recordCVLoc(MCContext &Ctx, const MCSymbol *Label,
Label, FunctionId, FileNo, Line, Column, PrologueEnd, IsStmt});
}
-MCDataFragment *CodeViewContext::getStringTableFragment() {
- if (!StrTabFragment) {
- StrTabFragment = MCCtx->allocFragment<MCDataFragment>();
- // Start a new string table out with a null byte.
- StrTabFragment->appendContents(1, '\0');
- }
- return StrTabFragment;
-}
-
std::pair<StringRef, unsigned> CodeViewContext::addToStringTable(StringRef S) {
- SmallVectorImpl<char> &Contents = getStringTableFragment()->getContents();
auto Insertion =
- StringTable.insert(std::make_pair(S, unsigned(Contents.size())));
+ StringTable.insert(std::make_pair(S, unsigned(StrTab.size())));
// Return the string from the table, since it is stable.
std::pair<StringRef, unsigned> Ret =
std::make_pair(Insertion.first->first(), Insertion.first->second);
if (Insertion.second) {
// The string map key is always null terminated.
- StrTabFragment->appendContents(
- ArrayRef(Ret.first.begin(), Ret.first.end() + 1));
+ StrTab.append(Ret.first.begin(), Ret.first.end() + 1);
}
return Ret;
}
@@ -178,9 +165,9 @@ void CodeViewContext::emitStringTable(MCObjectStreamer &OS) {
// Put the string table data fragment here, if we haven't already put it
// somewhere else. If somebody wants two string tables in their .s file, one
// will just be empty.
- if (!InsertedStrTabFragment) {
- OS.insert(getStringTableFragment());
- InsertedStrTabFragment = true;
+ if (!StrTabFragment) {
+ StrTabFragment = Ctx.allocFragment<MCDataFragment>();
+ OS.insert(StrTabFragment);
}
OS.emitValueToAlignment(Align(4), 0);
@@ -375,11 +362,9 @@ void CodeViewContext::emitLineTableForFunction(MCObjectStreamer &OS,
return Loc.getFileNum() != CurFileNum;
});
unsigned EntryCount = FileSegEnd - I;
- OS.AddComment(
- "Segment for file '" +
- Twine(getStringTableFragment()
- ->getContents()[Files[CurFileNum - 1].StringTableOffset]) +
- "' begins");
+ OS.AddComment("Segment for file '" +
+ Twine(StrTab[Files[CurFileNum - 1].StringTableOffset]) +
+ "' begins");
OS.emitCVFileChecksumOffsetDirective(CurFileNum);
OS.emitInt32(EntryCount);
uint32_t SegmentSize = 12;