aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorThomas Schwinge <tschwinge@baylibre.com>2024-05-28 23:20:29 +0200
committerThomas Schwinge <tschwinge@baylibre.com>2024-05-31 15:02:01 +0200
commitd9c90c82d900fdae95df4499bf5f0a4ecb903b53 (patch)
treed1e4dabb306a38108629d53021fd6b41e5934f93 /gcc
parent65dbe0ab7cdaf2aa84b09a74e594f0faacf1945c (diff)
downloadgcc-d9c90c82d900fdae95df4499bf5f0a4ecb903b53.zip
gcc-d9c90c82d900fdae95df4499bf5f0a4ecb903b53.tar.gz
gcc-d9c90c82d900fdae95df4499bf5f0a4ecb903b53.tar.bz2
nvptx target: Global constructor, destructor support, via nvptx-tools 'ld'
The function attributes 'constructor', 'destructor', and 'init_priority' now work, as do the C++ features making use of this. Test cases with effective target 'global_constructor' and 'init_priority' now generally work, and 'check-gcc-c++' test results greatly improve; no more "sorry, unimplemented: global constructors not supported on this target". For proper execution test results, this depends on <https://github.com/SourceryTools/nvptx-tools/commit/96f8fc59a757767b9e98157d95c21e9fef22a93b> "ld: Global constructor/destructor support". gcc/ * config/nvptx/nvptx.h: Configure global constructor, destructor support. gcc/testsuite/ * gcc.dg/no_profile_instrument_function-attr-1.c: GCC/nvptx is 'NO_DOT_IN_LABEL' but not 'NO_DOLLAR_IN_LABEL', so '$' may apper in identifiers. * lib/target-supports.exp (check_effective_target_global_constructor): Enable for nvptx. libgcc/ * config/nvptx/crt0.c (__gbl_ctors): New weak function. (__main): Invoke it. * config/nvptx/gbl-ctors.c: New. * config/nvptx/t-nvptx: Configure global constructor, destructor support.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/nvptx/nvptx.h14
-rw-r--r--gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c2
-rw-r--r--gcc/testsuite/lib/target-supports.exp3
3 files changed, 15 insertions, 4 deletions
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index e282aad..74f4a68 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -356,7 +356,19 @@ struct GTY(()) machine_function
#define MOVE_MAX 8
#define MOVE_RATIO(SPEED) 4
#define FUNCTION_MODE QImode
-#define HAS_INIT_SECTION 1
+
+/* Implement global constructor, destructor support in a conceptually simpler
+ way than using 'collect2' (the program): implement the respective
+ functionality in the nvptx-tools 'ld'. This however still requires the
+ compiler-side effects corresponding to 'USE_COLLECT2': the global
+ constructor, destructor support functions need to have external linkage, and
+ therefore names that are "unique across the whole link". Use
+ '!targetm.have_ctors_dtors' to achieve this (..., and thus don't need to
+ provide 'targetm.asm_out.constructor', 'targetm.asm_out.destructor'). */
+#define TARGET_HAVE_CTORS_DTORS false
+
+/* See 'libgcc/config/nvptx/crt0.c' for wrapping of 'main'. */
+#define HAS_INIT_SECTION
/* The C++ front end insists to link against libstdc++ -- which we don't build.
Tell it to instead link against the innocuous libgcc. */
diff --git a/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
index 909f8a6..5b4101c 100644
--- a/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
+++ b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
@@ -18,7 +18,7 @@ int main ()
return foo ();
}
-/* { dg-final { scan-tree-dump-times "__gcov0\[._\]main.* = PROF_edge_counter" 1 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "__gcov0\[$._\]main.* = PROF_edge_counter" 1 "optimized"} } */
/* { dg-final { scan-tree-dump-times "__gcov_indirect_call_profiler_v" 1 "optimized" } } */
/* { dg-final { scan-tree-dump-times "__gcov_time_profiler_counter = " 1 "optimized" } } */
/* { dg-final { scan-tree-dump-times "__gcov_init" 1 "optimized" } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index f0f6da5..a3992fa 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -942,8 +942,7 @@ proc check_effective_target_nonlocal_goto {} {
# Return 1 if global constructors are supported, 0 otherwise.
proc check_effective_target_global_constructor {} {
- if { [istarget nvptx-*-*]
- || [istarget bpf-*-*] } {
+ if { [istarget bpf-*-*] } {
return 0
}
return 1