Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
* How to get the preprocessor output as part of the compilation process?
@ 2019-12-08 19:05 Frank A. Cancio Bello
  2019-12-08 21:53 ` Valdis Klētnieks
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Frank A. Cancio Bello @ 2019-12-08 19:05 UTC (permalink / raw)
  To: kernelnewbies

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.

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get the preprocessor output as part of the compilation process?
  2019-12-08 19:05 How to get the preprocessor output as part of the compilation process? Frank A. Cancio Bello
@ 2019-12-08 21:53 ` Valdis Klētnieks
  2019-12-09 10:10 ` Konstantin Andreev
  2019-12-12  3:14 ` Aruna Hewapathirane
  2 siblings, 0 replies; 6+ messages in thread
From: Valdis Klētnieks @ 2019-12-08 21:53 UTC (permalink / raw)
  To: Frank A. Cancio Bello; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 377 bytes --]

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

[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get the preprocessor output as part of the compilation process?
  2019-12-08 19:05 How to get the preprocessor output as part of the compilation process? Frank A. Cancio Bello
  2019-12-08 21:53 ` Valdis Klētnieks
@ 2019-12-09 10:10 ` Konstantin Andreev
  2019-12-10  3:17   ` Valdis Klētnieks
  2019-12-12  3:14 ` Aruna Hewapathirane
  2 siblings, 1 reply; 6+ messages in thread
From: Konstantin Andreev @ 2019-12-09 10:10 UTC (permalink / raw)
  To: Frank A. Cancio Bello, kernelnewbies

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?

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get the preprocessor output as part of the compilation process?
  2019-12-09 10:10 ` Konstantin Andreev
@ 2019-12-10  3:17   ` Valdis Klētnieks
  2019-12-10 13:35     ` Konstantin Andreev
  0 siblings, 1 reply; 6+ messages in thread
From: Valdis Klētnieks @ 2019-12-10  3:17 UTC (permalink / raw)
  To: Konstantin Andreev; +Cc: Frank A. Cancio Bello, kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 1203 bytes --]

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

[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get the preprocessor output as part of the compilation process?
  2019-12-10  3:17   ` Valdis Klētnieks
@ 2019-12-10 13:35     ` Konstantin Andreev
  0 siblings, 0 replies; 6+ messages in thread
From: Konstantin Andreev @ 2019-12-10 13:35 UTC (permalink / raw)
  Cc: kernelnewbies

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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get the preprocessor output as part of the compilation process?
  2019-12-08 19:05 How to get the preprocessor output as part of the compilation process? Frank A. Cancio Bello
  2019-12-08 21:53 ` Valdis Klētnieks
  2019-12-09 10:10 ` Konstantin Andreev
@ 2019-12-12  3:14 ` Aruna Hewapathirane
  2 siblings, 0 replies; 6+ messages in thread
From: Aruna Hewapathirane @ 2019-12-12  3:14 UTC (permalink / raw)
  To: Frank A. Cancio Bello; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 1116 bytes --]

>> 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 ?
:)

[-- Attachment #1.2: Type: text/html, Size: 2353 bytes --]

<div dir="ltr"><div dir="ltr" class="gmail_attr">&gt;&gt; On Sun, Dec 8, 2019 at 2:06 PM Frank A. Cancio Bello &lt;<a href="mailto:frank@generalsoftwareinc.com">frank@generalsoftwareinc.com</a>&gt; wrote:</div><div dir="ltr" class="gmail_attr">&gt;&gt; Hi,</div><div dir="ltr" class="gmail_attr">&gt;&gt; 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?</div><div dir="ltr" class="gmail_attr">&gt;&gt;</div><div dir="ltr" class="gmail_attr">&gt;&gt; thanks</div><div dir="ltr" class="gmail_attr">&gt;&gt; frank a.</div><div dir="ltr" class="gmail_attr"><br></div><div class="gmail_attr">Hi Frank,</div><div class="gmail_attr"><br></div><div class="gmail_attr">There are two options you can use with gcc to get the processor output as part of the kernel compilation process.</div><div class="gmail_attr">  -save-temps                <br>  -save-temps=&lt;arg&gt;     <br></div><div class="gmail_attr"><br></div><div class="gmail_attr">1 - Open the top level Makefile in your favorite text editor.</div><div class="gmail_attr">2 - Search for KBUILD_CFLAGS</div><div class="gmail_attr">    My Makefile which is at /home/aruna/linux-5.4.2/Makefile shows me at line 458</div><div class="gmail_attr">    KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs <br></div><br><div class="gmail_attr">3 - Now plugin   -save-temps=&lt;arg&gt; but replace &lt;arg&gt; with obj like shown below:</div><div class="gmail_attr"><div class="gmail_attr">   KBUILD_CFLAGS   := -Wall  -save-temps=obj  -Wundef -Werror=strict-prototypes -Wno-trigraphs <br></div><div class="gmail_attr"><br></div><div class="gmail_attr">4 - Save the Makefile.</div><div class="gmail_attr">5 - Run make and we are done !<br></div><div class="gmail_attr"><br></div><div class="gmail_attr">Each directory will have the preprocessor output in *.i and *.s files.<br></div><div class="gmail_attr"><br></div><div class="gmail_attr">Good luck - Aruna ( I keep asking myself &#39;why&#39; are you doing this though ? :)<br></div><div class="gmail_attr"><br></div></div><div class="gmail_attr"><br></div><div class="gmail_attr"><br></div><div class="gmail_attr"><br></div><div class="gmail_attr"><br></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-08 19:05 How to get the preprocessor output as part of the compilation process? Frank A. Cancio Bello
2019-12-08 21:53 ` Valdis Klētnieks
2019-12-09 10:10 ` Konstantin Andreev
2019-12-10  3:17   ` Valdis Klētnieks
2019-12-10 13:35     ` Konstantin Andreev
2019-12-12  3:14 ` Aruna Hewapathirane

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org
	public-inbox-index kernelnewbies

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git