From a3f2d08801c5a54048faca52f422bcededf81b2a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 1 Feb 2015 05:21:39 +0100 Subject: Bug 1125 - Make ELF Reader 'jogamp.common.os.elf' Stateless ELF Reader 'jogamp.common.os.elf' currently uses Platform's pre-determined OS_TYPE and CPUType. It also uses the host platforms MachineDescription, hence can not read ELF files from other machines. This also forbids Platform to determine CPUType etc w/o having a valid 'os.arch' property. +++ ElfHeader should be split in - ElfHeaderPart1 (CPUType independent) - ElfHeaderPart2 (CPUType dependent) Fix shall make the ELF Reader self containing by only using ELF CPUType data, etc. This requires customization of struct parsing, where MachineDescription.Static index shall be - defined in ElfHeaderPart1 using e_Ident's CPUType. - used in ElfHeaderPart2 and all its struct types. --- .../com/jogamp/common/os/TestElfReader01.java | 72 ++++++++++++++-------- .../com/jogamp/common/util/IntIntHashMapTest.java | 2 +- .../jogamp/common/util/IntObjectHashMapTest.java | 2 +- 3 files changed, 50 insertions(+), 26 deletions(-) (limited to 'src/junit') diff --git a/src/junit/com/jogamp/common/os/TestElfReader01.java b/src/junit/com/jogamp/common/os/TestElfReader01.java index a750dd0..980a17a 100644 --- a/src/junit/com/jogamp/common/os/TestElfReader01.java +++ b/src/junit/com/jogamp/common/os/TestElfReader01.java @@ -8,7 +8,9 @@ import java.io.OutputStream; import java.io.RandomAccessFile; import java.util.List; -import jogamp.common.os.elf.ElfHeader; +import jogamp.common.os.PlatformPropsImpl; +import jogamp.common.os.elf.ElfHeaderPart1; +import jogamp.common.os.elf.ElfHeaderPart2; import jogamp.common.os.elf.Section; import jogamp.common.os.elf.SectionArmAttributes; import jogamp.common.os.elf.SectionHeader; @@ -26,6 +28,7 @@ public class TestElfReader01 extends SingletonJunitCase { public static String GNU_LINUX_SELF_EXE = "/proc/self/exe"; public static String ARM_HF_EXE = "tst-exe-armhf"; public static String ARM_SF_EXE = "tst-exe-arm"; + static File userFile = null; private static boolean checkFileReadAccess(final File file) { try { @@ -49,49 +52,64 @@ public class TestElfReader01 extends SingletonJunitCase { } @Test - public void testGNULinuxSelfExe () throws IOException { - if( OSType.LINUX == Platform.getOSType() ) { - final File f = new File(GNU_LINUX_SELF_EXE); - if( checkFileReadAccess(f) ) { - testElfHeaderImpl(f, false); + public void test01GNULinuxSelfExe () throws IOException { + if( null == userFile ) { + if( OSType.LINUX == Platform.getOSType() ) { + final File f = new File(GNU_LINUX_SELF_EXE); + if( checkFileReadAccess(f) ) { + testElfHeaderImpl(f, false); + } } } } @Test - public void testJavaLib () throws IOException { - File jvmLib = findJVMLib("java"); - if( null == jvmLib ) { - jvmLib = findJVMLib("jvm"); + public void test02JavaLib () throws IOException { + if( null == userFile ) { + File jvmLib = findJVMLib("java"); + if( null == jvmLib ) { + jvmLib = findJVMLib("jvm"); + } + if( null != jvmLib ) { + testElfHeaderImpl(jvmLib, false); + } } - if( null != jvmLib ) { - testElfHeaderImpl(jvmLib, false); + } + + @Test + public void test99UserFile() throws IOException { + if( null != userFile ) { + testElfHeaderImpl(userFile, false); } } void testElfHeaderImpl(final File file, final boolean fileOutSections) throws IOException { + Platform.initSingleton(); System.err.println("Test file "+file.getAbsolutePath()); final RandomAccessFile in = new RandomAccessFile(file, "r"); try { - final ElfHeader eh; + final ElfHeaderPart1 eh1; + final ElfHeaderPart2 eh2; try { - eh = ElfHeader.read(in); + eh1 = ElfHeaderPart1.read(PlatformPropsImpl.OS_TYPE, in); + eh2 = ElfHeaderPart2.read(eh1, in); } catch (final Exception e) { System.err.println("Probably not an ELF file - or not in current format: (caught) "+e.getMessage()); e.printStackTrace(); return; } int i=0; - System.err.println(eh); - System.err.println("SH entsz "+eh.d.getE_shentsize()); - System.err.println("SH off "+toHexString(eh.d.getE_shoff())); - System.err.println("SH strndx "+eh.d.getE_shstrndx()); - System.err.println("SH num "+eh.sht.length); - if( 0 < eh.sht.length ) { - System.err.println("SH size "+eh.sht[0].d.getBuffer().limit()); + System.err.println(eh1); + System.err.println(eh2); + System.err.println("SH entsz "+eh2.raw.getE_shentsize()); + System.err.println("SH off "+toHexString(eh2.raw.getE_shoff())); + System.err.println("SH strndx "+eh2.raw.getE_shstrndx()); + System.err.println("SH num "+eh2.sht.length); + if( 0 < eh2.sht.length ) { + System.err.println("SH size "+eh2.sht[0].raw.getBuffer().limit()); } { - final SectionHeader sh = eh.getSectionHeader(SectionHeader.SHT_ARM_ATTRIBUTES); + final SectionHeader sh = eh2.getSectionHeader(SectionHeader.SHT_ARM_ATTRIBUTES); boolean abiVFPArgsAcceptsVFPVariant = false; if( null != sh ) { final SectionArmAttributes sArmAttrs = (SectionArmAttributes) sh.readSection(in); @@ -102,8 +120,8 @@ public class TestElfReader01 extends SingletonJunitCase { } System.err.println("abiVFPArgsAcceptsVFPVariant "+abiVFPArgsAcceptsVFPVariant); } - for(i=0; i