mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-20 05:38:50 +00:00
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
This commit is contained in:
parent
a582f1f396
commit
1025e9e9d6
@ -346,8 +346,8 @@ public:
|
|||||||
getSegmentLoadCommand(const LoadCommandInfo &L) const;
|
getSegmentLoadCommand(const LoadCommandInfo &L) const;
|
||||||
MachO::segment_command_64
|
MachO::segment_command_64
|
||||||
getSegment64LoadCommand(const LoadCommandInfo &L) const;
|
getSegment64LoadCommand(const LoadCommandInfo &L) const;
|
||||||
MachO::linker_options_command
|
MachO::linker_option_command
|
||||||
getLinkerOptionsLoadCommand(const LoadCommandInfo &L) const;
|
getLinkerOptionLoadCommand(const LoadCommandInfo &L) const;
|
||||||
MachO::version_min_command
|
MachO::version_min_command
|
||||||
getVersionMinLoadCommand(const LoadCommandInfo &L) const;
|
getVersionMinLoadCommand(const LoadCommandInfo &L) const;
|
||||||
MachO::dylib_command
|
MachO::dylib_command
|
||||||
|
@ -131,7 +131,7 @@ namespace llvm {
|
|||||||
LC_SOURCE_VERSION = 0x0000002Au,
|
LC_SOURCE_VERSION = 0x0000002Au,
|
||||||
LC_DYLIB_CODE_SIGN_DRS = 0x0000002Bu,
|
LC_DYLIB_CODE_SIGN_DRS = 0x0000002Bu,
|
||||||
LC_ENCRYPTION_INFO_64 = 0x0000002Cu,
|
LC_ENCRYPTION_INFO_64 = 0x0000002Cu,
|
||||||
LC_LINKER_OPTIONS = 0x0000002Du,
|
LC_LINKER_OPTION = 0x0000002Du,
|
||||||
LC_LINKER_OPTIMIZATION_HINT = 0x0000002Eu
|
LC_LINKER_OPTIMIZATION_HINT = 0x0000002Eu
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -874,7 +874,7 @@ namespace llvm {
|
|||||||
uint32_t export_size;
|
uint32_t export_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct linker_options_command {
|
struct linker_option_command {
|
||||||
uint32_t cmd;
|
uint32_t cmd;
|
||||||
uint32_t cmdsize;
|
uint32_t cmdsize;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
@ -1206,7 +1206,7 @@ namespace llvm {
|
|||||||
sys::swapByteOrder(C.datasize);
|
sys::swapByteOrder(C.datasize);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void swapStruct(linker_options_command &C) {
|
inline void swapStruct(linker_option_command &C) {
|
||||||
sys::swapByteOrder(C.cmd);
|
sys::swapByteOrder(C.cmd);
|
||||||
sys::swapByteOrder(C.cmdsize);
|
sys::swapByteOrder(C.cmdsize);
|
||||||
sys::swapByteOrder(C.count);
|
sys::swapByteOrder(C.count);
|
||||||
|
@ -418,7 +418,7 @@ void MachObjectWriter::WriteLinkeditLoadCommand(uint32_t Type,
|
|||||||
static unsigned ComputeLinkerOptionsLoadCommandSize(
|
static unsigned ComputeLinkerOptionsLoadCommandSize(
|
||||||
const std::vector<std::string> &Options, bool is64Bit)
|
const std::vector<std::string> &Options, bool is64Bit)
|
||||||
{
|
{
|
||||||
unsigned Size = sizeof(MachO::linker_options_command);
|
unsigned Size = sizeof(MachO::linker_option_command);
|
||||||
for (unsigned i = 0, e = Options.size(); i != e; ++i)
|
for (unsigned i = 0, e = Options.size(); i != e; ++i)
|
||||||
Size += Options[i].size() + 1;
|
Size += Options[i].size() + 1;
|
||||||
return RoundUpToAlignment(Size, is64Bit ? 8 : 4);
|
return RoundUpToAlignment(Size, is64Bit ? 8 : 4);
|
||||||
@ -431,10 +431,10 @@ void MachObjectWriter::WriteLinkerOptionsLoadCommand(
|
|||||||
uint64_t Start = OS.tell();
|
uint64_t Start = OS.tell();
|
||||||
(void) Start;
|
(void) Start;
|
||||||
|
|
||||||
Write32(MachO::LC_LINKER_OPTIONS);
|
Write32(MachO::LC_LINKER_OPTION);
|
||||||
Write32(Size);
|
Write32(Size);
|
||||||
Write32(Options.size());
|
Write32(Options.size());
|
||||||
uint64_t BytesWritten = sizeof(MachO::linker_options_command);
|
uint64_t BytesWritten = sizeof(MachO::linker_option_command);
|
||||||
for (unsigned i = 0, e = Options.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Options.size(); i != e; ++i) {
|
||||||
// Write each string, including the null byte.
|
// Write each string, including the null byte.
|
||||||
const std::string &Option = Options[i];
|
const std::string &Option = Options[i];
|
||||||
|
@ -2254,9 +2254,9 @@ MachOObjectFile::getSegment64LoadCommand(const LoadCommandInfo &L) const {
|
|||||||
return getStruct<MachO::segment_command_64>(this, L.Ptr);
|
return getStruct<MachO::segment_command_64>(this, L.Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
MachO::linker_options_command
|
MachO::linker_option_command
|
||||||
MachOObjectFile::getLinkerOptionsLoadCommand(const LoadCommandInfo &L) const {
|
MachOObjectFile::getLinkerOptionLoadCommand(const LoadCommandInfo &L) const {
|
||||||
return getStruct<MachO::linker_options_command>(this, L.Ptr);
|
return getStruct<MachO::linker_option_command>(this, L.Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
MachO::version_min_command
|
MachO::version_min_command
|
||||||
|
BIN
test/tools/llvm-objdump/X86/Inputs/linkerOption.macho-x86_64
Normal file
BIN
test/tools/llvm-objdump/X86/Inputs/linkerOption.macho-x86_64
Normal file
Binary file not shown.
@ -3,6 +3,8 @@
|
|||||||
// RUN: | FileCheck %s -check-prefix=EXE
|
// RUN: | FileCheck %s -check-prefix=EXE
|
||||||
// RUN: llvm-objdump -p %p/Inputs/dylibLoadKinds.macho-x86_64 \
|
// RUN: llvm-objdump -p %p/Inputs/dylibLoadKinds.macho-x86_64 \
|
||||||
// RUN: | FileCheck %s -check-prefix=LOAD
|
// RUN: | FileCheck %s -check-prefix=LOAD
|
||||||
|
// RUN: llvm-objdump -p %p/Inputs/linkerOption.macho-x86_64 \
|
||||||
|
// RUN: | FileCheck %s -check-prefix=LD_OPT
|
||||||
|
|
||||||
CHECK: Mach header
|
CHECK: Mach header
|
||||||
CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
|
CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
|
||||||
@ -366,3 +368,14 @@ LOAD: name /usr/lib/foo4.dylib (offset 24)
|
|||||||
LOAD: current version 0.0.0
|
LOAD: current version 0.0.0
|
||||||
LOAD: compatibility version 0.0.0
|
LOAD: compatibility version 0.0.0
|
||||||
|
|
||||||
|
LD_OPT: Load command 4
|
||||||
|
LD_OPT: cmd LC_LINKER_OPTION
|
||||||
|
LD_OPT: cmdsize 24
|
||||||
|
LD_OPT: count 1
|
||||||
|
LD_OPT: string #1 -lc++
|
||||||
|
LD_OPT: Load command 5
|
||||||
|
LD_OPT: cmd LC_LINKER_OPTION
|
||||||
|
LD_OPT: cmdsize 40
|
||||||
|
LD_OPT: count 2
|
||||||
|
LD_OPT: string #1 -framework
|
||||||
|
LD_OPT: string #2 Foundation
|
||||||
|
@ -3644,6 +3644,36 @@ static void PrintEncryptionInfoCommand64(MachO::encryption_info_command_64 ec,
|
|||||||
outs() << " pad " << ec.pad << "\n";
|
outs() << " pad " << ec.pad << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void PrintLinkerOptionCommand(MachO::linker_option_command lo,
|
||||||
|
const char *Ptr) {
|
||||||
|
outs() << " cmd LC_LINKER_OPTION\n";
|
||||||
|
outs() << " cmdsize " << lo.cmdsize;
|
||||||
|
if (lo.cmdsize < sizeof(struct MachO::linker_option_command))
|
||||||
|
outs() << " Incorrect size\n";
|
||||||
|
else
|
||||||
|
outs() << "\n";
|
||||||
|
outs() << " count " << lo.count << "\n";
|
||||||
|
const char *string = Ptr + sizeof(struct MachO::linker_option_command);
|
||||||
|
uint32_t left = lo.cmdsize - sizeof(struct MachO::linker_option_command);
|
||||||
|
uint32_t i = 0;
|
||||||
|
while (left > 0) {
|
||||||
|
while (*string == '\0' && left > 0) {
|
||||||
|
string++;
|
||||||
|
left--;
|
||||||
|
}
|
||||||
|
if (left > 0) {
|
||||||
|
i++;
|
||||||
|
outs() << " string #" << i << " " << format("%.*s\n", left, string);
|
||||||
|
uint32_t len = strnlen(string, left) + 1;
|
||||||
|
string += len;
|
||||||
|
left -= len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lo.count != i)
|
||||||
|
outs() << " count " << lo.count << " does not match number of strings " << i
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
|
||||||
static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) {
|
static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) {
|
||||||
if (dl.cmd == MachO::LC_ID_DYLIB)
|
if (dl.cmd == MachO::LC_ID_DYLIB)
|
||||||
outs() << " cmd LC_ID_DYLIB\n";
|
outs() << " cmd LC_ID_DYLIB\n";
|
||||||
@ -3797,6 +3827,9 @@ static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds,
|
|||||||
} else if (Command.C.cmd == MachO::LC_ENCRYPTION_INFO_64) {
|
} else if (Command.C.cmd == MachO::LC_ENCRYPTION_INFO_64) {
|
||||||
MachO::encryption_info_command_64 Ei = Obj->getEncryptionInfoCommand64(Command);
|
MachO::encryption_info_command_64 Ei = Obj->getEncryptionInfoCommand64(Command);
|
||||||
PrintEncryptionInfoCommand64(Ei, Buf.size());
|
PrintEncryptionInfoCommand64(Ei, Buf.size());
|
||||||
|
} else if (Command.C.cmd == MachO::LC_LINKER_OPTION) {
|
||||||
|
MachO::linker_option_command Lo = Obj->getLinkerOptionLoadCommand(Command);
|
||||||
|
PrintLinkerOptionCommand(Lo, Command.Ptr);
|
||||||
} else if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
|
} else if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
|
||||||
Command.C.cmd == MachO::LC_ID_DYLIB ||
|
Command.C.cmd == MachO::LC_ID_DYLIB ||
|
||||||
Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||
|
Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||
|
||||||
|
@ -300,12 +300,12 @@ DumpDataInCodeDataCommand(const MachOObjectFile &Obj,
|
|||||||
static int
|
static int
|
||||||
DumpLinkerOptionsCommand(const MachOObjectFile &Obj,
|
DumpLinkerOptionsCommand(const MachOObjectFile &Obj,
|
||||||
const MachOObjectFile::LoadCommandInfo &LCI) {
|
const MachOObjectFile::LoadCommandInfo &LCI) {
|
||||||
MachO::linker_options_command LOLC = Obj.getLinkerOptionsLoadCommand(LCI);
|
MachO::linker_option_command LOLC = Obj.getLinkerOptionLoadCommand(LCI);
|
||||||
outs() << " ('count', " << LOLC.count << ")\n"
|
outs() << " ('count', " << LOLC.count << ")\n"
|
||||||
<< " ('_strings', [\n";
|
<< " ('_strings', [\n";
|
||||||
|
|
||||||
uint64_t DataSize = LOLC.cmdsize - sizeof(MachO::linker_options_command);
|
uint64_t DataSize = LOLC.cmdsize - sizeof(MachO::linker_option_command);
|
||||||
const char *P = LCI.Ptr + sizeof(MachO::linker_options_command);
|
const char *P = LCI.Ptr + sizeof(MachO::linker_option_command);
|
||||||
StringRef Data(P, DataSize);
|
StringRef Data(P, DataSize);
|
||||||
for (unsigned i = 0; i != LOLC.count; ++i) {
|
for (unsigned i = 0; i != LOLC.count; ++i) {
|
||||||
std::pair<StringRef,StringRef> Split = Data.split('\0');
|
std::pair<StringRef,StringRef> Split = Data.split('\0');
|
||||||
@ -356,7 +356,7 @@ static int DumpLoadCommand(const MachOObjectFile &Obj,
|
|||||||
return DumpLinkeditDataCommand(Obj, LCI);
|
return DumpLinkeditDataCommand(Obj, LCI);
|
||||||
case MachO::LC_DATA_IN_CODE:
|
case MachO::LC_DATA_IN_CODE:
|
||||||
return DumpDataInCodeDataCommand(Obj, LCI);
|
return DumpDataInCodeDataCommand(Obj, LCI);
|
||||||
case MachO::LC_LINKER_OPTIONS:
|
case MachO::LC_LINKER_OPTION:
|
||||||
return DumpLinkerOptionsCommand(Obj, LCI);
|
return DumpLinkerOptionsCommand(Obj, LCI);
|
||||||
case MachO::LC_VERSION_MIN_IPHONEOS:
|
case MachO::LC_VERSION_MIN_IPHONEOS:
|
||||||
case MachO::LC_VERSION_MIN_MACOSX:
|
case MachO::LC_VERSION_MIN_MACOSX:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user