<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94428>94428</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Compiling C++ codes with arm-eabi target triple wrongly defines _GNU_SOURCE
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lbmeng
</td>
</tr>
</table>
<pre>
**Version**: LLVM 17.0.6
**Download URL**: https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz
Considering the following test code:
```
$ cat test.c
#ifdef _GNU_SOURCE
#warning "_GNU_SOURCE is defined!"
#endif
int main() {return 0;}
$ ln -s test.c test.cpp
```
Compiling the test.c and test.cpp with clang and clang++, with arm-eabi target gives me:
```
$ clang --target=arm-eabi -c test.c -o test
$ clang++ --target=arm-eabi -c test.cpp -o test
test.cpp:2:2: warning: "_GNU_SOURCE is defined!" [-W#warnings]
2 | #warning "_GNU_SOURCE is defined!"
| ^
1 warning generated.
```
Testing arm64, i386, x86_64, riscv32, riscv64 targets does not expose the same behavior:
```
$ clang --target=arm64 -c test.c -o test
$ clang++ --target=arm64 -c test.cpp -o test
$ clang --target=i386 -c test.c -o test
$ clang++ --target=i386 -c test.cpp -o test
$ clang --target=x86_64 -c test.c -o test
$ clang++ --target=x86_64 -c test.cpp -o test
$ clang --target=riscv32 -c test.c -o test
$ clang++ --target=riscv32 -c test.cpp -o test
$ clang --target=riscv64 -c test.c -o test
$ clang++ --target=riscv64 -c test.cpp -o test
```
If I append _-linux_ to the target triple, arm64, i386, x86_64, riscv32, riscv64 targets for C++ will throw out the warning, but C will not, e.g.: riscv64-linux
```
$ clang --target=riscv64-linux -c test.c -o test
$ clang++ --target=riscv64-linux -c test.cpp -o test
test.cpp:2:2: warning: "_GNU_SOURCE is defined!" [-W#warnings]
2 | #warning "_GNU_SOURCE is defined!"
| ^
1 warning generated.
```
Appending _-linux_ to arm-eabi triple does not make any difference:
```
$ clang --target=arm-eabi-linux -c test.c -o test
$ clang++ --target=arm-eabi-linux -c test.cpp -o test
test.cpp:2:2: warning: "_GNU_SOURCE is defined!" [-W#warnings]
2 | #warning "_GNU_SOURCE is defined!"
| ^
1 warning generated.
```
There are two issues:
1. It looks the arm-eabi target wrongly defines _GNU_SOURCE when compiling C++ code
2. Why compiling C code does not get _GNU_SOURCE defined, either with or without the -linux triple, for these targets (arm-eabi/arm64/i386/x86_64/riscv32/riscv64)?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkV01v4zYT_jX0ZSBBpr7sgw6O_erFAmkLbJvdY0BZI4ldmhRIKk766wtRlO18NE18aA8NlJAi55kZzjMcTZgxvJWIBUlvSLpbsMF2SheiOqBsF5WqnwpCN4RuvqE2XMnphcQbuL399hMs8zAKMxLtSLSZtnbqKIViNdx9vT0Ld9b2hsQbQktCy5bbbqjCvToQWgrxMA9Br9XvuLeElhoFMoOG0LL2Gr2Q0m3gzdJyL5hsCb1x6Gk1eFxl91kSCC6Hx6CVQzBUg7RDQGkYJaFlOnz8w3vs_m6VNLxGzWULtkNolBDq6N7QWNirGkfPJ0QW-ccfOYE9s04w3M9rMW9qbOD-_z_f3f_6y93X7f9OO0em5aiZUHqxDdxAjQ2XWBO6JJSe5FHWvLl0lksLB8YloStC10DyG4120BIiEt-QfHf2S0gIjPfMD33_9il8GA49F3MQPI7J-oSFI7cduIi79Tn27tlOu0wfAmQVB8t0ixZa_oAGDu8H0GkMgglC4t1JSTA7DoFysxegyfj70L5_Dj5FIt5Q_wuelXH6N8QASW-C72ciDUl9yAEAKJB8C5-lGdzPiASS-lRZzj5BixI1s1iH73D3Gxo7CjN9yJKRDB6vsnGc7sI409zsH2J6mmaJ58hArdCAVBbwsVcGHf-GHRAq7NgDV_qz7GXJddRd4l7y9qat8ZhXmHoO-5ClKZBX2HoJ_JA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