aix: add required changes to build with clang#62656
aix: add required changes to build with clang#62656abmusse wants to merge 6 commits intonodejs:mainfrom
Conversation
Some gcc flags dont work on clang: -mfprnd -mno-popcntb -fno-extern-tls-init So now we conditionally add them when clang is not enabled Also for clang builds we need to pass some additonal flags: -fno-integrated-as -fno-xl-pragma-pack These flags are discuessed in: https://chromium-review.googlesource.com/c/chromium/src/+/7120638
to header files not shipping declarations. This seems like a bug in AIX header files because the examples show including the headers but upon inspecting these files there are no declarations for sendmmsg and others: https://www.ibm.com/docs/en/aix/7.2.0?topic=s-sendmmsg-subroutine For now we can claim to not have these functions. Alternatively we can declare these ourselves if we are AIX 7.2 or newer. The actual functions look to be available in libc. GCC also has the same implicit function declaration but it happily moves forward. Clang started making this an explict error in clang 16: https://www.redhat.com/en/blog/new-warnings-and-errors-clang-16
Original commit message: aix: add required changes to build with clang Change-Id: Icc78c58831306aa2f227843b0b4ec2321585fa64 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7107287 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/main@{#104364}
visibility for symbols.
Without these changes we are getting back linker errors
AIX with clang builds:
```text
ld: 0711-407 ERROR: Symbol [SYMBOL_NAME]
Visibility is not allowed on a reference to an imported symbol.
```
Not including hidden symbols in the export files matches the
recomendation by XLC documentation:
> When using export lists, it is not recommended to put symbols with
> hidden visibility in the lists.
ref: https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.4?topic=libraries-symbol-exports-visibilities
in create_expfile.sh AIX export files support the `weak` keyword to mark weak symbols. ref: https://www.ibm.com/docs/en/aix/7.2.0?topic=l-ld-command#ld__a3119106d This helps preserve C++ weak symbol semantics and preventing potential linker conflicts.
|
Review requested:
|
| #if defined(_AIX) && !defined(_AIX72) | ||
| /* AIX >= 7.2 provides sendmmsg() and recvmmsg(). */ | ||
| #if defined(_AIX) | ||
| /* Force fallback to sndmsg and recvmsg */ |
There was a problem hiding this comment.
This needs to be made upstream as otherwise it's going to get reverted every OpenSSL upgrade we take: https://github.com/openssl/openssl/blob/72d5e8dcd2977234e47e840d2173917daa8bb0fa/crypto/bio/bss_dgram.c#L71-L72
There was a problem hiding this comment.
I found a similar issue upstream: openssl/openssl#23751
Someone there mentioned that the headers for sendmmsg recvmmsg are in another location:
#include <net/proto_uipc.h>
I will open up a PR on upstream and see what maintainers say.
There was a problem hiding this comment.
I see that that documentation claims its available here: https://www.ibm.com/docs/en/aix/7.2.0?topic=s-sendmmsg-subroutine
(Starting in AIX 7.2)
Following those docs you get back implicit function declaration for it.
You can re-recreate the behavior with this simple c program:
#include <sys/types.h>
#include <sys/socketvar.h>
#include <sys/socket.h>
#include <net/proto_uipc.h>
int main() {
struct mmsghdr msgs[1];
/* This causes implicit declaration warning - no header declares sendmmsg */
sendmmsg(0, msgs, 1, 0);
return 0;
}Clang:
$ /opt/clang+llvm-20.1.7-powerpc64-ibm-aix-7.2/bin/clang -o aix-sendmmsg-issue.out aix-sendmmsg-issue.c
aix-sendmmsg-issue.c:23:5: error: call to undeclared function 'sendmmsg'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
23 | sendmmsg(0, msgs, 1, 0);
| ^
aix-sendmmsg-issue.c:23:5: note: did you mean 'nsendmsg'?
/usr/include/sys/socket.h:645:9: note: 'nsendmsg' declared here
645 | ssize_t sendmsg(int, const struct msghdr *, int);
| ^
/usr/include/sys/socket.h:174:25: note: expanded from macro 'sendmsg'
174 | #define sendmsg nsendmsg
| ^
1 error generated.
GCC:
$ /opt/freeware/bin/gcc-12 -o aix-sendmmsg-issue.out aix-sendmmsg-issue.c
aix-sendmmsg-issue.c: In function 'main':
aix-sendmmsg-issue.c:23:5: warning: implicit declaration of function 'sendmmsg'; did you mean 'sendmsg'? [-Wimplicit-function-declaration]
23 | sendmmsg(0, msgs, 1, 0);
| ^~~~~~~~
| sendmsg
Even including net/proto_uipc.h it fails too, upon further investigation looks like everything in that header is wrapped in #ifdef _KERNEL so it seems like sendmmsg / recvmmsg is not really usuable unless _KERNEL is defined.
With the above information, I'm now going forward with my changes in the PR on upstream openssl to just fall back to sendmsg and recvmsg.
I will try to open an issue with AIX team about sendmmsg not being available.
This PR enables building Node.js on AIX with Clang by addressing several issues.
The game plan I have in mind to get AIX building with clang:
Confirm the changes in this PR doesn't break gcc builds (Node.js 24, 22, 20 still use it), then merge this PR
After this PR gets merged, update select compiler to use clang for Node.js 26+ builds
(I have a draft PR for that here: aix: select clang for Node.26+ builds build#4286)
Changes
1. Add conditional flags for Clang builds
Some GCC flags don't work on Clang:
-mfprnd-mno-popcntb-fno-extern-tls-initThese are now conditionally added only when Clang is not enabled.
For Clang builds, we need additional flags:
-fno-integrated-as-fno-xl-pragma-packThese flags are discussed in: https://chromium-review.googlesource.com/c/chromium/src/+/7120638
2. Fix OpenSSL implicit declaration errors
AIX header files don't ship declarations for
sendmmsgand related functions, despite documentation showing they should be included. This appears to be a bug in AIX header files.GCC tolerates implicit function declarations, but Clang 16+ treats them as errors:
https://www.redhat.com/en/blog/new-warnings-and-errors-clang-16
example:
ref: https://ci.nodejs.org/job/node-test-commit-aix/nodes=aix72-power9/62022/consoleFull
For now, we claim to not have these functions. The actual functions are available in libc, so an alternative would be to declare them ourselves for AIX 7.2+.
Ref: https://www.ibm.com/docs/en/aix/7.2.0?topic=s-sendmmsg-subroutine
3. Cherry-pick V8 commit for AIX Clang support
Cherry-picked V8 commit 7107287 which adds required changes to build V8 with Clang on AIX.
Original commit: https://chromium-review.googlesource.com/c/v8/v8/+/7107287
4. Filter hidden visibility symbols from export script
Without filtering HIDDEN symbols, AIX Clang builds fail with linker errors:
Not including hidden symbols in the export files matches the recommendation by XLC documentation:
Ref: https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.4?topic=libraries-symbol-exports-visibilities
5. Add weak symbol detection in create_expfile.sh
AIX export files support the
weakkeyword to mark weak symbols. According to IBM documentation:ref: https://www.ibm.com/docs/en/aix/7.2.0?topic=l-ld-command#ld__a3119106d
This helps preserve C++ weak symbol semantics and preventing potential linker conflicts.