On Thu, 18 Apr 2024 04:26:21 GMT, Kim Barrett <kbarr...@openjdk.org> wrote:

>> I opened https://bugs.openjdk.org/browse/JDK-8330539 so we don't lose track 
>> of this, but we can keep the discussion/voting here.
>
> 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.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18536#discussion_r1583360569

Reply via email to