Commit 84200662 authored by Thomas Guillem's avatar Thomas Guillem Committed by Jean-Baptiste Kempf

LibVlcUtil: add x86_64 and aarch64 support

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent a62f5ad9
...@@ -121,17 +121,27 @@ public class LibVlcUtil { ...@@ -121,17 +121,27 @@ public class LibVlcUtil {
} catch (Exception e) { } } catch (Exception e) { }
} }
Log.i(TAG, "machine = " + (elf.e_machine == EM_ARM ? "arm" : elf.e_machine == EM_386 ? "x86" : "mips")); final boolean elfHasX86 = elf.e_machine == EM_386 || elf.e_machine == EM_X86_64;
final boolean elfHasArm = elf.e_machine == EM_ARM || elf.e_machine == EM_AARCH64;
final boolean elfHasMips = elf.e_machine == EM_MIPS;
final boolean elfIs64bits = elf.is64bits;
Log.i(TAG, "machine = " + (elfHasArm ? "arm" : elfHasX86 ? "x86" : "mips") + ", " +
(elfIs64bits ? "64bits" : "32bits"));
Log.i(TAG, "arch = " + elf.att_arch); Log.i(TAG, "arch = " + elf.att_arch);
Log.i(TAG, "fpu = " + elf.att_fpu); Log.i(TAG, "fpu = " + elf.att_fpu);
boolean hasNeon = false, hasFpu = false, hasArmV6 = false, boolean hasNeon = false, hasFpu = false, hasArmV6 = false,
hasArmV7 = false, hasMips = false, hasX86 = false; hasArmV7 = false, hasMips = false, hasX86 = false, is64bits = false;
float bogoMIPS = -1; float bogoMIPS = -1;
int processors = 0; int processors = 0;
if(CPU_ABI.equals("x86") || if(CPU_ABI.equals("x86") ||
CPU_ABI2.equals("x86")) { CPU_ABI2.equals("x86")) {
hasX86 = true; hasX86 = true;
} else if(CPU_ABI.equals("x86_64") ||
CPU_ABI2.equals("x86_64")) {
hasX86 = true;
is64bits = true;
} else if(CPU_ABI.equals("armeabi-v7a") || } else if(CPU_ABI.equals("armeabi-v7a") ||
CPU_ABI2.equals("armeabi-v7a")) { CPU_ABI2.equals("armeabi-v7a")) {
hasArmV7 = true; hasArmV7 = true;
...@@ -139,6 +149,12 @@ public class LibVlcUtil { ...@@ -139,6 +149,12 @@ public class LibVlcUtil {
} else if(CPU_ABI.equals("armeabi") || } else if(CPU_ABI.equals("armeabi") ||
CPU_ABI2.equals("armeabi")) { CPU_ABI2.equals("armeabi")) {
hasArmV6 = true; hasArmV6 = true;
} else if(CPU_ABI.equals("arm64-v8a") ||
CPU_ABI2.equals("arm64-v8a")) {
hasNeon = true;
hasArmV6 = true;
hasArmV7 = true;
is64bits = true;
} }
try { try {
...@@ -192,21 +208,21 @@ public class LibVlcUtil { ...@@ -192,21 +208,21 @@ public class LibVlcUtil {
processors = 1; // possibly borked cpuinfo? processors = 1; // possibly borked cpuinfo?
// Enforce proper architecture to prevent problems // Enforce proper architecture to prevent problems
if(elf.e_machine == EM_386 && !hasX86) { if(elfHasX86 && !hasX86) {
errorMsg = "x86 build on non-x86 device"; errorMsg = "x86 build on non-x86 device";
isCompatible = false; isCompatible = false;
return false; return false;
} else if(elf.e_machine == EM_ARM && hasX86) { } else if(elfHasArm && hasX86) {
errorMsg = "ARM build on x86 device"; errorMsg = "ARM build on x86 device";
isCompatible = false; isCompatible = false;
return false; return false;
} }
if(elf.e_machine == EM_MIPS && !hasMips) { if(elfHasMips && !hasMips) {
errorMsg = "MIPS build on non-MIPS device"; errorMsg = "MIPS build on non-MIPS device";
isCompatible = false; isCompatible = false;
return false; return false;
} else if(elf.e_machine == EM_ARM && hasMips) { } else if(elfHasArm && hasMips) {
errorMsg = "ARM build on MIPS device"; errorMsg = "ARM build on MIPS device";
isCompatible = false; isCompatible = false;
return false; return false;
...@@ -228,6 +244,10 @@ public class LibVlcUtil { ...@@ -228,6 +244,10 @@ public class LibVlcUtil {
return false; return false;
} }
} }
if (elfIs64bits && !is64bits) {
errorMsg = "64bits build on 32bits device";
isCompatible = false;
}
float frequency = -1; float frequency = -1;
try { try {
...@@ -256,6 +276,7 @@ public class LibVlcUtil { ...@@ -256,6 +276,7 @@ public class LibVlcUtil {
machineSpecs.hasMips = hasMips; machineSpecs.hasMips = hasMips;
machineSpecs.hasNeon = hasNeon; machineSpecs.hasNeon = hasNeon;
machineSpecs.hasX86 = hasX86; machineSpecs.hasX86 = hasX86;
machineSpecs.is64bits = is64bits;
machineSpecs.bogoMIPS = bogoMIPS; machineSpecs.bogoMIPS = bogoMIPS;
machineSpecs.processors = processors; machineSpecs.processors = processors;
machineSpecs.frequency = frequency; machineSpecs.frequency = frequency;
...@@ -273,6 +294,7 @@ public class LibVlcUtil { ...@@ -273,6 +294,7 @@ public class LibVlcUtil {
public boolean hasArmV7; public boolean hasArmV7;
public boolean hasMips; public boolean hasMips;
public boolean hasX86; public boolean hasX86;
public boolean is64bits;
public float bogoMIPS; public float bogoMIPS;
public int processors; public int processors;
public float frequency; /* in MHz */ public float frequency; /* in MHz */
...@@ -281,11 +303,14 @@ public class LibVlcUtil { ...@@ -281,11 +303,14 @@ public class LibVlcUtil {
private static final int EM_386 = 3; private static final int EM_386 = 3;
private static final int EM_MIPS = 8; private static final int EM_MIPS = 8;
private static final int EM_ARM = 40; private static final int EM_ARM = 40;
private static final int EM_X86_64 = 62;
private static final int EM_AARCH64 = 183;
private static final int ELF_HEADER_SIZE = 52; private static final int ELF_HEADER_SIZE = 52;
private static final int SECTION_HEADER_SIZE = 40; private static final int SECTION_HEADER_SIZE = 40;
private static final int SHT_ARM_ATTRIBUTES = 0x70000003; private static final int SHT_ARM_ATTRIBUTES = 0x70000003;
private static class ElfData { private static class ElfData {
ByteOrder order; ByteOrder order;
boolean is64bits;
int e_machine; int e_machine;
int e_shoff; int e_shoff;
int e_shnum; int e_shnum;
...@@ -317,6 +342,8 @@ public class LibVlcUtil { ...@@ -317,6 +342,8 @@ public class LibVlcUtil {
switch (elf.e_machine) { switch (elf.e_machine) {
case EM_386: case EM_386:
case EM_MIPS: case EM_MIPS:
case EM_X86_64:
case EM_AARCH64:
return elf; return elf;
case EM_ARM: case EM_ARM:
in.close(); in.close();
...@@ -354,10 +381,12 @@ public class LibVlcUtil { ...@@ -354,10 +381,12 @@ public class LibVlcUtil {
bytes[1] != 'E' || bytes[1] != 'E' ||
bytes[2] != 'L' || bytes[2] != 'L' ||
bytes[3] != 'F' || bytes[3] != 'F' ||
bytes[4] != 1) { // ELFCLASS32, Only 32bit header is supported (bytes[4] != 1 && bytes[4] != 2)) {
Log.e(TAG, "ELF header invalid");
return false; return false;
} }
elf.is64bits = bytes[4] == 2;
elf.order = bytes[5] == 1 elf.order = bytes[5] == 1
? ByteOrder.LITTLE_ENDIAN // ELFDATA2LSB ? ByteOrder.LITTLE_ENDIAN // ELFDATA2LSB
: ByteOrder.BIG_ENDIAN; // ELFDATA2MSB : ByteOrder.BIG_ENDIAN; // ELFDATA2MSB
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment