feature request: asm block outside of a function
gcc allows basic asm blocks outside of any function:
$ cat foo.c
asm("cli");
int main() { return 1; }
$ gcc foo.c
compcert, doesn't seem to support this:
$ ccomp -finline-asm foo.c
foo.c:1: syntax error.
Fatal error; compilation aborted.
1 error detected.
In CompCert, "asm" is a statement, like "return" or "if", so naturally it can only occur within a function body. This is consistent with ISO C99 J.5.10 ("The most common implementation is a statement of the form..."). I don't understand the purpose of a "top-level" asm statement like in the foo.c example. GCC just dumps a "cli" instruction outside of any function, where it will never be executed...
You're right, my example was not very good. Here's a better one:
#include <stdio.h>
__asm__( \
".section .gnu.warning." __STRING(gets) \
" ; .ascii \"" "gets() is unsafe." "\" ; .text");
int main(int argc, char **argv)
{
char str[50];
gets(str);
}
The above adds a warning anytime gets(3) is seen:
$ gcc foo.c
/tmp/ccVEAzyx.o: In function `main':
foo.c:(.text+0x26): warning: gets() is unsafe.
It can also be done outside of the compiler if needed:
$ ccomp -S foo.c
$ cat custom.s foo.s > foo.new.s
$ ccomp foo.new.s
foo.new.o(.text+0x14): In function `main':
: warning: gets() is unsafe
Perhaps we should close this one? It’s been a few years and as I point out it can be done outside of compcert? Leave the final decision to you all.