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

Any way to force buildtype for compiler.preprocess? #14201

Open
tagoh opened this issue Jan 29, 2025 · 3 comments
Open

Any way to force buildtype for compiler.preprocess? #14201

tagoh opened this issue Jan 29, 2025 · 3 comments
Assignees

Comments

@tagoh
Copy link

tagoh commented Jan 29, 2025

Hi,

I have a few content in meson.build which preprocess something. It basically works but it doesn't when giving -g3 in CFLAGS and preprocessing with gcc because gcc embeds few definitions inline:

$ diff -u <(gcc -E /usr/include/stdio.h) <(gcc -E -g3 /usr/include/stdio.h) | head
--- /dev/fd/63  2025-01-29 10:37:54.697944607 +0900
+++ /dev/fd/62  2025-01-29 10:37:54.697944607 +0900
@@ -1,66 +1,1474 @@
 # 0 "/usr/include/stdio.h"
+# 1 "/tmp/"
 # 0 "<built-in>"
+#define __STDC__ 1
+# 0 "<built-in>"
+#define __STDC_VERSION__ 202311L
+# 0 "<built-in>"
$ diff -u <(clang -E /usr/include/stdio.h) <(clang -E -g3 /usr/include/stdio.h) | head
$ 

and it causes the redefinition error.

I could worked this around like compiler.preprocess(..., compile_args: '-g0') but I'm not sure if it is really portable way.
What is the best way to build such case without any problems?

@thesamesam
Copy link
Collaborator

thesamesam commented Jan 29, 2025

Some context here is:

GCC documents that macro definitions are included inline with -g3:

Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.

It appears that this is actually a Clang bug in that it doesn't map -g3 to its -fdebug-macro option, per llvm/llvm-project#14524, so we should be seeing this behaviour with both GCC and Clang, and it's a bug that we don't with Clang.

But as for compiler.preprocess, I suppose we want to always add -g0 or -fno-debug-macro (?) if supported by the compiler.

@dcbaker
Copy link
Member

dcbaker commented Jan 29, 2025

Given that Clang is saying this is a bug, then we should go for one of those two options.

@thesamesam
Copy link
Collaborator

OK, mine.

@thesamesam thesamesam self-assigned this Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants