use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.
the class LLVMContext method checkSymbol.
/**
* This method is only intended to be used during initialization of a Sulong library.
*/
@TruffleBoundary
public boolean checkSymbol(LLVMSymbol symbol) {
assert !symbol.isAlias();
if (symbol.hasValidIndexAndID()) {
BitcodeID bitcodeID = symbol.getBitcodeIDUncached();
int id = bitcodeID.getId();
if (id < symbolDynamicStorage.length && symbolDynamicStorage[id] != null) {
LLVMPointer[] symbols = symbolDynamicStorage[id];
int index = symbol.getSymbolIndexUncached();
return symbols[index] != null;
}
}
throw new LLVMLinkerException(String.format("External %s %s cannot be found.", symbol.getKind(), symbol.getName()));
}
use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.
the class ParserDriver method registerRenamed.
/**
* An unresolved name has the form defined by the {@code _SULONG_IMPORT_SYMBOL(libName,
* symbolName)} macro defined in the {@code sulong-internal.h} header file. Check whether we
* have a symbol named "symbolName" in the library "libName". If it exists, introduce an alias.
* This can be used to explicitly call symbols from a certain standard library, in case the
* symbol is hidden (either using the "hidden" attribute, or because it is overridden).
*/
private void registerRenamed(String name, GlobalSymbol external, RegisterRenamed result) {
int idx = name.indexOf('_', SULONG_RENAME_MARKER_LEN);
if (idx > 0) {
String lib = name.substring(SULONG_RENAME_MARKER_LEN, idx);
LLVMScope scope = language.getInternalFileScopes(getSimpleLibraryName(lib));
if (scope == null) {
try {
// If the library that contains the function has not been parsed,
// then the library will be lazily parse now.
String libName = lib + "." + language.getCapability(PlatformCapability.class).getLibrarySuffix();
TruffleFile file = createTruffleFile(libName, null, InternalLibraryLocator.INSTANCE, "<default bitcode library>");
context.getEnv().parseInternal(Source.newBuilder("llvm", file).internal(context.isInternalLibraryFile(file)).build());
scope = language.getInternalFileScopes(getSimpleLibraryName(lib));
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
if (scope == null) {
// initialised.
throw new LLVMLinkerException(String.format("The symbol %s could not be imported because library %s was not found during symbol renaming", external.getName(), lib));
}
String originalName = name.substring(idx + 1);
result.register(scope, originalName, lib);
}
}
use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.
the class ParserDriver method createNewGlobal.
private static void createNewGlobal(LLVMScope scope, String originalName, LLVMParserResult parserResult, GlobalVariable external, String lib, String name) {
LLVMGlobal originalSymbol = scope.getGlobalVariable(originalName);
if (originalSymbol == null) {
throw new LLVMLinkerException(String.format("The symbol %s could not be imported because the symbol %s was not found in library %s", external.getName(), originalName, lib));
}
LLVMAlias newGlobal = new LLVMAlias(name, originalSymbol, false);
parserResult.getRuntime().getFileScope().register(newGlobal);
}
use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.
the class ParserDriver method createNewFunction.
private static void createNewFunction(LLVMScope scope, String originalName, LLVMParserResult parserResult, FunctionSymbol external, String lib, String name, ListIterator<FunctionSymbol> it) {
LLVMFunction originalSymbol = scope.getFunction(originalName);
if (originalSymbol == null) {
throw new LLVMLinkerException(String.format("The symbol %s could not be imported because the symbol %s was not found in library %s", external.getName(), originalName, lib));
}
LLVMFunction newFunction = LLVMFunction.create(name, originalSymbol.getFunction(), originalSymbol.getType(), parserResult.getRuntime().getBitcodeID(), external.getIndex(), external.isExported(), parserResult.getRuntime().getFile().getPath(), external.isExternalWeak());
parserResult.getRuntime().getFileScope().register(newFunction);
if (external.isExported()) {
parserResult.getRuntime().getPublicFileScope().register(newFunction);
}
it.remove();
parserResult.getDefinedFunctions().add(external);
}
use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.
the class InitializeSymbolsNode method allocGlobals.
private void allocGlobals(LLVMContext context, LLVMPointer roBase, LLVMPointer rwBase) {
for (int i = 0; i < globals.length; i++) {
LLVMSymbol allocGlobal = globals[i];
LLVMGlobal descriptor = fileScope.getGlobalVariable(allocGlobal.getName());
if (descriptor == null) {
exception.enter();
throw new LLVMLinkerException(this, "Global variable %s not found", allocGlobal.getName());
}
if (!context.checkSymbol(allocGlobal)) {
// because of our symbol overriding support, it can happen that the global was
// already bound before to a different target location
LLVMPointer ref;
if (globalOffsets[i] == -1) {
ref = LLVMManagedPointer.create(new LLVMGlobalContainer());
} else {
LLVMPointer base = globalIsReadOnly[i] ? roBase : rwBase;
ref = base.increment(globalOffsets[i]);
}
context.initializeSymbol(globals[i], ref);
List<LLVMSymbol> list = new ArrayList<>(1);
list.add(descriptor);
context.registerSymbolReverseMap(list, ref);
}
}
}
Aggregations