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

Extend compiler version detection with clang #392

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

gemesa
Copy link
Contributor

@gemesa gemesa commented Jan 2, 2024

Previously when compiled with clang the version check returned this misleading gcc version:

$ ./hcxdumptool -v
hcxdumptool 6.3.2 (C) 2023 ZeroBeat
...
compiled by gcc 4.2.1
...

I guess it is because clang defines the __GNUC__ macros for some compatibility reasons or something like that.

I think clang is becoming more widespread so this case should be handled. Now, after the changes the version check is fixed:

$ make CC=clang                                                  
fatal: No names found, cannot describe anything.
clang -O3 -Wall -Wextra -Wpedantic -std=gnu99   -o hcxdumptool hcxdumptool.c -DVERSION_TAG=\"6.3.2\" -DVERSION_YEAR=\"2023\" -DHCXSTATUSOUT -DHCXNMEAOUT
$ ./hcxdumptool -v
...
compiled by clang 17.0.6
...
$ make clean
...
$ make
fatal: No names found, cannot describe anything.
cc -O3 -Wall -Wextra -Wpedantic -std=gnu99   -o hcxdumptool hcxdumptool.c -DVERSION_TAG=\"6.3.2\" -DVERSION_YEAR=\"2023\" -DHCXSTATUSOUT -DHCXNMEAOUT
$ ./hcxdumptool -v
...
compiled by gcc 13.2.1
..

@ZerBea ZerBea merged commit 44bd50b into ZerBea:master Jan 3, 2024
2 checks passed
@gemesa gemesa deleted the compiler-version branch January 3, 2024 08:08
@ZerBea
Copy link
Owner

ZerBea commented Jan 3, 2024

Thanks, merged but modified because gcc should be on first rank.

@gemesa
Copy link
Contributor Author

gemesa commented Jan 3, 2024

That would have been my preference also but with this approach we are back to the original problem because __GNUC__ is defined both by gcc and clang so the branch #elif defined(__clang__) is never hit. If you want to check for __GNUC__ first, you could write something like this:

#if defined(__GNUC__) && !defined(__clang__)
fprintf(stdout, "compiled by gcc %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#elif defined(__clang__)
fprintf(stdout, "compiled by clang %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__);
...

@ZerBea
Copy link
Owner

ZerBea commented Jan 3, 2024

Thanks, that is better:

$ ./hcxdumptool -v
hcxdumptool 6.3.2-145-g4fd4dfb (C) 2023 ZeroBeat
running on Linux kernel 6.6.7-arch1-1
running GNU libc version 2.38
compiled by gcc 13.2.1
compiled with Linux API headers 6.4.0
compiled with GNU libc headers 2.38
enabled REALTIME DISPLAY
enabled GPS support
enabled BPF compiler

$ ./hcxdumptool -v
hcxdumptool 6.3.2-145-g4fd4dfb (C) 2023 ZeroBeat
running on Linux kernel 6.6.7-arch1-1
running GNU libc version 2.38
compiled by clang 16.0.6
compiled with Linux API headers 6.4.0
compiled with GNU libc headers 2.38
enabled REALTIME DISPLAY
enabled GPS support
enabled BPF compiler


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

Successfully merging this pull request may close these issues.

2 participants