Search in sources :

Example 11 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer 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)

Example 12 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.

the class InitializeSymbolsNode method allocFunctions.

private void allocFunctions(LLVMContext context) {
    for (int i = 0; i < allocFuncs.length; i++) {
        AllocSymbolNode allocSymbol = allocFuncs[i];
        LLVMPointer pointer = allocSymbol.allocate(context);
        context.initializeSymbol(functions[i], pointer);
        List<LLVMSymbol> list = new ArrayList<>(1);
        list.add(allocSymbol.symbol);
        context.registerSymbolReverseMap(list, pointer);
    }
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) ArrayList(java.util.ArrayList) LLVMSymbol(com.oracle.truffle.llvm.runtime.LLVMSymbol)

Example 13 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.

the class InitializeSymbolsNode method execute.

public LLVMPointer execute(LLVMContext ctx) {
    if (LibraryLocator.loggingEnabled()) {
        LibraryLocator.traceStaticInits(ctx, "symbol initializers", moduleName);
    }
    LLVMPointer roBase = allocOrNull(allocRoSection);
    LLVMPointer rwBase = allocOrNull(allocRwSection);
    allocGlobals(ctx, roBase, rwBase);
    allocFunctions(ctx);
    if (allocRoSection != null) {
        ctx.registerReadOnlyGlobals(bitcodeID.getId(), roBase, nodeFactory);
    }
    if (allocRwSection != null) {
        ctx.registerGlobals(rwBase, nodeFactory);
    }
    // needed later to apply memory protection after initialization
    return roBase;
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)

Example 14 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.

the class InitializeExternalNode method execute.

/*
     * (PLi): Need to be careful of native functions/globals that are not in the nfi context (i.e.
     * __xstat). Ideally they will be added to the symbol table as unresolved/undefined
     * functions/globals.
     */
public void execute(LLVMContext context, LLVMScopeChain localScope, LLVMDLOpen.RTLDFlags rtldFlags) {
    LLVMScopeChain globalScope = context.getGlobalScopeChain();
    LLVMIntrinsicProvider intrinsicProvider = getLanguage().getCapability(LLVMIntrinsicProvider.class);
    NativeContextExtension nativeContextExtension = getNativeContextExtension(context);
    for (int i = 0; i < globals.length; i++) {
        LLVMGlobal global = globals[i];
        LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, global);
        if (pointer == null) {
            continue;
        }
        context.initializeSymbol(globals[i], pointer);
    }
    for (int i = 0; i < functions.length; i++) {
        LLVMFunction function = functions[i];
        LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, function);
        if (pointer == null) {
            continue;
        }
        context.initializeSymbol(functions[i], pointer);
    }
}
Also used : LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVMScopeChain(com.oracle.truffle.llvm.runtime.LLVMScopeChain) LLVMGlobal(com.oracle.truffle.llvm.runtime.global.LLVMGlobal) LLVMIntrinsicProvider(com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider) NativeContextExtension(com.oracle.truffle.llvm.runtime.NativeContextExtension)

Example 15 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.

the class AllocExternalSymbolNode method execute.

public LLVMPointer execute(LLVMScopeChain localScope, LLVMScopeChain globalScope, LLVMIntrinsicProvider intrinsicProvider, NativeContextExtension nativeContextExtension, LLVMContext context, LLVMDLOpen.RTLDFlags rtldFlags, LLVMSymbol symbol) {
    LLVMPointer pointerFromLocal = lookupFromScope(localScope, symbol, context);
    // The default case for active default flag is to search the local scope first.
    if (pointerFromLocal != null && isDefaultFlagActive(rtldFlags)) {
        return pointerFromLocal;
    }
    LLVMPointer pointerFromGlobal = lookupFromScope(globalScope, symbol, context);
    // the default flag, global scope takes priority if the default flag is not active.)
    if (pointerFromGlobal != null) {
        return pointerFromGlobal;
    }
    // flag is not active).
    if (pointerFromLocal != null) {
        return pointerFromLocal;
    }
    // Allocating a native global symbol to the symbol table as provided by the nfi context.
    if (symbol.isGlobalVariable()) {
        if (symbol.isExternalWeak()) {
            return LLVMNativePointer.createNull();
        } else if (nativeContextExtension != null) {
            NativeContextExtension.NativePointerIntoLibrary pointer = getNativePointer(nativeContextExtension, symbol);
            if (pointer != null) {
                return LLVMNativePointer.create(pointer.getAddress());
            }
            return null;
        }
    }
    // native function and intrinsic function.
    if (symbol.isFunction()) {
        if (symbol.isExternalWeak()) {
            return LLVMNativePointer.createNull();
        } else if (intrinsicProvider != null && intrinsicProvider.isIntrinsified(symbol.getName())) {
            LLVMFunctionCode functionCode = new LLVMFunctionCode(symbol.asFunction());
            LLVMFunctionDescriptor functionDescriptor = context.createFunctionDescriptor(symbol.asFunction(), functionCode);
            functionDescriptor.getFunctionCode().define(intrinsicProvider, nodeFactory);
            return LLVMManagedPointer.create(functionDescriptor);
        } else if (intrinsicProvider != null && !intrinsicProvider.isIntrinsified(symbol.getName()) && nativeContextExtension != null) {
            /*
                 * Currently native functions/globals that are not in the nfi context are not
                 * written into the symbol table. For function, another lookup will happen when
                 * something tries to call the function. (see {@link
                 * LLVMDispatchNode#doCachedNative}) The function will be taken from the filescope
                 * directly. Ideally the filescope and symbol table is in sync, and any lazy look up
                 * will resolve from the function code in the symbol table.
                 */
            NativeLookupResult nativeFunction = getNativeFunction(nativeContextExtension, symbol);
            if (nativeFunction != null) {
                LLVMFunctionDescriptor functionDescriptor = context.createFunctionDescriptor(symbol.asFunction(), new LLVMFunctionCode(symbol.asFunction()));
                functionDescriptor.getFunctionCode().define(new LLVMFunctionCode.NativeFunction(nativeFunction.getObject()));
                symbol.asFunction().setNFISymbol(nativeFunction.getObject());
                return LLVMManagedPointer.create(functionDescriptor);
            }
            return null;
        }
    }
    /*
         * Fallback for when the same symbol is being overwritten. There exists code where the
         * symbol is not there.
         */
    return null;
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVMFunctionCode(com.oracle.truffle.llvm.runtime.LLVMFunctionCode) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) NativePointerIntoLibrary(com.oracle.truffle.llvm.runtime.NativeContextExtension.NativePointerIntoLibrary) NativeLookupResult(com.oracle.truffle.llvm.runtime.NativeContextExtension.NativeLookupResult)

Aggregations

LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)33 Specialization (com.oracle.truffle.api.dsl.Specialization)12 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)4 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)3 ExportMessage (com.oracle.truffle.api.library.ExportMessage)3 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)3 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)3 BitcodeID (com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID)3 LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)3 LLVMIllegalSymbolIndexException (com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException)3 LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)3 Assumption (com.oracle.truffle.api.Assumption)2 LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)2 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)2 LLVMScopeChain (com.oracle.truffle.llvm.runtime.LLVMScopeChain)2 LLVM80BitFloat (com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat)2 LLVMForeignGetSuperElemPtrNode (com.oracle.truffle.llvm.runtime.interop.export.LLVMForeignGetSuperElemPtrNode)2 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)2 LLVMManagedPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer)2