1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

Bug 337254 - Binary not found - Universal ppc+i386 executables are not picked up on 64 bit machines. Patch by Johan van den Berg.

This commit is contained in:
Sergey Prigogin 2011-02-16 01:30:34 +00:00
parent 98559b4f80
commit 97e5359102

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2009 QNX Software Systems and others. * Copyright (c) 2000, 2011 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -50,9 +50,7 @@ public class MachO64 {
protected static final SymbolComparator symbol_comparator = new SymbolComparator(); protected static final SymbolComparator symbol_comparator = new SymbolComparator();
public class MachOhdr { public class MachOhdr {
/* values of magic */ /* values of magic */
public final static int MH_MAGIC = 0xfeedface; /* the mach magic number */ public final static int MH_MAGIC = 0xfeedface; /* the mach magic number */
public final static int MH_CIGAM = 0xcefaedfe; public final static int MH_CIGAM = 0xcefaedfe;
@ -204,6 +202,7 @@ public class MachO64 {
public int sizeofcmds; /* the size of all the load commands */ public int sizeofcmds; /* the size of all the load commands */
public int flags; /* flags */ public int flags; /* flags */
public int reserved; // 64bit reserved public int reserved; // 64bit reserved
protected MachOhdr() throws IOException { protected MachOhdr() throws IOException {
efile.seek(0); efile.seek(0);
efile.setEndian(false); efile.setEndian(false);
@ -212,23 +211,19 @@ public class MachO64 {
efile.setEndian(true); efile.setEndian(true);
if (MH_CIGAM_64 == magic) if (MH_CIGAM_64 == magic)
b64 = true; b64 = true;
} } else if (magic == MH_UNIVERSAL) {
else
if ( magic == MH_UNIVERSAL)
{
String arch = System.getProperty("os.arch"); //$NON-NLS-1$ String arch = System.getProperty("os.arch"); //$NON-NLS-1$
int numArchives = efile.readIntE(); int numArchives = efile.readIntE();
while (numArchives-- > 0) while (numArchives-- > 0) {
{
int cpuType = efile.readIntE(); // cpuType int cpuType = efile.readIntE(); // cpuType
efile.readIntE(); // cpuSubType efile.readIntE(); // cpuSubType
int archiveOffset = efile.readIntE(); // archiveOffset int archiveOffset = efile.readIntE(); // archiveOffset
efile.readIntE(); // archiveSize efile.readIntE(); // archiveSize
efile.readIntE(); // archiveAlignment efile.readIntE(); // archiveAlignment
if ((cpuType == MachO64.MachOhdr.CPU_TYPE_I386 && arch.equalsIgnoreCase("i386")) || //$NON-NLS-1$ if ((cpuType == MachO64.MachOhdr.CPU_TYPE_I386 &&
(arch.equalsIgnoreCase("i386") || arch.equalsIgnoreCase("x86_64"))) || //$NON-NLS-1$ //$NON-NLS-2$
(cpuType == MachO64.MachOhdr.CPU_TYPE_POWERPC && arch.equalsIgnoreCase("ppc")) || //$NON-NLS-1$ (cpuType == MachO64.MachOhdr.CPU_TYPE_POWERPC && arch.equalsIgnoreCase("ppc")) || //$NON-NLS-1$
(cpuType == MachO64.MachOhdr.CPU_TYPE_X86_64 && arch.equalsIgnoreCase("x86_64"))) //$NON-NLS-1$ (cpuType == MachO64.MachOhdr.CPU_TYPE_X86_64 && arch.equalsIgnoreCase("x86_64"))) { //$NON-NLS-1$
{
if (cpuType == MachO64.MachOhdr.CPU_TYPE_X86_64) if (cpuType == MachO64.MachOhdr.CPU_TYPE_X86_64)
b64 = true; b64 = true;
efile.seek(archiveOffset); efile.seek(archiveOffset);
@ -240,9 +235,9 @@ public class MachO64 {
break; break;
} }
} }
} } else if (magic != MH_MAGIC && magic != MH_MAGIC_64) {
else if ( magic != MH_MAGIC && magic != MH_MAGIC_64)
throw new IOException(CCorePlugin.getResourceString("Util.exception.notMACHO")); //$NON-NLS-1$ throw new IOException(CCorePlugin.getResourceString("Util.exception.notMACHO")); //$NON-NLS-1$
}
if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64) if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64)
b64 = true; b64 = true;
cputype = efile.readIntE(); cputype = efile.readIntE();
@ -264,23 +259,19 @@ public class MachO64 {
isle = true; isle = true;
if (MH_CIGAM_64 == magic) if (MH_CIGAM_64 == magic)
b64 = true; b64 = true;
} } else if (magic == MH_UNIVERSAL) {
else
if ( magic == MH_UNIVERSAL)
{
String arch = System.getProperty("os.arch"); //$NON-NLS-1$ String arch = System.getProperty("os.arch"); //$NON-NLS-1$
int numArchives = makeInt(bytes, offset, isle); offset += 4; int numArchives = makeInt(bytes, offset, isle); offset += 4;
while (numArchives-- > 0) while (numArchives-- > 0) {
{
int cpuType = makeInt(bytes, offset, isle); offset += 4; int cpuType = makeInt(bytes, offset, isle); offset += 4;
offset += 4; // cpuSubType offset += 4; // cpuSubType
int archiveOffset = makeInt(bytes, offset, isle); offset += 4; int archiveOffset = makeInt(bytes, offset, isle); offset += 4;
offset += 4; // archiveSize offset += 4; // archiveSize
offset += 4; // archiveAlignment offset += 4; // archiveAlignment
if ((cpuType == MachO64.MachOhdr.CPU_TYPE_I386 && arch.equalsIgnoreCase("i386")) || //$NON-NLS-1$ if ((cpuType == MachO64.MachOhdr.CPU_TYPE_I386 &&
(arch.equalsIgnoreCase("i386") || arch.equalsIgnoreCase("x86_64"))) || //$NON-NLS-1$ //$NON-NLS-2$
(cpuType == MachO64.MachOhdr.CPU_TYPE_POWERPC && arch.equalsIgnoreCase("ppc")) || //$NON-NLS-1$ (cpuType == MachO64.MachOhdr.CPU_TYPE_POWERPC && arch.equalsIgnoreCase("ppc")) || //$NON-NLS-1$
(cpuType == MachO64.MachOhdr.CPU_TYPE_X86_64 && arch.equalsIgnoreCase("x86_64"))) //$NON-NLS-1$ (cpuType == MachO64.MachOhdr.CPU_TYPE_X86_64 && arch.equalsIgnoreCase("x86_64"))) { //$NON-NLS-1$
{
if (cpuType == MachO64.MachOhdr.CPU_TYPE_X86_64) if (cpuType == MachO64.MachOhdr.CPU_TYPE_X86_64)
b64 = true; b64 = true;
offset = archiveOffset; offset = archiveOffset;
@ -292,9 +283,9 @@ public class MachO64 {
break; break;
} }
} }
} } else if (magic != MH_MAGIC && magic != MH_MAGIC_64) {
else if ( magic != MH_MAGIC && magic != MH_MAGIC_64)
throw new IOException(CCorePlugin.getResourceString("Util.exception.notMACHO")); //$NON-NLS-1$ throw new IOException(CCorePlugin.getResourceString("Util.exception.notMACHO")); //$NON-NLS-1$
}
if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64) if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64)
b64 = true; b64 = true;
cputype = makeInt(bytes, offset, isle); offset += 4; cputype = makeInt(bytes, offset, isle); offset += 4;
@ -307,13 +298,13 @@ public class MachO64 {
reserved = makeInt(bytes, offset, isle); offset += 4; reserved = makeInt(bytes, offset, isle); offset += 4;
} }
} }
public boolean is64() { public boolean is64() {
return b64; return b64;
} }
} }
private static final int makeInt(byte [] val, int offset, boolean isle) throws IOException private static final int makeInt(byte [] val, int offset, boolean isle) throws IOException {
{
if (val.length < offset + 4) if (val.length < offset + 4)
throw new IOException(); throw new IOException();
if (isle ) { if (isle ) {
@ -410,7 +401,6 @@ public class MachO64 {
} }
public class Section { public class Section {
public final static int SECTION_TYP = 0x000000ff; /* 256 section types */ public final static int SECTION_TYP = 0x000000ff; /* 256 section types */
public final static int SECTION_ATTRIBUTES = 0xffffff00; /* 24 section attributes */ public final static int SECTION_ATTRIBUTES = 0xffffff00; /* 24 section attributes */
public final static int SECTION_ATTRIBUTES_USR =0xff000000; /* User setable attributes */ public final static int SECTION_ATTRIBUTES_USR =0xff000000; /* User setable attributes */
@ -683,9 +673,7 @@ public class MachO64 {
} }
} }
private void commonSetup( String file, long offset, boolean filton ) private void commonSetup(String file, long offset, boolean filton ) throws IOException {
throws IOException
{
this.cppFiltEnabled = filton; this.cppFiltEnabled = filton;
try { try {
@ -948,7 +936,7 @@ public class MachO64 {
} }
/** /**
* We have to implement a separate compararator since when we do the * We have to implement a separate comparator since when we do the
* binary search down below we are using a Long and a Symbol object * binary search down below we are using a Long and a Symbol object
* and the Long doesn't know how to compare against a Symbol so if * and the Long doesn't know how to compare against a Symbol so if
* we compare Symbol vs Long it is ok, but not if we do Long vs Symbol. * we compare Symbol vs Long it is ok, but not if we do Long vs Symbol.
@ -956,7 +944,6 @@ public class MachO64 {
public static class SymbolComparator implements Comparator<Object> { public static class SymbolComparator implements Comparator<Object> {
long val1, val2; long val1, val2;
public int compare(Object o1, Object o2) { public int compare(Object o1, Object o2) {
if (o1 instanceof Long) { if (o1 instanceof Long) {
val1 = ((Long) o1).longValue(); val1 = ((Long) o1).longValue();
} else if (o1 instanceof Symbol) { } else if (o1 instanceof Symbol) {
@ -972,8 +959,7 @@ public class MachO64 {
} else { } else {
return -1; return -1;
} }
return (val1 == val2) ? 0 return val1 == val2 ? 0 : val1 < val2 ? -1 : 1;
: ((val1 < val2) ? -1 : 1);
} }
} }
@ -1161,7 +1147,6 @@ public class MachO64 {
} }
public static Attribute getAttributes(byte [] array) throws IOException { public static Attribute getAttributes(byte [] array) throws IOException {
MachO64 emptyMachO = new MachO64(); MachO64 emptyMachO = new MachO64();
emptyMachO.mhdr = emptyMachO.new MachOhdr(array); emptyMachO.mhdr = emptyMachO.new MachOhdr(array);
//emptyMachO.sections = new MachO64.Section[0]; //emptyMachO.sections = new MachO64.Section[0];
@ -1307,7 +1292,6 @@ public class MachO64 {
} }
} }
} }
} }
private ArrayList<Section> getSections(SegmentCommand seg) throws IOException { private ArrayList<Section> getSections(SegmentCommand seg) throws IOException {
@ -1783,12 +1767,12 @@ public class MachO64 {
if (loadcommands == null ) { if (loadcommands == null ) {
loadLoadCommands(); loadLoadCommands();
} }
} catch (Throwable e) { e.printStackTrace(); } } catch (Throwable e) {
e.printStackTrace();
}
for (LoadCommand loadcommand : loadcommands) { for (LoadCommand loadcommand : loadcommands) {
if (loadcommand.cmd == LoadCommand.LC_SYMTAB) if (loadcommand.cmd == LoadCommand.LC_SYMTAB) {
{
symtab = (SymtabCommand)loadcommand; symtab = (SymtabCommand)loadcommand;
try { try {
int symSize = symtab.nsyms * (mhdr.is64() ? StabConstant.SIZE_64 : StabConstant.SIZE); int symSize = symtab.nsyms * (mhdr.is64() ? StabConstant.SIZE_64 : StabConstant.SIZE);
@ -1799,8 +1783,9 @@ public class MachO64 {
efile.seek(symtab.stroff); efile.seek(symtab.stroff);
efile.readFully(stabstr); efile.readFully(stabstr);
symReader = new StabsReader(data, stabstr, getAttributes().isLittleEndian(),mhdr.is64()); symReader = new StabsReader(data, stabstr, getAttributes().isLittleEndian(),mhdr.is64());
} catch (Throwable e) { e.printStackTrace(); } } catch (Throwable e) {
e.printStackTrace();
}
} }
} }
return symReader; return symReader;