0

I'am trying to generate csmith programs without any printf inside.

I tried to apply -E -DNO_PRINTF to a generated program but it seem as GCC doesn't have an argument to link files and then apply the preprocessing pass.

So how to tell csmith to avoid printf in its generated programs?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jcnm
  • 83
  • 1
  • 6
  • "GCC doesn't have an argument to link files and then apply the preprocessing pass." No, of course it doesn't. Preprocessing happens (logically) before compilation, and linking happens after. If you're ready to link, then the opportunity to preprocess is long past. – John Bollinger Sep 09 '15 at 19:03
  • If `csmith` generates source code which contains conditional compilation directives hinging on whether the symbol `NO_PRINTF` is defined, then the time to define that symbol would normally be when you compile. Alternatively, if you preprocess `csmith`-generated source with `gcc -E -DNO_PRINTF`, then the next step is to *compile* the pre-processed output. – John Bollinger Sep 09 '15 at 19:07
  • Thank, I guess that I got the compilation steps. But, I was looking for a magic trick to link if possible and then apply the preprocessing step (or a mixing). As I said, "gcc -E -DNO_PRINTF" yields something which still contains printf despite the -DNO_PRINTF argument. – jcnm Sep 10 '15 at 09:31
  • there is no magic trick. For each contributing source file, you preprocess, THEN compile. Once all the sources are compiled THEN you link. Sometimes some or all of that can be wrapped up in only a small number of explicit commands, but the logical progression must always be consistent with that order. – John Bollinger Sep 10 '15 at 13:35
  • As for the `NO_PRINTF` symbol, I see it in a few places in the csmith 2.2.0 sources, but I find no documentation of it whatever. I certainly don't see the basis for your apparent belief that defining that symbol during compilation of generated sources should cause the generated program to avoid ever calling `printf()`. – John Bollinger Sep 10 '15 at 13:39
  • My main problem come from csmith_minimal.h. There are a lot of NO_PRINTF usage here. This function _platform_main_end (uint64_t x, int flag) { //... #ifdef NO_PRINTF //putchar #else // printf #endif } #endif }_ Event with -DNO_PRINTF activated, the generated source code is _platform_main_end (uint64_t x, int flag) { if (!flag) { printf ("checksum = %llx\n", x); } }_ Anyways, thanks for your help with those information, I am trying alternatives solutions. Beside, why my question is valuated -1 ? – jcnm Sep 14 '15 at 08:27
  • Have you tried the option `--no-hash-value-printf`? Check the not-so-commonly-used flags by running `csmith` with the `-hh` option – Morten Jensen Sep 15 '15 at 09:47

0 Answers0