Search in sources :

Example 6 with LLVMLinkerException

use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.

the class ProcessUtil method executeSulongTestMainSameEngine.

public static ProcessResult executeSulongTestMainSameEngine(File bitcodeFile, String[] args, Map<String, String> options, Function<Context.Builder, CaptureOutput> captureOutput, Engine engine) throws IOException {
    if (TestOptions.TEST_AOT_IMAGE == null) {
        org.graalvm.polyglot.Source source = org.graalvm.polyglot.Source.newBuilder(LLVMLanguage.ID, bitcodeFile).build();
        Builder builder = Context.newBuilder();
        try (CaptureOutput out = captureOutput.apply(builder)) {
            int result;
            try (Context context = builder.engine(engine).arguments(LLVMLanguage.ID, args).options(options).allowAllAccess(true).build()) {
                Value main = context.eval(source);
                if (!main.canExecute()) {
                    throw new LLVMLinkerException("No main function found.");
                }
                result = main.execute().asInt();
            }
            return new ProcessResult(bitcodeFile.getName(), result, out.getStdErr(), out.getStdOut());
        }
    } else {
        String aotArgs = TestOptions.TEST_AOT_ARGS == null ? "" : TestOptions.TEST_AOT_ARGS + " ";
        String cmdline = TestOptions.TEST_AOT_IMAGE + " " + aotArgs + concatOptions(options) + bitcodeFile.getAbsolutePath() + " " + concatCommand(args);
        return executeNativeCommand(cmdline);
    }
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) Context(org.graalvm.polyglot.Context) Builder(org.graalvm.polyglot.Context.Builder) Value(org.graalvm.polyglot.Value) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)

Example 7 with LLVMLinkerException

use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.

the class NFIContextExtension method createWellKnownFunction.

private Object createWellKnownFunction(WellKnownFunction fn) {
    CompilerAsserts.neverPartOfCompilation();
    NativeLookupResult result = getNativeFunctionOrNull(fn.name);
    if (result != null) {
        CallTarget parsedSignature = env.parseInternal(fn.signatureSource);
        Object signature = parsedSignature.call();
        return SignatureLibrary.getUncached().bind(signature, result.getObject());
    }
    throw new LLVMLinkerException(String.format("External function %s cannot be found.", fn.name));
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)

Example 8 with LLVMLinkerException

use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.

the class ParserDriver method resolveRenamedSymbols.

protected void resolveRenamedSymbols(LLVMParserResult parserResult) {
    for (GlobalVariable external : parserResult.getExternalGlobals()) {
        String name = external.getName();
        if (name.startsWith(SULONG_RENAME_MARKER)) {
            registerRenamed(name, external, (scope, originalName, lib) -> createNewGlobal(scope, originalName, parserResult, external, lib, name));
        }
    }
    ListIterator<FunctionSymbol> it = parserResult.getExternalFunctions().listIterator();
    while (it.hasNext()) {
        FunctionSymbol external = it.next();
        String name = external.getName();
        if (name.startsWith(SULONG_RENAME_MARKER)) {
            registerRenamed(name, external, (scope, originalName, lib) -> createNewFunction(scope, originalName, parserResult, external, lib, name, it));
        } else if (CXXDemangler.isRenamedNamespaceSymbol(name)) {
            LLVMScope scope;
            ArrayList<String> namespaces = CXXDemangler.decodeNamespace(name);
            String lib = CXXDemangler.getAndRemoveLibraryName(namespaces);
            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 = CXXDemangler.encodeNamespace(namespaces);
            createNewFunction(scope, originalName, parserResult, external, lib, name, it);
        }
    }
}
Also used : GlobalVariable(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable) FunctionSymbol(com.oracle.truffle.llvm.parser.model.functions.FunctionSymbol) ArrayList(java.util.ArrayList) TruffleFile(com.oracle.truffle.api.TruffleFile) LLVMScope(com.oracle.truffle.llvm.runtime.LLVMScope) PlatformCapability(com.oracle.truffle.llvm.runtime.PlatformCapability) 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 9 with LLVMLinkerException

use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.

the class LLVMContext method initializeSymbol.

/**
 * This method is only intended to be used during initialization of a Sulong library.
 */
@TruffleBoundary
public void initializeSymbol(LLVMSymbol symbol, LLVMPointer value) {
    assert !symbol.isAlias();
    BitcodeID bitcodeID = symbol.getBitcodeIDUncached();
    int id = bitcodeID.getId();
    LLVMPointer[] symbols = symbolDynamicStorage[id];
    Assumption[] assumptions = symbolAssumptions[id];
    synchronized (symbols) {
        try {
            int index = symbol.getSymbolIndexUncached();
            if (symbols[index] != null && symbols[index].isSame(value)) {
                return;
            }
            symbols[index] = value;
            assumptions[index] = Truffle.getRuntime().createAssumption();
            if (symbol instanceof LLVMFunction) {
                ((LLVMFunction) symbol).setValue(value);
            }
        } catch (LLVMIllegalSymbolIndexException e) {
            throw new LLVMLinkerException("Writing symbol into symbol table is inconsistent.");
        }
    }
}
Also used : LLVMIllegalSymbolIndexException(com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException) 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) Assumption(com.oracle.truffle.api.Assumption) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 10 with LLVMLinkerException

use of com.oracle.truffle.llvm.runtime.except.LLVMLinkerException in project graal by oracle.

the class LLVMParser method defineAlias.

private void defineAlias(String aliasName, boolean isAliasExported, SymbolImpl value, DataLayout targetDataLayout) {
    if (value instanceof FunctionSymbol) {
        FunctionSymbol function = (FunctionSymbol) value;
        defineAlias(function.getName(), aliasName, isAliasExported);
    } else if (value instanceof GlobalVariable) {
        GlobalVariable global = (GlobalVariable) value;
        defineAlias(global.getName(), aliasName, isAliasExported);
    } else if (value instanceof GlobalAlias) {
        GlobalAlias target = (GlobalAlias) value;
        defineAlias(target, targetDataLayout);
        defineAlias(target.getName(), aliasName, isAliasExported);
    } else if (value instanceof CastConstant) {
        // TODO (chaeubl): this is not perfectly accurate as we are loosing the type cast
        CastConstant cast = (CastConstant) value;
        defineAlias(aliasName, isAliasExported, cast.getValue(), targetDataLayout);
    } else if (value instanceof GetElementPointerConstant) {
        GetElementPointerConstant elementPointerConstant = (GetElementPointerConstant) value;
        defineExpressionSymbol(aliasName, isAliasExported, elementPointerConstant, targetDataLayout);
    } else {
        throw new LLVMLinkerException("Unknown alias type: " + value.getClass());
    }
}
Also used : GlobalVariable(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable) FunctionSymbol(com.oracle.truffle.llvm.parser.model.functions.FunctionSymbol) GetElementPointerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.GetElementPointerConstant) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias) CastConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.CastConstant) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)

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