llvm.org GIT mirror llvm / 1025e9e
Add printing the LC_LINKER_OPTION load command with llvm-objdump’s -private-headers. Also corrected the name of the load command to not end in an ’S’ as well as corrected the name of the MachO::linker_option_command struct and other places that had the word option as plural which did not match the Mac OS X headers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224485 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 5 years ago
8 changed file(s) with 61 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
345345 getSegmentLoadCommand(const LoadCommandInfo &L) const;
346346 MachO::segment_command_64
347347 getSegment64LoadCommand(const LoadCommandInfo &L) const;
348 MachO::linker_options_command
349 getLinkerOptionsLoadCommand(const LoadCommandInfo &L) const;
348 MachO::linker_option_command
349 getLinkerOptionLoadCommand(const LoadCommandInfo &L) const;
350350 MachO::version_min_command
351351 getVersionMinLoadCommand(const LoadCommandInfo &L) const;
352352 MachO::dylib_command
130130 LC_SOURCE_VERSION = 0x0000002Au,
131131 LC_DYLIB_CODE_SIGN_DRS = 0x0000002Bu,
132132 LC_ENCRYPTION_INFO_64 = 0x0000002Cu,
133 LC_LINKER_OPTIONS = 0x0000002Du,
133 LC_LINKER_OPTION = 0x0000002Du,
134134 LC_LINKER_OPTIMIZATION_HINT = 0x0000002Eu
135135 };
136136
873873 uint32_t export_size;
874874 };
875875
876 struct linker_options_command {
876 struct linker_option_command {
877877 uint32_t cmd;
878878 uint32_t cmdsize;
879879 uint32_t count;
12051205 sys::swapByteOrder(C.datasize);
12061206 }
12071207
1208 inline void swapStruct(linker_options_command &C) {
1208 inline void swapStruct(linker_option_command &C) {
12091209 sys::swapByteOrder(C.cmd);
12101210 sys::swapByteOrder(C.cmdsize);
12111211 sys::swapByteOrder(C.count);
417417 static unsigned ComputeLinkerOptionsLoadCommandSize(
418418 const std::vector &Options, bool is64Bit)
419419 {
420 unsigned Size = sizeof(MachO::linker_options_command);
420 unsigned Size = sizeof(MachO::linker_option_command);
421421 for (unsigned i = 0, e = Options.size(); i != e; ++i)
422422 Size += Options[i].size() + 1;
423423 return RoundUpToAlignment(Size, is64Bit ? 8 : 4);
430430 uint64_t Start = OS.tell();
431431 (void) Start;
432432
433 Write32(MachO::LC_LINKER_OPTIONS);
433 Write32(MachO::LC_LINKER_OPTION);
434434 Write32(Size);
435435 Write32(Options.size());
436 uint64_t BytesWritten = sizeof(MachO::linker_options_command);
436 uint64_t BytesWritten = sizeof(MachO::linker_option_command);
437437 for (unsigned i = 0, e = Options.size(); i != e; ++i) {
438438 // Write each string, including the null byte.
439439 const std::string &Option = Options[i];
22532253 return getStruct(this, L.Ptr);
22542254 }
22552255
2256 MachO::linker_options_command
2257 MachOObjectFile::getLinkerOptionsLoadCommand(const LoadCommandInfo &L) const {
2258 return getStruct(this, L.Ptr);
2256 MachO::linker_option_command
2257 MachOObjectFile::getLinkerOptionLoadCommand(const LoadCommandInfo &L) const {
2258 return getStruct(this, L.Ptr);
22592259 }
22602260
22612261 MachO::version_min_command
22 // RUN: | FileCheck %s -check-prefix=EXE
33 // RUN: llvm-objdump -p %p/Inputs/dylibLoadKinds.macho-x86_64 \
44 // RUN: | FileCheck %s -check-prefix=LOAD
5 // RUN: llvm-objdump -p %p/Inputs/linkerOption.macho-x86_64 \
6 // RUN: | FileCheck %s -check-prefix=LD_OPT
57
68 CHECK: Mach header
79 CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
365367 LOAD: current version 0.0.0
366368 LOAD: compatibility version 0.0.0
367369
370 LD_OPT: Load command 4
371 LD_OPT: cmd LC_LINKER_OPTION
372 LD_OPT: cmdsize 24
373 LD_OPT: count 1
374 LD_OPT: string #1 -lc++
375 LD_OPT: Load command 5
376 LD_OPT: cmd LC_LINKER_OPTION
377 LD_OPT: cmdsize 40
378 LD_OPT: count 2
379 LD_OPT: string #1 -framework
380 LD_OPT: string #2 Foundation
36433643 outs() << " pad " << ec.pad << "\n";
36443644 }
36453645
3646 static void PrintLinkerOptionCommand(MachO::linker_option_command lo,
3647 const char *Ptr) {
3648 outs() << " cmd LC_LINKER_OPTION\n";
3649 outs() << " cmdsize " << lo.cmdsize;
3650 if (lo.cmdsize < sizeof(struct MachO::linker_option_command))
3651 outs() << " Incorrect size\n";
3652 else
3653 outs() << "\n";
3654 outs() << " count " << lo.count << "\n";
3655 const char *string = Ptr + sizeof(struct MachO::linker_option_command);
3656 uint32_t left = lo.cmdsize - sizeof(struct MachO::linker_option_command);
3657 uint32_t i = 0;
3658 while (left > 0) {
3659 while (*string == '\0' && left > 0) {
3660 string++;
3661 left--;
3662 }
3663 if (left > 0) {
3664 i++;
3665 outs() << " string #" << i << " " << format("%.*s\n", left, string);
3666 uint32_t len = strnlen(string, left) + 1;
3667 string += len;
3668 left -= len;
3669 }
3670 }
3671 if (lo.count != i)
3672 outs() << " count " << lo.count << " does not match number of strings " << i
3673 << "\n";
3674 }
3675
36463676 static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) {
36473677 if (dl.cmd == MachO::LC_ID_DYLIB)
36483678 outs() << " cmd LC_ID_DYLIB\n";
37963826 } else if (Command.C.cmd == MachO::LC_ENCRYPTION_INFO_64) {
37973827 MachO::encryption_info_command_64 Ei = Obj->getEncryptionInfoCommand64(Command);
37983828 PrintEncryptionInfoCommand64(Ei, Buf.size());
3829 } else if (Command.C.cmd == MachO::LC_LINKER_OPTION) {
3830 MachO::linker_option_command Lo = Obj->getLinkerOptionLoadCommand(Command);
3831 PrintLinkerOptionCommand(Lo, Command.Ptr);
37993832 } else if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
38003833 Command.C.cmd == MachO::LC_ID_DYLIB ||
38013834 Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||
299299 static int
300300 DumpLinkerOptionsCommand(const MachOObjectFile &Obj,
301301 const MachOObjectFile::LoadCommandInfo &LCI) {
302 MachO::linker_options_command LOLC = Obj.getLinkerOptionsLoadCommand(LCI);
302 MachO::linker_option_command LOLC = Obj.getLinkerOptionLoadCommand(LCI);
303303 outs() << " ('count', " << LOLC.count << ")\n"
304304 << " ('_strings', [\n";
305305
306 uint64_t DataSize = LOLC.cmdsize - sizeof(MachO::linker_options_command);
307 const char *P = LCI.Ptr + sizeof(MachO::linker_options_command);
306 uint64_t DataSize = LOLC.cmdsize - sizeof(MachO::linker_option_command);
307 const char *P = LCI.Ptr + sizeof(MachO::linker_option_command);
308308 StringRef Data(P, DataSize);
309309 for (unsigned i = 0; i != LOLC.count; ++i) {
310310 std::pair Split = Data.split('\0');
355355 return DumpLinkeditDataCommand(Obj, LCI);
356356 case MachO::LC_DATA_IN_CODE:
357357 return DumpDataInCodeDataCommand(Obj, LCI);
358 case MachO::LC_LINKER_OPTIONS:
358 case MachO::LC_LINKER_OPTION:
359359 return DumpLinkerOptionsCommand(Obj, LCI);
360360 case MachO::LC_VERSION_MIN_IPHONEOS:
361361 case MachO::LC_VERSION_MIN_MACOSX: