[llvm] r346815 - Make dsymutil more robust when parsing load commands.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 13 15:31:25 PST 2018
Author: adrian
Date: Tue Nov 13 15:31:25 2018
New Revision: 346815
URL: http://llvm.org/viewvc/llvm-project?rev=346815&view=rev
Log:
Make dsymutil more robust when parsing load commands.
rdar://problem/45883463
Modified:
llvm/trunk/test/tools/dsymutil/Inputs/lc_build_version.x86_64
llvm/trunk/test/tools/dsymutil/X86/lc_build_version.test
llvm/trunk/tools/dsymutil/MachOUtils.cpp
Modified: llvm/trunk/test/tools/dsymutil/Inputs/lc_build_version.x86_64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/lc_build_version.x86_64?rev=346815&r1=346814&r2=346815&view=diff
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/lc_build_version.x86_64 (original) and llvm/trunk/test/tools/dsymutil/Inputs/lc_build_version.x86_64 Tue Nov 13 15:31:25 2018 differ
Modified: llvm/trunk/test/tools/dsymutil/X86/lc_build_version.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/lc_build_version.test?rev=346815&r1=346814&r2=346815&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/lc_build_version.test (original)
+++ llvm/trunk/test/tools/dsymutil/X86/lc_build_version.test Tue Nov 13 15:31:25 2018
@@ -8,4 +8,4 @@ CHECK-NEXT: platform: 1
CHECK-NEXT: minos: 658944
CHECK-NEXT: sdk: 658944
CHECK-NEXT: ntools: 0
-CHECK-NEXT: - cmd
+CHECK-NEXT: - cmd: LC_BUILD_VERSION
Modified: llvm/trunk/tools/dsymutil/MachOUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachOUtils.cpp?rev=346815&r1=346814&r2=346815&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachOUtils.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachOUtils.cpp Tue Nov 13 15:31:25 2018
@@ -374,23 +374,28 @@ bool generateDsymCompanion(const DebugMa
// Get LC_UUID and LC_BUILD_VERSION.
MachO::uuid_command UUIDCmd;
- MachO::build_version_command BuildVersionCmd;
+ SmallVector<MachO::build_version_command, 2> BuildVersionCmd;
memset(&UUIDCmd, 0, sizeof(UUIDCmd));
- memset(&BuildVersionCmd, 0, sizeof(BuildVersionCmd));
for (auto &LCI : InputBinary.load_commands()) {
switch (LCI.C.cmd) {
case MachO::LC_UUID:
+ if (UUIDCmd.cmd)
+ return error("Binary contains more than one UUID");
UUIDCmd = InputBinary.getUuidCommand(LCI);
++NumLoadCommands;
- LoadCommandSize += sizeof(MachO::uuid_command);
+ LoadCommandSize += sizeof(UUIDCmd);
break;
- case MachO::LC_BUILD_VERSION:
- BuildVersionCmd = InputBinary.getBuildVersionLoadCommand(LCI);
+ case MachO::LC_BUILD_VERSION: {
+ MachO::build_version_command Cmd;
+ memset(&Cmd, 0, sizeof(Cmd));
+ Cmd = InputBinary.getBuildVersionLoadCommand(LCI);
++NumLoadCommands;
- LoadCommandSize += sizeof(MachO::build_version_command);
+ LoadCommandSize += sizeof(Cmd);
// LLDB doesn't care about the build tools for now.
- BuildVersionCmd.ntools = 0;
+ Cmd.ntools = 0;
+ BuildVersionCmd.push_back(Cmd);
break;
+ }
default:
break;
}
@@ -463,13 +468,13 @@ bool generateDsymCompanion(const DebugMa
OutFile.write(reinterpret_cast<const char *>(UUIDCmd.uuid), 16);
assert(OutFile.tell() == HeaderSize + sizeof(UUIDCmd));
}
- if (BuildVersionCmd.cmd != 0) {
- Writer.W.write<uint32_t>(BuildVersionCmd.cmd);
- Writer.W.write<uint32_t>(sizeof(BuildVersionCmd));
- Writer.W.write<uint32_t>(BuildVersionCmd.platform);
- Writer.W.write<uint32_t>(BuildVersionCmd.minos);
- Writer.W.write<uint32_t>(BuildVersionCmd.sdk);
- Writer.W.write<uint32_t>(BuildVersionCmd.ntools);
+ for (auto Cmd : BuildVersionCmd) {
+ Writer.W.write<uint32_t>(Cmd.cmd);
+ Writer.W.write<uint32_t>(sizeof(Cmd));
+ Writer.W.write<uint32_t>(Cmd.platform);
+ Writer.W.write<uint32_t>(Cmd.minos);
+ Writer.W.write<uint32_t>(Cmd.sdk);
+ Writer.W.write<uint32_t>(Cmd.ntools);
}
assert(SymtabCmd.cmd && "No symbol table.");
More information about the llvm-commits
mailing list