How to get the preprocessor output as part of the compilation process?
Hi, I know that with gcc -E you can get the output of the preprocessor, but what I have to do to get that output for every source code file in the Linux Lernel as part of the compilation process? thanks frank a.
On Sun, 08 Dec 2019 14:05:06 -0500, "Frank A. Cancio Bello" said:
I know that with gcc -E you can get the output of the preprocessor, but what I have to do to get that output for every source code file in the Linux Lernel as part of the compilation process?
What problem are you trying to solve by doing that? There's probably a better and more efficient approach....
Hi, Frank. The universal approach that always works in this and many similar cases is just to replace the instrumented binary by your interception shell script. E.g. rename gcc to gcc.hide (generally, moving into another location may not work) and setup 'gcc' script that does what you want: replaces `-c' with the `-E', replaces `-o' argument, etc ..., calls gcc.hide to preprocess source then calls gcc.hide with original non-modified command line. This is cumbersome process, you can break some things, there may be a handful try and fix iterations, but the advantage is that you have a full control on what is happening, and you do not need support from the tool, build process and product maintainers. The interception like this is used by static code analysis tools. Regards, Konstantin Frank A. Cancio Bello, 08 Dec 2019 MSK:
Hi, I know that with gcc -E you can get the output of the preprocessor, but what I have to do to get that output for every source code file in the Linux Lernel as part of the compilation process?
On Mon, 09 Dec 2019 13:10:11 +0300, Konstantin Andreev said:
The universal approach that always works in this and many similar cases is just to replace the instrumented binary by your interception shell script.
E.g. rename gcc to gcc.hide (generally, moving into another location may not work) and setup 'gcc' script that does what you want: replaces `-c' with the `-E', replaces `-o' argument, etc ..., calls gcc.hide to preprocess source then calls gcc.hide with original non-modified command line.
This is cumbersome process, you can break some things,
And in fact, what you may want to do is have your script invoke gcc *twice*, once with -E, and then a second time with -c, because otherwise the build will die the first time it tries to link together two or more non-existent .o files. Using 'make -k' *might* also work, but will leave the build log output littered with a *lot* of error messages. Or explain why you're doing this - there may be a simpler way to achieve your goal. For instance, if you're trying to build a cross-reference of what .c files include what .h directly or indirectly, there's already specialized tools for doing that sort of thing, such as 'cxref'.
Hi, Valdis. It wasn't me who asked the question, so I can't comment on the Frank's goal.
And in fact, what you may want to do is have your script invoke gcc twice, once with -E, and then a second time with -c, ...
Certainly. That is exactly what I have proposed. Nothing wrong with this. Regards, Konstantin Valdis Klētnieks, 10 Dec 2019 06:17 MSK:
And in fact, what you may want to do is have your script invoke gcc twice, once with -E, and then a second time with -c, because otherwise the build will die the first time it tries to link together two or more non-existent .o files.
Using 'make -k' might also work, but will leave the build log output littered with a lot of error messages.
Or explain why you're doing this - there may be a simpler way to achieve your goal. For instance, if you're trying to build a cross-reference of what .c files include what .h directly or indirectly, there's already specialized tools for doing that sort of thing, such as 'cxref'.
Konstantin Andreev, 09 Dec 2019 13:10 MSK:
The universal approach that always works in this and many similar cases is just to replace the instrumented binary by your interception shell script.
E.g. rename gcc to gcc.hide (generally, moving into another location may not work) and setup 'gcc' script that does what you want: replaces `-c' with the `-E', replaces `-o' argument, etc ..., calls gcc.hide to preprocess source then calls gcc.hide with original non-modified command line.
This is cumbersome process, you can break some things, ...
On Sun, Dec 8, 2019 at 2:06 PM Frank A. Cancio Bello < frank@generalsoftwareinc.com> wrote: Hi, I know that with gcc -E you can get the output of the preprocessor, but what I have to do to get that output for every source code file in the Linux Lernel as part of the compilation process?
thanks frank a.
Hi Frank, There are two options you can use with gcc to get the processor output as part of the kernel compilation process. -save-temps -save-temps=<arg> 1 - Open the top level Makefile in your favorite text editor. 2 - Search for KBUILD_CFLAGS My Makefile which is at /home/aruna/linux-5.4.2/Makefile shows me at line 458 KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs 3 - Now plugin -save-temps=<arg> but replace <arg> with obj like shown below: KBUILD_CFLAGS := -Wall -save-temps=obj -Wundef -Werror=strict-prototypes -Wno-trigraphs 4 - Save the Makefile. 5 - Run make and we are done ! Each directory will have the preprocessor output in *.i and *.s files. Good luck - Aruna ( I keep asking myself 'why' are you doing this though ? :)
participants (4)
-
Aruna Hewapathirane -
Frank A. Cancio Bello -
Konstantin Andreev -
Valdis Klētnieks