hppa: Always enable PIE on 64-bit target
[official-gcc.git] / libgcc / c++-minimal / guard.c
blob02c67bc2de926b8ff88218371a0e2e4aa850d1fa
1 /* 'libstdc++-v3/libsupc++/guard.cc' for offload devices, until we have
2 libstdc++-v3/libsupc++ proper.
4 Copyright (C) 2002-2024 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
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.
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/>. */
27 #if defined __AMDGCN__
28 #elif defined __nvptx__
29 #else
30 # error not ported
31 #endif
33 #include "../../libstdc++-v3/config/cpu/generic/cxxabi_tweaks.h"
35 /* Copy'n'paste/edit from 'libstdc++-v3/libsupc++/cxxabi.h'. */
37 int
38 __cxa_guard_acquire(__guard*);
40 void
41 __cxa_guard_release(__guard*);
43 void
44 __cxa_guard_abort(__guard*);
46 /* Copy'n'paste/edit from 'libstdc++-v3/libsupc++/guard.cc'. */
48 #undef _GLIBCXX_GUARD_TEST_AND_ACQUIRE
49 #undef _GLIBCXX_GUARD_SET_AND_RELEASE
50 #define _GLIBCXX_GUARD_SET_AND_RELEASE(G) _GLIBCXX_GUARD_SET (G)
52 static inline int
53 init_in_progress_flag(__guard* g)
54 { return ((char *)g)[1]; }
56 static inline void
57 set_init_in_progress_flag(__guard* g, int v)
58 { ((char *)g)[1] = v; }
60 static inline void
61 throw_recursive_init_exception(void)
63 // Use __builtin_trap so we don't require abort().
64 __builtin_trap();
67 // acquire() is a helper function used to acquire guard if thread support is
68 // not compiled in or is compiled in but not enabled at run-time.
69 static int
70 acquire(__guard *g)
72 // Quit if the object is already initialized.
73 if (_GLIBCXX_GUARD_TEST(g))
74 return 0;
76 if (init_in_progress_flag(g))
77 throw_recursive_init_exception();
79 set_init_in_progress_flag(g, 1);
80 return 1;
83 int __cxa_guard_acquire (__guard *g)
85 return acquire (g);
88 void __cxa_guard_abort (__guard *g)
90 set_init_in_progress_flag(g, 0);
93 void __cxa_guard_release (__guard *g)
95 set_init_in_progress_flag(g, 0);
96 _GLIBCXX_GUARD_SET_AND_RELEASE (g);