https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122458
Bug ID: 122458
Summary: static function is removed even when referred from
extended toplevel asm
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ubizjak at gmail dot com
Target Milestone: ---
Consider the following testcase:
--cut here--
static int foo (void) { return 0; };
asm ("call %c0" :: "i" (foo));
--cut here--
gcc -O2:
.file "toplev.c"
.text
#APP
call foo
.ident "GCC: (GNU) 15.2.1 20251022 (Red Hat 15.2.1-3)"
.section .note.GNU-stack,"",@progbits
The foo () is gone although it is referred in the toplevel asm.
Using __attribute__((used)) solves this issue, but the compiler should be able
to figure this out by itself.