| 1 |
/* Copyright (C) 2017-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
This file is free software; you can redistribute it and/or modify it |
| 4 |
under the terms of the GNU General Public License as published by the |
| 5 |
Free Software Foundation; either version 3, or (at your option) any |
| 6 |
later version. |
| 7 |
|
| 8 |
This file is distributed in the hope that it will be useful, but |
| 9 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
General Public License for more details. |
| 12 |
|
| 13 |
Under Section 7 of GPL version 3, you are granted additional |
| 14 |
permissions described in the GCC Runtime Library Exception, version |
| 15 |
3.1, as published by the Free Software Foundation. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License and |
| 18 |
a copy of the GCC Runtime Library Exception along with this program; |
| 19 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 20 |
<http://www.gnu.org/licenses/>. */ |
| 21 |
|
| 22 |
typedef long long size_t; |
| 23 |
|
| 24 |
/* Provide an entry point symbol to silence a linker warning. */ |
| 25 |
void _start() {} |
| 26 |
|
| 27 |
|
| 28 |
#define PR119369_fixed 0 |
| 29 |
|
| 30 |
|
| 31 |
/* Host/device compatibility: '__cxa_finalize'. Dummy; if necessary, |
| 32 |
overridden via libgomp 'target-cxa-dso-dtor.c'. */ |
| 33 |
|
| 34 |
#if PR119369_fixed |
| 35 |
extern void __GCC_offload___cxa_finalize (void *) __attribute__((weak)); |
| 36 |
#else |
| 37 |
void __GCC_offload___cxa_finalize (void *) __attribute__((weak)); |
| 38 |
|
| 39 |
void __attribute__((weak)) |
| 40 |
__GCC_offload___cxa_finalize (void *dso_handle __attribute__((unused))) |
| 41 |
{ |
| 42 |
} |
| 43 |
#endif |
| 44 |
|
| 45 |
/* There are no DSOs; this is the main program. */ |
| 46 |
static void * const __dso_handle = 0; |
| 47 |
|
| 48 |
|
| 49 |
#ifdef USE_NEWLIB_INITFINI |
| 50 |
|
| 51 |
extern void __libc_init_array (void) __attribute__((weak)); |
| 52 |
extern void __libc_fini_array (void) __attribute__((weak)); |
| 53 |
|
| 54 |
__attribute__((amdgpu_hsa_kernel ())) |
| 55 |
void _init_array() |
| 56 |
{ |
| 57 |
__libc_init_array (); |
| 58 |
} |
| 59 |
|
| 60 |
__attribute__((amdgpu_hsa_kernel ())) |
| 61 |
void _fini_array() |
| 62 |
{ |
| 63 |
#if PR119369_fixed |
| 64 |
if (__GCC_offload___cxa_finalize) |
| 65 |
#endif |
| 66 |
__GCC_offload___cxa_finalize (__dso_handle); |
| 67 |
|
| 68 |
__libc_fini_array (); |
| 69 |
} |
| 70 |
|
| 71 |
#endif |
| 72 |
|
| 73 |
/* These magic symbols are provided by the linker. */ |
| 74 |
extern void (*__preinit_array_start []) (void) __attribute__((weak)); |
| 75 |
extern void (*__preinit_array_end []) (void) __attribute__((weak)); |
| 76 |
extern void (*__init_array_start []) (void) __attribute__((weak)); |
| 77 |
extern void (*__init_array_end []) (void) __attribute__((weak)); |
| 78 |
extern void (*__fini_array_start []) (void) __attribute__((weak)); |
| 79 |
extern void (*__fini_array_end []) (void) __attribute__((weak)); |
| 80 |
|
| 81 |
__attribute__((amdgpu_hsa_kernel ())) |
| 82 |
void _init_array() |
| 83 |
{ |
| 84 |
/* Iterate over all the init routines. */ |
| 85 |
size_t count; |
| 86 |
size_t i; |
| 87 |
|
| 88 |
count = __preinit_array_end - __preinit_array_start; |
| 89 |
for (i = 0; i < count; i++) |
| 90 |
__preinit_array_start[i] (); |
| 91 |
|
| 92 |
count = __init_array_end - __init_array_start; |
| 93 |
for (i = 0; i < count; i++) |
| 94 |
__init_array_start[i] (); |
| 95 |
} |
| 96 |
|
| 97 |
__attribute__((amdgpu_hsa_kernel ())) |
| 98 |
void _fini_array() |
| 99 |
{ |
| 100 |
#if PR119369_fixed |
| 101 |
if (__GCC_offload___cxa_finalize) |
| 102 |
#endif |
| 103 |
__GCC_offload___cxa_finalize (__dso_handle); |
| 104 |
|
| 105 |
size_t count; |
| 106 |
size_t i; |
| 107 |
|
| 108 |
count = __fini_array_end - __fini_array_start; |
| 109 |
for (i = count; i > 0; i--) |
| 110 |
__fini_array_start[i-1] (); |
| 111 |
} |