On Mon, 29 Apr 2024 16:17:13 GMT, Joachim Kern <jk...@openjdk.org> wrote:
>> For the impatient, I suggest adopting mechanism 2, i.e. unconditionally >> include <alloc.h> in globalDefinitions_gcc.hpp. >> >> We can't include <alloca.h> in shared code, and there is a use in shared code >> (in the relatively recently added JavaThread::pretouch_stack). >> >> When I questioned whether we needed to include <alloca.h> at all, I referred >> to a Linux man page I'd found on the internet (the same page mdoerr linked >> to), which says (in part) >> >> "By default, modern compilers automatically translate all uses of alloca() >> into the built-in ..." >> >> Apparently I should have kept digging, because it seems that page is >> old/incorrect. A seemingly more recent Linux man page describes a different >> way of handling it that is closer to what we're seeing, but still not quite >> correct. >> >> glibc's <stdlib.h> includes <alloca.h> if __USE_MISC is defined. >> One of the ways __USE_MISC can become defined is if _GNU_SOURCE is defined, >> and we define that for both gcc and clang toolchains. >> >> We include <stdlib.h> in globalDefinitions_gcc.hpp. So when building with >> gcc, >> globalDefinitions.hpp implicitly includes <alloca.h>. >> >> The glibc definition of alloca is >> >> #ifdef __GNUC__ >> # define alloca(size) __builtin_alloca (size) >> #endif /* GCC. */ >> >> So that explains why we don't need any explicit include of <alloca.h> when >> building with gcc. I expect there's something similar going on with Visual >> Studio and Xcode/clang. But apparently not with Open XLC clang. > > On AIX `stdlib.h` also would define `alloca`, if `__STRICT_ANSI__` wouldn't > be set. > > > 780 #if !defined(__xlC__) || defined(__ibmxl__) || defined(__cplusplus) > 781 #if defined(__IBMCPP__) && !defined(__ibmxl__) > 782 extern "builtin" char *__alloca (size_t); > 783 # define alloca __alloca > 784 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) > 785 #undef alloca > 786 #define alloca(size) __builtin_alloca (size) > 787 #endif > > > A small plain Testprogramm not using all of the flags we used in jdk build, > does not set `__STRICT_ANSI__` and then `alloca` is defined correct. The compiler flag introducing __STRICT_ANSI__ is -std=c++14. If I omit this explicit compiler flag the default is used, which is also c++14. But the default does not set __STRICT_ANSI__ but 2 other defines. I will try a build without -std=c++14 and if this works, we have a solution. Nevertheless i will interrogate IBM what the hell this behavior should be. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/18536#discussion_r1584461665