Check if PPC __has_include(<sys/auxv.h>)
Categories
(NSS :: Build, defect, P1)
Tracking
(Not tracked)
People
(Reporter: giulio.benetti, Assigned: giulio.benetti)
Details
Attachments
(1 file, 1 obsolete file)
1.44 KB,
patch
|
kjacobs
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36
Steps to reproduce:
Build on an environment without sys/auxv.h
Actual results:
sys/auxv.h is not present leading to build failure
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 1•5 years ago
|
||
Assignee | ||
Comment 2•5 years ago
|
||
Kindly ping
Comment 3•5 years ago
|
||
Assignee | ||
Comment 4•5 years ago
|
||
(In reply to Kevin Jacobs [:kjacobs] from comment #3)
Comment on attachment 9125320 [details] [diff] [review]
0001-Bug-1614183-Check-if-PPC-__has_include-sys-auxv.h.patchI don't believe is available on GCC <5, and the documentation recommends a
check to make sure it's defined first:
https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html. Could you
please add that?
Sure
It might be more readable to check this inside the firstdefined(__linux__) ...
conditional (rather than prepending two somewhat-unrelated conditions).
But this way we assume that on FreeBSD sys/auxv.h always exists.
Is that acceptable?
Comment 5•5 years ago
|
||
My suggestion was to place the first include guards around the include statement, rather than in the OS checks. Then it will check regardless.
Assignee | ||
Comment 6•5 years ago
|
||
(In reply to Kevin Jacobs [:kjacobs] from comment #5)
My suggestion was to place the first include guards around the include statement, rather than in the OS checks. Then it will check regardless.
Ok for this.
Anyway if I use this form:
'''
#if defined __has_include
if __has_include (<sys/auxv.h>)
include <sys/auxv.h>
endif
#endif
'''
it will really include <sys/auxv.h> only if __has_include() is supported, so only with gcc version >= 4.9.2:
https://android.googlesource.com/toolchain/gcc/+/master/gcc-4.9/libcpp/ChangeLog#26
is this acceptable?
Updated•5 years ago
|
Comment 7•5 years ago
|
||
(In reply to Giulio Benetti from comment #6)
(In reply to Kevin Jacobs [:kjacobs] from comment #5)
....
it will really include <sys/auxv.h> only if __has_include() is supported, so only with gcc version >= 4.9.2:
https://android.googlesource.com/toolchain/gcc/+/master/gcc-4.9/libcpp/ChangeLog#26is this acceptable?
Given that we still support older GCC versions, we'll probably want to fail the other way (with an else
) and simply include
it when we're not able to first verify its availability. This maintains the current behavior on those older GCCs.
Updated•5 years ago
|
Assignee | ||
Comment 8•5 years ago
|
||
(In reply to Kevin Jacobs [:kjacobs] from comment #7)
(In reply to Giulio Benetti from comment #6)
(In reply to Kevin Jacobs [:kjacobs] from comment #5)
....
it will really include <sys/auxv.h> only if __has_include() is supported, so only with gcc version >= 4.9.2:
https://android.googlesource.com/toolchain/gcc/+/master/gcc-4.9/libcpp/ChangeLog#26is this acceptable?
Given that we still support older GCC versions, we'll probably want to fail the other way (with an
else
) and simplyinclude
it when we're not able to first verify its availability. This maintains the current behavior on those older GCCs.
But on aarch64 and arm they use this:
https://hg.mozilla.org/projects/nss/file/tip/lib/freebl/blinit.c#l111
so already they assume that if __has_include() is not supported <sys/auxv.h> is not present.
And if I place __has_include() guard only for #include and <sys/auxv.h> is not present and not included,
compiler will fail on getauxval(AT_HWCAP2):
https://hg.mozilla.org/projects/nss/file/tip/lib/freebl/blinit.c#l452
or:
on elf_aux_into():
https://hg.mozilla.org/projects/nss/file/tip/lib/freebl/blinit.c#l455
so this patch would solve nothing IMHO.
So ok for:
#if defined(__powerpc__)
#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD__ >= 12)
#ifdef __has_include
#if __has_include(<sys/auxv.h>)
#include <sys/auxv.h>
#endif
#else
#include <sys/auxv.h>
#endif
#elif (defined(__FreeBSD__) && __FreeBSD__ < 12)
#include <sys/sysctl.h>
#endif
but then I need this too:
#if defined(__linux__)
#if __has_include(<sys/auxv.h>)
hwcaps = getauxval(AT_HWCAP2);
#endif
#elif defined(__FreeBSD__)
#if __FreeBSD__ >= 12
#if __has_include(<sys/auxv.h>)
elf_aux_info(AT_HWCAP2, &hwcaps, sizeof(hwcaps));
#endif
#else
size_t len = sizeof(hwcaps);
sysctlbyname("hw.cpu_features2", &hwcaps, &len, NULL, 0);
#endif
#endif
I send a patch like this.
Assignee | ||
Comment 9•5 years ago
|
||
(In reply to Giulio Benetti from comment #8)
(In reply to Kevin Jacobs [:kjacobs] from comment #7)
(In reply to Giulio Benetti from comment #6)
(In reply to Kevin Jacobs [:kjacobs] from comment #5)
....
it will really include <sys/auxv.h> only if __has_include() is supported, so only with gcc version >= 4.9.2:
https://android.googlesource.com/toolchain/gcc/+/master/gcc-4.9/libcpp/ChangeLog#26is this acceptable?
Given that we still support older GCC versions, we'll probably want to fail the other way (with an
else
) and simplyinclude
it when we're not able to first verify its availability. This maintains the current behavior on those older GCCs.But on aarch64 and arm they use this:
https://hg.mozilla.org/projects/nss/file/tip/lib/freebl/blinit.c#l111so already they assume that if __has_include() is not supported <sys/auxv.h> is not present.
And if I place __has_include() guard only for #include and <sys/auxv.h> is not present and not included,
compiler will fail on getauxval(AT_HWCAP2):
https://hg.mozilla.org/projects/nss/file/tip/lib/freebl/blinit.c#l452
or:
on elf_aux_into():
https://hg.mozilla.org/projects/nss/file/tip/lib/freebl/blinit.c#l455so this patch would solve nothing IMHO.
So ok for:
#if defined(__powerpc__) #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD__ >= 12) #ifdef __has_include #if __has_include(<sys/auxv.h>) #include <sys/auxv.h> #endif #else #include <sys/auxv.h> #endif #elif (defined(__FreeBSD__) && __FreeBSD__ < 12) #include <sys/sysctl.h> #endif
but then I need this too:
#if defined(__linux__) #if __has_include(<sys/auxv.h>) hwcaps = getauxval(AT_HWCAP2); #endif #elif defined(__FreeBSD__) #if __FreeBSD__ >= 12 #if __has_include(<sys/auxv.h>) elf_aux_info(AT_HWCAP2, &hwcaps, sizeof(hwcaps)); #endif #else size_t len = sizeof(hwcaps); sysctlbyname("hw.cpu_features2", &hwcaps, &len, NULL, 0); #endif #endif
I send a patch like this.
Oh no, wait, if:
#if defined(__linux__)
#if __has_include(<sys/auxv.h>)
hwcaps = getauxval(AT_HWCAP2);
#endif
#elif defined(__FreeBSD__)
but __has_include() is not defined, then <sys/auxv.h> will be includeed but getauxval() won't get called.
Mmmh
Assignee | ||
Comment 10•5 years ago
|
||
I see only 2 options:
- treat it like Aarch64/ARM assuming __has_include() is provided by compiler
- introduce getauxval() and elf_aux_info() pointers similar to what's been already done with Aarch64/ARM:
https://hg.mozilla.org/projects/nss/file/tip/lib/freebl/blinit.c#l122
but also case 2) is based on case 1), so it will become a big mess IMHO.
Comment 11•5 years ago
|
||
I had not seen the #define __has_include(x) 0
ARM code you linked. My request was based on an assumption that it will be more common to compile on an old GCC (that can't check for the include) in an environment with <sys/auxv.h>, than to use such an old GCC and an environment without <sys/auxv.h>... And not wanting to disable HW crypto in the larger subset of builds.
Nevertheless, since we have a precedent for #define __has_include(x) 0
, I'm okay adapting that solution here. We'll just need to make sure it's defined in PPC builds as well.
Assignee | ||
Comment 12•5 years ago
|
||
Here is the new patch using the same form Arm used:
#ifndef __has_include
#define __has_include(x) 0
#endif
Updated•5 years ago
|
Comment 13•5 years ago
|
||
Comment 14•5 years ago
|
||
Description
•