Search in sources :

Example 1 with LLVMLinkerException

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()));
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) BitcodeID(com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 2 with LLVMLinkerException

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);
    }
}
Also used : TruffleFile(com.oracle.truffle.api.TruffleFile) LLVMScope(com.oracle.truffle.llvm.runtime.LLVMScope) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 3 with LLVMLinkerException

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);
}
Also used : LLVMAlias(com.oracle.truffle.llvm.runtime.LLVMAlias) LLVMGlobal(com.oracle.truffle.llvm.runtime.global.LLVMGlobal) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)

Example 4 with LLVMLinkerException

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);
}
Also used : LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)

Example 5 with LLVMLinkerException

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);
        }
    }
}
Also used : LLVMGlobalContainer(com.oracle.truffle.llvm.runtime.global.LLVMGlobalContainer) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) ArrayList(java.util.ArrayList) LLVMGlobal(com.oracle.truffle.llvm.runtime.global.LLVMGlobal) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException) LLVMSymbol(com.oracle.truffle.llvm.runtime.LLVMSymbol)

Aggregations

LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)10 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 TruffleFile (com.oracle.truffle.api.TruffleFile)2 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)2 FunctionSymbol (com.oracle.truffle.llvm.parser.model.functions.FunctionSymbol)2 GlobalVariable (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable)2 BitcodeID (com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID)2 LLVMScope (com.oracle.truffle.llvm.runtime.LLVMScope)2 LLVMParserException (com.oracle.truffle.llvm.runtime.except.LLVMParserException)2 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)2 ArrayList (java.util.ArrayList)2 Assumption (com.oracle.truffle.api.Assumption)1 CallTarget (com.oracle.truffle.api.CallTarget)1 CastConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.CastConstant)1 GetElementPointerConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.GetElementPointerConstant)1 GlobalAlias (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)1 LLVMAlias (com.oracle.truffle.llvm.runtime.LLVMAlias)1 LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)1 LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)1