3

I want to analyze a file from a large project to create a Program Dependence Graph using Frama-C, but keep getting odd errors such as:

/usr/include/bits/fcntl-linux.h:305:[kernel] user error: Length of array is zero. This extension is unsupported

If I try to use the libc implementation provided by frama-c, compilation fails due to missing headers such as sys/file.h.

I am trying to analyze files from the Lynx project, specifically the file in src/WWW/Library/Implementation/HTTP.c, using GCC version 4.8.1

What I really need is to be able to generate a PDG for this source file (which of course has various dependencies) but I think if I could get even a somewhat incomplete graph by skipping over undefined functions, that would be a great first step.

tkanzakic
  • 5,499
  • 16
  • 34
  • 41
Squatch
  • 33
  • 4
  • 1
    Perhaps you need to tell frama-c the location of the headers. This is done by setting the environment variable like this: `export CPP='gcc -C -E -I/path/to/headers -I.'` – Cristiano Sousa Jun 17 '13 at 01:42
  • @CristianoSousa True (in addition, GCC option `-nostdinc` tells GCC not to use the system's headers at all), but it seems the OP already knows this. It is true that some widely used headers are not provided in Frama-C: the Frama-C provided headers are the bare minimum C-mandated ones (and perhaps some POSIX ones). – Pascal Cuoq Jun 17 '13 at 07:30

1 Answers1

4

You need to provide your own "file.h" file in a directory "sys" placed anywhere in the path GCC searches when pre-processing for Frama-C.

For reference, here is the implementation of sys/file.h on another system. You may also be interested in this other StackOverflow question about sys/file.h.

For Frama-C's value analysis, assigns clauses alongside the prototypes go a long way:

/*@ assigns *f \from ui, s, *fo; */
void finit(struct file *f, u_int ui, short s, void *p, struct fileops *fo);

Note that I have no idea what function finit() does and whether the above is a correct assigns clause for it. In fact, this is the whole point: neither does Frama-C out of the box, and since this lowish-level, lessish-portable system call is used in the code you wish to analyze, someone will have to know. I am afraid it is going to have to be you. On the plus side, you only need to provide the types, macros and function prototypes that the code you wish to analyze uses.

Community
  • 1
  • 1
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • Hi, I have a similar problem as the OP: `/usr/include/x86_64-linux-gnu/bits/fcntl-linux.h:316:[kernel] user error: Length of array is zero. This extension is unsupported`. I downloaded a copy of "file.h" and placed it a directory called "sys" in one of the include paths indicated like this `export CPP='gcc -C -E -I/path/to/headers -I.'` to Frama-C. However, I still get the same error. Did I misunderstand your answer? Was I supposed to do something else to solve this problem? Thanks. – Benny Nov 17 '14 at 13:57
  • 1
    @Benny Yes, I think you are talking of another problem, “how do I make Frama-C take into account my headers instead of the system's?”. I cannot blame you for trying to read what's available before asking your own question, but in this case, it is a different question that should have been asked in a different “thread” rather than as a comment on the existing one. The answer is “use `-nostdinc` for pre-processing. As long as you get error messages in /usr/include/x86_64-linux-gnu/…, you are still using the wrong headers, so keep trying not to. – Pascal Cuoq Nov 17 '14 at 14:15
  • 1
    @Benny Your question, had you asked it, would have been a duplicate of http://stackoverflow.com/q/23162014/139746 – Pascal Cuoq Nov 17 '14 at 14:16