char *funcname;
if (sscanf (buf, "\t.8byte\t%ms\n", &funcname))
{
+ fputs (buf, out);
obstack_ptr_grow (&fns_os, funcname);
fn_count++;
continue;
out);
}
else if (sscanf (buf, " .section .gnu.offload_funcs%c", &dummy) > 0)
- state = IN_FUNCS;
+ {
+ state = IN_FUNCS;
+ /* Likewise for .gnu.offload_vars; used for reverse offload. */
+ fputs (buf, out);
+ fputs ("\t.global .offload_func_table\n"
+ "\t.type .offload_func_table, @object\n"
+ ".offload_func_table:\n",
+ out);
+ }
else if (sscanf (buf, " .amdgpu_metadata%c", &dummy) > 0)
{
state = IN_METADATA;
int
GOMP_OFFLOAD_load_image (int ord, unsigned version, const void *target_data,
struct addr_pair **target_table,
- uint64_t **rev_fn_table __attribute__((unused)))
+ uint64_t **rev_fn_table)
{
if (GOMP_VERSION_DEV (version) != GOMP_VERSION_GCN)
{
if (module->fini_array_func)
kernel_count--;
+ if (rev_fn_table != NULL && kernel_count == 0)
+ *rev_fn_table = NULL;
+ else if (rev_fn_table != NULL)
+ {
+ hsa_status_t status;
+ hsa_executable_symbol_t var_symbol;
+ status = hsa_fns.hsa_executable_get_symbol_fn (agent->executable, NULL,
+ ".offload_func_table",
+ agent->id, 0, &var_symbol);
+ if (status != HSA_STATUS_SUCCESS)
+ hsa_fatal ("Could not find symbol for variable in the code object",
+ status);
+ uint64_t fn_table_addr;
+ status = hsa_fns.hsa_executable_symbol_get_info_fn
+ (var_symbol, HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_ADDRESS,
+ &fn_table_addr);
+ if (status != HSA_STATUS_SUCCESS)
+ hsa_fatal ("Could not extract a variable from its symbol", status);
+ *rev_fn_table = GOMP_PLUGIN_malloc (kernel_count * sizeof (uint64_t));
+ GOMP_OFFLOAD_dev2host (agent->device_id, *rev_fn_table,
+ (void*) fn_table_addr,
+ kernel_count * sizeof (uint64_t));
+ }
+
return kernel_count + var_count + other_count;
}