Bug 65584 - [i386] Intrinsics inclusion with `-nostdinc' failing due to `stdlib.h' dependency
Summary: [i386] Intrinsics inclusion with `-nostdinc' failing due to `stdlib.h' depend...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 102231 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-03-26 15:43 UTC by Kirill Yukhin
Modified: 2024-03-26 15:54 UTC (History)
3 users (show)

See Also:
Host:
Target: i386, x86_64
Build:
Known to work:
Known to fail: 12.0
Last reconfirmed: 2021-09-07 00:00:00


Attachments
Reproducer (71 bytes, text/plain)
2015-03-26 15:43 UTC, Kirill Yukhin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kirill Yukhin 2015-03-26 15:43:44 UTC
Created attachment 35149 [details]
Reproducer

Hello,
When disabling standard headers inclusion, it is impossible to use GCC intrinsics:

$ ./release/usr/local/bin/gcc  -mavx -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.2/include -S repro.c
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/xmmintrin.h:38:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/x86intrin.h:34,
                 from repro.c:2:
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/mm_malloc.h:27:20: fatal error: stdlib.h: No such file or directory
compilation terminated.

This is because `mm_malloc.h' depends on malloc () / free () calls.

Maybe remove this dependence?
Comment 1 Jakub Jelinek 2015-03-26 16:14:46 UTC
IMHO a user error, if you use -nostdinc, you are responsible for letting the compiler know where to find all the needed includes.
Comment 2 Kirill Yukhin 2015-03-31 11:55:25 UTC
(In reply to Jakub Jelinek from comment #1)
> IMHO a user error, if you use -nostdinc, you are responsible for letting the
> compiler know where to find all the needed includes.

Yes, but for my case, these header is not needed. Moreover, as far as I understand <stdlib.h> inclusion was added for compatibility with ICC only.

Maybe, somehow check if this header is available and include <mm_malloc.h>
into <x86intrin.h> only if it is.
Comment 3 Andrew Pinski 2021-09-07 15:30:18 UTC
*** Bug 102231 has been marked as a duplicate of this bug. ***
Comment 4 Segher Boessenkool 2021-09-07 15:41:16 UTC
Since you closed PR102231 (which has a lot more detail), let me paste
that here:


<xmmintrin.h> includes <mm_malloc.h> unconditionally

Instead, it should do something like
  #if __STDC_HOSTED__
  #include <mm_malloc.h>
  #endif
as Clang does, because <mm_malloc.h> only exists on hosted environments
(which is good, because it itself uses <stdlib.h>, etc.)

A few intrinsics that use stuff from <mm_malloc.h> need the same treatment.


(apparently <mm_malloc.h> *is* created by GCC, but in the source tree it is
pmm_malloc.h and gmm_malloc.h).
Comment 5 Jakub Jelinek 2021-09-07 16:12:42 UTC
We could avoid the stdlib.h include for pmm_alloc.h through __builtin_malloc/__builtin_free and __SIZE_TYPE__.
But yes, maybe not defining _mm_malloc/_mm_free at all for non-__STDC_HOSTED__ is better.
Comment 6 Jakub Jelinek 2021-09-07 16:14:29 UTC
And the "somehow" is now possible too, we can use __has_include(<stdlib.h>).
Comment 7 Segher Boessenkool 2021-09-07 17:05:43 UTC
(In reply to Jakub Jelinek from comment #6)
> And the "somehow" is now possible too, we can use __has_include(<stdlib.h>).

Including it with -ffreestanding in effect is always wrong.  Even if the header
exists it may not be what you expected.