Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: asm block outside of a function #8

Open
didickman opened this issue Dec 28, 2014 · 3 comments
Open

feature request: asm block outside of a function #8

didickman opened this issue Dec 28, 2014 · 3 comments

Comments

@didickman
Copy link
Contributor

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.
@xavierleroy
Copy link
Contributor

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...

@didickman
Copy link
Contributor Author

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

@didickman
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants