diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-03-14 05:15:09 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-03-14 05:15:09 +0000 |
commit | b9456a5eb3d35d7de81988016dbc0c38be4a4cec (patch) | |
tree | 7c437a030cc8c276d32209168800fc2118edc944 /llvm/lib | |
parent | f91911c3ae5f2c720a4daa171636b561cb3616a0 (diff) | |
download | bcm5719-llvm-b9456a5eb3d35d7de81988016dbc0c38be4a4cec.tar.gz bcm5719-llvm-b9456a5eb3d35d7de81988016dbc0c38be4a4cec.zip |
[CodeView] Consistently handle overly large symbol names
Overly large symbol names weren't correctly handled for leaf function
records.
llvm-svn: 263408
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 233bce41b19..51a71dfdc23 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -231,6 +231,15 @@ void CodeViewDebug::endModule() { clear(); } +static void emitNullTerminatedSymbolName(MCStreamer &OS, StringRef S) { + // Microsoft's linker seems to have trouble with symbol names longer than + // 0xffd8 bytes. + S = S.substr(0, 0xffd8); + SmallString<32> NullTerminatedString(S); + NullTerminatedString.push_back('\0'); + OS.EmitBytes(NullTerminatedString); +} + void CodeViewDebug::emitTypeInformation() { // Start the .debug$T section with 0x4. OS.SwitchSection(Asm->getObjFileLowering().getCOFFDebugTypesSection()); @@ -274,7 +283,10 @@ void CodeViewDebug::emitTypeInformation() { for (auto *SP : CUNode->getSubprograms()) { StringRef DisplayName = SP->getDisplayName(); OS.AddComment("Type record length"); - OS.EmitIntValue(2 + sizeof(FuncId) + DisplayName.size() + 1, 2); + MCSymbol *FuncBegin = MMI->getContext().createTempSymbol(), + *FuncEnd = MMI->getContext().createTempSymbol(); + OS.emitAbsoluteSymbolDiff(FuncEnd, FuncBegin, 2); + OS.EmitLabel(FuncBegin); OS.AddComment("Leaf type: LF_FUNC_ID"); OS.EmitIntValue(LF_FUNC_ID, 2); @@ -283,12 +295,10 @@ void CodeViewDebug::emitTypeInformation() { OS.AddComment("Function type"); OS.EmitIntValue(VoidProcIdx.getIndex(), 4); { - SmallString<32> NullTerminatedString(DisplayName); - if (NullTerminatedString.empty() || NullTerminatedString.back() != '\0') - NullTerminatedString.push_back('\0'); OS.AddComment("Function name"); - OS.EmitBytes(NullTerminatedString); + emitNullTerminatedSymbolName(OS, DisplayName); } + OS.EmitLabel(FuncEnd); TypeIndex FuncIdIdx = getNextTypeIndex(); SubprogramToFuncId.insert(std::make_pair(SP, FuncIdIdx)); @@ -397,14 +407,6 @@ void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI, OS.EmitIntValue(SymbolRecordKind::S_INLINESITE_END, 2); // RecordKind } -static void emitNullTerminatedString(MCStreamer &OS, StringRef S, - size_t MaxSize) { - S = S.substr(0, MaxSize); - SmallString<32> NullTerminatedString(S); - NullTerminatedString.push_back('\0'); - OS.EmitBytes(NullTerminatedString); -} - void CodeViewDebug::emitDebugInfoForFunction(const Function *GV, FunctionInfo &FI) { // For each function there is a separate subsection @@ -464,7 +466,7 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV, // Emit the function display name as a null-terminated string. OS.AddComment("Function name"); // Truncate the name so we won't overflow the record length field. - emitNullTerminatedString(OS, FuncName, 0xffd9); + emitNullTerminatedSymbolName(OS, FuncName); OS.EmitLabel(ProcRecordEnd); for (const LocalVariable &Var : FI.Locals) @@ -709,7 +711,7 @@ void CodeViewDebug::emitLocalVariable(const LocalVariable &Var) { OS.AddComment("Flags"); OS.EmitIntValue(Flags, 2); // Truncate the name so we won't overflow the record length field. - emitNullTerminatedString(OS, Var.DIVar->getName(), 0xfff6); + emitNullTerminatedSymbolName(OS, Var.DIVar->getName()); OS.EmitLabel(LocalEnd); // Calculate the on disk prefix of the appropriate def range record. The |