Skip to content

Commit

Permalink
Sync with upstream trunk r236.
Browse files Browse the repository at this point in the history
  • Loading branch information
reverser committed Sep 2, 2014
1 parent f0822f3 commit c5b4bea
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 89 deletions.
6 changes: 3 additions & 3 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>CFBuildDate</key>
<string>Sun Mar 2 11:03:37 IST 2014</string>
<string>Tue Sep 2 23:25:07 WEST 2014</string>
<key>CFBuildNumber</key>
<string>9087</string>
<string>9089</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
Expand Down Expand Up @@ -44,7 +44,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>9087</string>
<string>9089</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
55 changes: 42 additions & 13 deletions LinkEdit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ - (MVNode *) createReloc64Node:(MVNode *)parent
// The first one has to be a X86_64_RELOC_SUBTRACTOR then must
// be followed by a X86_64_RELOC_UNSIGNED.

if (relocation_info->r_type == X86_64_RELOC_SUBTRACTOR)
if ((mach_header_64->cputype == CPU_TYPE_X86_64 && relocation_info->r_type == X86_64_RELOC_SUBTRACTOR)
||
(mach_header_64->cputype == CPU_TYPE_ARM64 && relocation_info->r_type == ARM64_RELOC_SUBTRACTOR))
{
color = [NSColor magentaColor];
prev_relocation_info = relocation_info;
Expand All @@ -372,7 +374,8 @@ - (MVNode *) createReloc64Node:(MVNode *)parent
// reference computed from difference of two symbols
//============================================

NSAssert(relocation_info->r_type == X86_64_RELOC_UNSIGNED, @"X86_64_RELOC_SUBTRACTOR must be followed by X86_64_RELOC_UNSIGNED");
NSAssert(!(mach_header_64->cputype == CPU_TYPE_X86_64) || relocation_info->r_type == X86_64_RELOC_UNSIGNED, @"X86_64_RELOC_SUBTRACTOR must be followed by X86_64_RELOC_UNSIGNED");
NSAssert(!(mach_header_64->cputype == CPU_TYPE_ARM64) || relocation_info->r_type == ARM64_RELOC_UNSIGNED, @"ARM64_RELOC_SUBTRACTOR must be followed by ARM64_RELOC_UNSIGNED");
NSParameterAssert (relocation_info->r_address == prev_relocation_info->r_address);

color = [NSColor magentaColor];
Expand Down Expand Up @@ -429,10 +432,15 @@ - (MVNode *) createReloc64Node:(MVNode *)parent
// 32bit signed PC Rel
NSParameterAssert(relocation_info->r_pcrel == true);
uint32_t relocValue = nlist_64->n_value - relocation_info->r_address - baseAddress - relocLength;
uint32_t relocAddend = [self read_uint32:rangeReloc] -
(relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? 1 :
uint32_t relocAddend = [self read_uint32:rangeReloc];

if (mach_header_64->cputype == CPU_TYPE_X86_64)
{
relocAddend -= (relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? 1 :
relocation_info->r_type == X86_64_RELOC_SIGNED_2 ? 2 :
relocation_info->r_type == X86_64_RELOC_SIGNED_4 ? 4 : 0);
}

if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend"
Expand Down Expand Up @@ -477,10 +485,15 @@ - (MVNode *) createReloc64Node:(MVNode *)parent
{
NSParameterAssert(relocation_info->r_pcrel == true);
NSRange rangeReloc = NSMakeRange(relocLocation,0);
uint32_t relocAddend = [self read_uint32:rangeReloc] -
(relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? 1 :
uint32_t relocAddend = [self read_uint32:rangeReloc];

if (mach_header_64->cputype == CPU_TYPE_X86_64)
{
relocAddend -= (relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? 1 :
relocation_info->r_type == X86_64_RELOC_SIGNED_2 ? 2 :
relocation_info->r_type == X86_64_RELOC_SIGNED_4 ? 4 : 0);
}

if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend"
Expand Down Expand Up @@ -551,7 +564,9 @@ - (MVNode *) createReloc64Node:(MVNode *)parent
NSRange rangeReloc = NSMakeRange(relocLocation,0);
uint64_t relocValue = 0;

if (relocation_info->r_type == X86_64_RELOC_SUBTRACTOR)
if ((mach_header_64->cputype == CPU_TYPE_X86_64 && relocation_info->r_type == X86_64_RELOC_SUBTRACTOR)
||
(mach_header_64->cputype == CPU_TYPE_ARM64 && relocation_info->r_type == ARM64_RELOC_SUBTRACTOR))
{
prev_relocation_info = relocation_info;
}
Expand All @@ -565,7 +580,9 @@ - (MVNode *) createReloc64Node:(MVNode *)parent
{
relocValue = [self read_uint32:rangeReloc];

if (relocation_info->r_type == X86_64_RELOC_UNSIGNED)
if ((mach_header_64->cputype == CPU_TYPE_X86_64 && relocation_info->r_type == X86_64_RELOC_UNSIGNED)
||
(mach_header_64->cputype == CPU_TYPE_ARM64 && relocation_info->r_type == ARM64_RELOC_UNSIGNED))
{
// 32bit direct relocation
NSParameterAssert (relocation_info->r_pcrel == false);
Expand All @@ -574,16 +591,22 @@ - (MVNode *) createReloc64Node:(MVNode *)parent
{
// 32bit PC relative signed relocation
NSParameterAssert (relocation_info->r_pcrel == true);
relocValue += relocation_info->r_address + baseAddress + relocLength -
(relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? 1 :
relocValue += relocation_info->r_address + baseAddress + relocLength;

if (mach_header_64->cputype == CPU_TYPE_X86_64)
{
relocValue -= (relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? 1 :
relocation_info->r_type == X86_64_RELOC_SIGNED_2 ? 2 :
relocation_info->r_type == X86_64_RELOC_SIGNED_4 ? 4 : 0);
}

}
}
else if (relocLength == sizeof(uint64_t))
{
// 64bit direct relocation
NSParameterAssert (relocation_info->r_type == X86_64_RELOC_UNSIGNED);
NSParameterAssert (!(mach_header_64->cputype == CPU_TYPE_X86_64) || relocation_info->r_type == X86_64_RELOC_UNSIGNED);
NSParameterAssert (!(mach_header_64->cputype == CPU_TYPE_ARM64) || relocation_info->r_type == ARM64_RELOC_UNSIGNED);
NSParameterAssert (relocation_info->r_pcrel == false);
relocValue = [self read_uint64:rangeReloc];
}
Expand Down Expand Up @@ -1673,6 +1696,7 @@ - (MVNode *) createSplitSegmentNode:parent

NSRange range = NSMakeRange(location,0);
NSString * lastReadHex;
NSString * symbolName = nil;

while (NSMaxRange(range) < location + length)
{
Expand Down Expand Up @@ -1709,6 +1733,8 @@ - (MVNode *) createSplitSegmentNode:parent
kind == 0x1E ? @"thumb2 movt low high 4 bits=0xE" :
kind == 0x1f ? @"thumb2 movt low high 4 bits=0xF" : @"???"];

[node.details setAttributes:MVCellColorAttributeName,[NSColor greenColor],nil];

uint64_t address = baseAddress;
uint64_t offset = 0;
do
Expand All @@ -1719,9 +1745,12 @@ - (MVNode *) createSplitSegmentNode:parent
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"uleb128"
:[NSString stringWithFormat:@"%@ 0x%qX",
:[NSString stringWithFormat:@"%@ %@",
[self is64bit] == NO ? [self findSectionContainsRVA:address] : [self findSectionContainsRVA64:address],
address]];
(symbolName = [self is64bit] == NO ? [self findSymbolAtRVA:(uint32_t)address] : [self findSymbolAtRVA64:address])]];

[node.details setAttributes:MVMetaDataAttributeName,symbolName,nil];

} while (offset != 0);

[node.details setAttributes:MVUnderlineAttributeName,@"YES",nil];
Expand Down
2 changes: 2 additions & 0 deletions LoadCommands.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ - (NSString *)getNameForCommand:(uint32_t)cmd
case LC_SOURCE_VERSION: return @"LC_SOURCE_VERSION";
case LC_DYLIB_CODE_SIGN_DRS: return @"LC_DYLIB_CODE_SIGN_DRS";
case LC_LINKER_OPTION: return @"LC_LINKER_OPTION";
case LC_LINKER_OPTIMIZATION_HINT: return @"LC_LINKER_OPTIMIZATION_HINT";
}
}

Expand Down Expand Up @@ -2263,6 +2264,7 @@ -(MVNode *)createLoadCommandNode:(MVNode *)parent
case LC_FUNCTION_STARTS:
case LC_DATA_IN_CODE:
case LC_DYLIB_CODE_SIGN_DRS:
case LC_LINKER_OPTIMIZATION_HINT:
{
MATCH_STRUCT(linkedit_data_command,location)
node = [self createLCLinkeditDataNode:parent
Expand Down
Loading

0 comments on commit c5b4bea

Please sign in to comment.