diff options
author | Adrian Prantl <aprantl@apple.com> | 2018-11-08 16:54:59 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2018-11-08 16:54:59 +0000 |
commit | 778fba3188328f06f0e10aad31b5437d39c50f16 (patch) | |
tree | a662b68ad4ca90534617db5ec92f4550dd4b0105 | |
parent | 5fd3e754786c394b735555119432e305521fe9ca (diff) | |
download | bcm5719-llvm-778fba3188328f06f0e10aad31b5437d39c50f16.tar.gz bcm5719-llvm-778fba3188328f06f0e10aad31b5437d39c50f16.zip |
[dsymutil] Copy the LC_BUILD_VERSION load command into the companion binary.
LC_BUILD_VERSION contains platform information that is useful for LLDB
to match up dSYM bundles with binaries. This patch copies the load
command over into the dSYM.
rdar://problem/44145175
rdar://problem/45883463
Differential Revision: https://reviews.llvm.org/D54233
llvm-svn: 346412
-rw-r--r-- | llvm/test/tools/dsymutil/Inputs/lc_build_version.x86_64 | bin | 0 -> 4248 bytes | |||
-rw-r--r-- | llvm/test/tools/dsymutil/X86/lc_build_version.test | 11 | ||||
-rw-r--r-- | llvm/tools/dsymutil/MachOUtils.cpp | 43 |
3 files changed, 40 insertions, 14 deletions
diff --git a/llvm/test/tools/dsymutil/Inputs/lc_build_version.x86_64 b/llvm/test/tools/dsymutil/Inputs/lc_build_version.x86_64 Binary files differnew file mode 100644 index 00000000000..f5e737d7c9a --- /dev/null +++ b/llvm/test/tools/dsymutil/Inputs/lc_build_version.x86_64 diff --git a/llvm/test/tools/dsymutil/X86/lc_build_version.test b/llvm/test/tools/dsymutil/X86/lc_build_version.test new file mode 100644 index 00000000000..5d4ab59e9ef --- /dev/null +++ b/llvm/test/tools/dsymutil/X86/lc_build_version.test @@ -0,0 +1,11 @@ +# RUN: dsymutil -f %p/../Inputs/lc_build_version.x86_64 -o - \ +# RUN: | obj2yaml | FileCheck %s + +CHECK: LoadCommands: +CHECK: - cmd: LC_BUILD_VERSION +CHECK-NEXT: cmdsize: 24 +CHECK-NEXT: platform: 1 +CHECK-NEXT: minos: 658944 +CHECK-NEXT: sdk: 658944 +CHECK-NEXT: ntools: 0 +CHECK-NEXT: - cmd diff --git a/llvm/tools/dsymutil/MachOUtils.cpp b/llvm/tools/dsymutil/MachOUtils.cpp index d213cfea509..7b3c1d45cca 100644 --- a/llvm/tools/dsymutil/MachOUtils.cpp +++ b/llvm/tools/dsymutil/MachOUtils.cpp @@ -368,27 +368,34 @@ bool generateDsymCompanion(const DebugMap &DM, MCStreamer &MS, bool Is64Bit = Writer.is64Bit(); MachO::symtab_command SymtabCmd = InputBinary.getSymtabLoadCommand(); - // Get UUID. + // Compute the number of load commands we will need. + unsigned LoadCommandSize = 0; + unsigned NumLoadCommands = 0; + + // Get LC_UUID and LC_BUILD_VERSION. MachO::uuid_command UUIDCmd; + MachO::build_version_command BuildVersionCmd; memset(&UUIDCmd, 0, sizeof(UUIDCmd)); - UUIDCmd.cmd = MachO::LC_UUID; - UUIDCmd.cmdsize = sizeof(MachO::uuid_command); + memset(&BuildVersionCmd, 0, sizeof(BuildVersionCmd)); for (auto &LCI : InputBinary.load_commands()) { - if (LCI.C.cmd == MachO::LC_UUID) { + switch (LCI.C.cmd) { + case MachO::LC_UUID: UUIDCmd = InputBinary.getUuidCommand(LCI); + ++NumLoadCommands; + LoadCommandSize += sizeof(MachO::uuid_command); + break; + case MachO::LC_BUILD_VERSION: + BuildVersionCmd = InputBinary.getBuildVersionLoadCommand(LCI); + ++NumLoadCommands; + LoadCommandSize += sizeof(MachO::build_version_command); + // LLDB doesn't care about the build tools for now. + BuildVersionCmd.ntools = 0; + break; + default: break; } } - // Compute the number of load commands we will need. - unsigned LoadCommandSize = 0; - unsigned NumLoadCommands = 0; - // We will copy the UUID if there is one. - if (UUIDCmd.cmd != 0) { - ++NumLoadCommands; - LoadCommandSize += sizeof(MachO::uuid_command); - } - // If we have a valid symtab to copy, do it. bool ShouldEmitSymtab = isExecutable(InputBinary) && hasLinkEditSegment(InputBinary); @@ -452,10 +459,18 @@ bool generateDsymCompanion(const DebugMap &DM, MCStreamer &MS, assert(OutFile.tell() == HeaderSize); if (UUIDCmd.cmd != 0) { Writer.W.write<uint32_t>(UUIDCmd.cmd); - Writer.W.write<uint32_t>(UUIDCmd.cmdsize); + Writer.W.write<uint32_t>(sizeof(UUIDCmd)); 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); + } assert(SymtabCmd.cmd && "No symbol table."); uint64_t StringStart = SymtabStart + NumSyms * NListSize; |