Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 41 additions & 13 deletions llvm/src/main/java/org/robovm/llvm/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,37 @@ public class NativeLibrary {
static {
String osProp = System.getProperty("os.name").toLowerCase();
String archProp = System.getProperty("os.arch").toLowerCase();
if (osProp.startsWith("mac") || osProp.startsWith("darwin")) {
if (osProp.startsWith("mac") || osProp.startsWith("darwin")) {
os = "macosx";
libName = "librobovm-llvm" + ".dylib";
} else if (osProp.startsWith("linux")) {
os = "linux";
libName = "librobovm-llvm" + ".so";
} else if (osProp.startsWith("windows")) {
os = "windows";
libName = "librobovm-llvm" + ".dll";
} else {
throw new Error("Unsupported OS: " + System.getProperty("os.name"));
}
if (archProp.matches("amd64|x86[-_]64")) {
arch = "x86_64";
} else if (archProp.matches("i386|x86")) {
arch = "x86";
if ("windows".equals(os)) {
String model = System.getProperty("sun.arch.data.model");
if ("32".equals(model))
arch = "x86";
else if ("64".equals(model))
arch = "x86_64";
else
throw new Error("Unsupported sun.arch.data.model: " + model);

} else {
throw new Error("Unsupported arch: " + System.getProperty("os.arch"));
if (archProp.matches("amd64|x86[-_]64")) {
arch = "x86_64";
} else if (archProp.matches("i386|x86")) {
arch = "x86";
} else {
throw new Error("Unsupported arch: "
+ System.getProperty("os.arch"));
}
}

libName = "librobovm-llvm" + (os.equals("macosx") ? ".dylib" : ".so");
}

public static synchronized void load() {
Expand All @@ -64,9 +79,11 @@ public static synchronized void load() {
String prefix = libName.substring(0, libName.lastIndexOf('.'));
String ext = libName.substring(libName.lastIndexOf('.'));

InputStream in = NativeLibrary.class.getResourceAsStream("binding/" + os + "/" + arch + "/" + libName);
String path = "binding/" + os + "/" + arch + "/" + libName;
InputStream in = NativeLibrary.class.getResourceAsStream(path);
if (in == null) {
throw new UnsatisfiedLinkError("Native library for " + os + "-" + arch + " not found");
throw new UnsatisfiedLinkError("Native library for " + os + "-"
+ arch + " not found. Path: " + path);
}
OutputStream out = null;
File tmpLibFile = null;
Expand All @@ -82,11 +99,22 @@ public static synchronized void load() {
closeQuietly(out);
}

Runtime.getRuntime().load(tmpLibFile.getAbsolutePath());
if (!LLVM.StartMultithreaded()) {
throw new UnsatisfiedLinkError("LLVMStartMultithreaded failed");
path= tmpLibFile.getAbsolutePath() ;

boolean result=true;
try {
Runtime.getRuntime().load(path);
result = !LLVM.StartMultithreaded();
} catch (Throwable e) {
String message = "Error while loading: " +path ;
throw new RuntimeException(message, e) ;
}
if (result) {
String message = "LLVMStartMultithreaded failed while loading: " +path ;
throw new UnsatisfiedLinkError(message);
}


LLVM.InitializeAllTargets();
LLVM.InitializeAllTargetInfos();
LLVM.InitializeAllTargetMCs();
Expand Down