https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97106
--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
This:
...
$ cat alias.c
void __f ()
{
__builtin_printf ("hello\n");
}
void f () __attribute__ ((alias ("__f")));
int
main (void)
{
f ();
return 0;
}
...
works fine at -O0 and -O1:
...
$ ./gcc.sh -O0 ./alias.c
$ ./install/bin/nvptx-none-run a.out
hello
$ ./gcc.sh -O1 ./alias.c
$ ./install/bin/nvptx-none-run a.out
hello
...
but at -O2 we have:
...
$ ./gcc.sh -O2 ./alias.c
$ ./install/bin/nvptx-none-run a.out
fatal : Internal error: reference to deleted section
nvptx-run: cuLinkComplete failed: unknown error (CUDA_ERROR_UNKNOWN, 999)
...
This seems to be due to f/__f being inlined into main, after which we have an
alias declaration which is unused:
...
.visible .func f;
.alias f,__f;
...
Removing these two lines make the executable run fine again.
Note: same thing when using nvptx-none-run -O0.
Fixed by:
...
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index ab1f62359d4b..3e51bf15776c 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -77,6 +77,7 @@
#include "opts.h"
#include "tree-pretty-print.h"
#include "rtl-iter.h"
+#include "cgraph.h"
/* This file should be included last. */
#include "target-def.h"
@@ -7396,6 +7397,10 @@ nvptx_mem_local_p (rtx mem)
void
nvptx_asm_output_def_from_decls (FILE *stream, tree name, tree value)
{
+ if (!cgraph_node::get (name)->referred_to_p ())
+ /* Prevent "Internal error: reference to deleted section". */
+ return;
+
std::stringstream s;
write_fn_proto (s, false, get_fnname_from_decl (name), name);
fputs (s.str().c_str(), stream);
...