[llvm] r263378 - [CodeView] Truncate display names
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 13 03:53:31 PDT 2016
Author: majnemer
Date: Sun Mar 13 05:53:30 2016
New Revision: 263378
URL: http://llvm.org/viewvc/llvm-project?rev=263378&view=rev
Log:
[CodeView] Truncate display names
Fundamentally, the length of a variable or function name is bound by the
maximum size of a record: 0xffff. However, the name doesn't live in a
vacuum; other data is associated with the name, lowering the bound
further.
We would naively attempt to emit the name, causing us to assert because
the record would no-longer fit in 16-bits. Instead, truncate the name
but preserve as much as we can.
While I have tested this locally, I've decided to not commit it due to
the test's size.
N.B. While this behavior is undesirable, it is better than MSVC's
behavior. They seem to truncate to ~4000 characters.
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=263378&r1=263377&r2=263378&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Sun Mar 13 05:53:30 2016
@@ -397,10 +397,11 @@ void CodeViewDebug::emitInlinedCallSite(
OS.EmitIntValue(SymbolRecordKind::S_INLINESITE_END, 2); // RecordKind
}
-static void emitNullTerminatedString(MCStreamer &OS, StringRef S) {
+static void emitNullTerminatedString(MCStreamer &OS, StringRef S,
+ size_t MaxSize) {
+ S = S.substr(0, MaxSize);
SmallString<32> NullTerminatedString(S);
- if (NullTerminatedString.empty() || NullTerminatedString.back() != '\0')
- NullTerminatedString.push_back('\0');
+ NullTerminatedString.push_back('\0');
OS.EmitBytes(NullTerminatedString);
}
@@ -462,7 +463,8 @@ void CodeViewDebug::emitDebugInfoForFunc
OS.EmitIntValue(0, 1);
// Emit the function display name as a null-terminated string.
OS.AddComment("Function name");
- emitNullTerminatedString(OS, FuncName);
+ // Truncate the name so we won't overflow the record length field.
+ emitNullTerminatedString(OS, FuncName, 0xffd9);
OS.EmitLabel(ProcRecordEnd);
for (const LocalVariable &Var : FI.Locals)
@@ -706,7 +708,8 @@ void CodeViewDebug::emitLocalVariable(co
OS.EmitIntValue(TypeIndex::Int32().getIndex(), 4);
OS.AddComment("Flags");
OS.EmitIntValue(Flags, 2);
- emitNullTerminatedString(OS, Var.DIVar->getName());
+ // Truncate the name so we won't overflow the record length field.
+ emitNullTerminatedString(OS, Var.DIVar->getName(), 0xfff6);
OS.EmitLabel(LocalEnd);
// Calculate the on disk prefix of the appropriate def range record. The
More information about the llvm-commits
mailing list