Debian Codegraph @

libgomp/config/accel/target-cxa-dso-dtor.c

raw
1 /* Host/device compatibility: Itanium C++ ABI, DSO Object Destruction API
2
3 Copyright (C) 2025 Free Software Foundation, Inc.
4
5 This file is part of the GNU Offloading and Multi Processing Library
6 (libgomp).
7
8 Libgomp is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 more details.
17
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
21
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
26
27 #include "libgomp.h"
28
29 extern void __cxa_finalize (void *);
30
31 /* See <https://itanium-cxx-abi.github.io/cxx-abi/abi.html#dso-dtor>.
32
33 Even if the device is '!DEFAULT_USE_CXA_ATEXIT', we may see '__cxa_atexit'
34 calls, referencing '__dso_handle', via a 'DEFAULT_USE_CXA_ATEXIT' host.
35 '__cxa_atexit' is provided by newlib, but use of '__dso_handle' for nvptx
36 results in 'ld' error:
37
38 unresolved symbol __dso_handle
39 collect2: error: ld returned 1 exit status
40 nvptx mkoffload: fatal error: [...]/x86_64-pc-linux-gnu-accel-nvptx-none-gcc returned 1 exit status
41
42 ..., or for GCN get an implicit definition (running with
43 '--trace-symbol=__dso_handle'):
44
45 ./a.xamdgcn-amdhsa.mkoffload.hsaco-a.xamdgcn-amdhsa.mkoffload.2.o: reference to __dso_handle
46 <internal>: definition of __dso_handle
47
48 ..., which might be fine, but let's just make it explicit. */
49
50 /* There are no DSOs; this is the main program. */
51 attribute_hidden void * const __dso_handle = 0;
52
53 /* If this file gets linked in, that means that '__dso_handle' has been
54 referenced (for '__cxa_atexit'), and in that case, we also have to run
55 '__cxa_finalize'. Make that happen by overriding the weak libgcc dummy
56 function '__GCC_offload___cxa_finalize'. */
57
58 void
59 __GCC_offload___cxa_finalize (void *dso_handle)
60 {
61 __cxa_finalize (dso_handle);
62 }