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);
}
}
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations