Exemplo n.º 1
0
extern "C" bool __offload_myoProcessTables(
    const void* image,
    MYOInitTableList::Node *init_table,
    MYOVarTableList::Node  *shared_table,
    MYOVarTableList::Node  *shared_vtable,
    MYOFuncTableList::Node *fptr_table
)
{
    OFFLOAD_DEBUG_TRACE(3, "%s\n", __func__);

    // Collect the tables in this .dll/.so
    __offload_myoRegisterTables1(
        init_table, shared_table, shared_vtable, fptr_table);

    // Now check what type of module we are dealing with
    if (__offload_target_image_is_executable(image)) {
        OFFLOAD_DEBUG_TRACE(2, "Main encountered\n");
        OFFLOAD_DEBUG_TRACE(2, "MYO initialization not deferred\n");
        // MYO tables across dlls have been collected
        // Now init MYO and process the tables
        __offload_myoProcessDeferredTables();
        // Return true to indicate that atexit needs to be calld by ofldbegin
        return true;
    } else {
        // This is a shared library, either auto-loaded or dynamically loaded
        // If __target_exe is set, then main has started running
        if (__target_exe != 0) {
            // Main is running: this is a dynamic load of a shared library
            // Finish processing the tables in this library
            OFFLOAD_DEBUG_TRACE(2,
                "Dynamically loaded shared library encountered\n");
            OFFLOAD_DEBUG_TRACE(2,
                "MYO initialization not deferred\n");
            __offload_myoProcessDeferredTables();
        } else {
            // Main is not running: this is an auto-loaded shared library
            // Tables have been collected, nothing else to do
            OFFLOAD_DEBUG_TRACE(2,
                "Auto-loaded shared library encountered\n");
            OFFLOAD_DEBUG_TRACE(2, "Deferring initialization of MYO\n");
        }
        return false;
    }
}
Exemplo n.º 2
0
static void offload_fini_so()
{
    // Offload and MYO tables need to be removed from list
    // to prevent invalid accesses after dlclose
    // Remove offload tables
    __offload_unregister_tables(&__offload_entry_node,
                                &__offload_func_node,
                                &__offload_var_node);
#if HOST_LIBRARY
   if(!__offload_target_image_is_executable(&__offload_target_image)) {
      __offload_unregister_image(&__offload_target_image);
   }
#endif
#ifdef MYO_SUPPORT
#if HOST_LIBRARY
    // Remove MYO tables
    __offload_myoRemoveTables(
        &__offload_myo_init_table_node,
        &__offload_myo_shared_var_node,
        &__offload_myo_shared_vtable_node,
        &__offload_myo_fptr_table_node);
#endif // HOST_LIBRARY
#endif // MYO_SUPPORT
}