summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-03-13 10:53:30 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-03-13 10:53:30 +0000
commit1256125fb73169b8a8a940bce05dd04622955edc (patch)
tree2ed9d5bb6fcdfda7c18bf2154a6f8c383befeaea /llvm/lib/CodeGen/AsmPrinter
parent90a021fb02b7ee1413c56f45a2a60ee066b305f3 (diff)
downloadbcm5719-llvm-1256125fb73169b8a8a940bce05dd04622955edc.tar.gz
bcm5719-llvm-1256125fb73169b8a8a940bce05dd04622955edc.zip
[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. llvm-svn: 263378
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 622d169750d..233bce41b19 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -397,10 +397,11 @@ void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI,
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::emitDebugInfoForFunction(const Function *GV,
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(const LocalVariable &Var) {
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
OpenPOWER on IntegriCloud