diff options
author | Kamil Rytarowski <n54@gmx.com> | 2016-02-16 22:55:13 +0100 |
---|---|---|
committer | Kamil Rytarowski <n54@gmx.com> | 2016-02-17 21:30:25 +0100 |
commit | 6952d90ad3edfc461ecbe081f121419f4072326c (patch) | |
tree | 3cb6501aa8bd1a278994bfa5dc9b0494e481f1fd | |
parent | 5a26372691fea92f1ef328f287e1e37243af3e34 (diff) | |
download | coreclr-6952d90ad3edfc461ecbe081f121419f4072326c.tar.gz coreclr-6952d90ad3edfc461ecbe081f121419f4072326c.tar.bz2 coreclr-6952d90ad3edfc461ecbe081f121419f4072326c.zip |
Fix NetBSD build issue: Use compiler version of alloca(3) when possible
The documentation of alloca(3) says:
o The alloca() function should be supplied by the compiler because the
compiler is allowed to make assumptions about the stack and frame
pointers. The libc alloca() implementation cannot account for those
assumptions. While there is a machine dependent implementation of
alloca() in libc, its use is discouraged and in most cases it will
not work. Using this implementation will produce linker warnings.
This is true for CoreCLR - alloca(3) was breaking 30 PAL tests.
Enforce on this operating system a compiler version.
Thanks Jan Kotas (Microsoft) for inspiration what may go wrong.
Thanks Jan Vorli (Microsoft) for useful suggestions in order to fix it.
-rw-r--r-- | src/ToolBox/SOS/Strike/strike.h | 11 | ||||
-rw-r--r-- | src/pal/inc/pal.h | 5 | ||||
-rw-r--r-- | src/pal/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/pal/src/include/pal/palinternal.h | 8 |
4 files changed, 14 insertions, 11 deletions
diff --git a/src/ToolBox/SOS/Strike/strike.h b/src/ToolBox/SOS/Strike/strike.h index a23a3f17bb..d6bd54dc54 100644 --- a/src/ToolBox/SOS/Strike/strike.h +++ b/src/ToolBox/SOS/Strike/strike.h @@ -76,6 +76,16 @@ #ifndef PAL_STDCPP_COMPAT #include <malloc.h> #endif + +#ifdef FEATURE_PAL +#ifndef alloca +#define alloca __builtin_alloca +#endif +#ifndef _alloca +#define _alloca __builtin_alloca +#endif +#endif // FEATURE_PAL + #include <stddef.h> #ifndef FEATURE_PAL @@ -128,4 +138,3 @@ HRESULT SetNGENCompilerFlags(DWORD flags); #endif // __strike_h__ - diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index 0aa436504a..7801883c6c 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -6340,11 +6340,6 @@ PALIMPORT char * __cdecl _strdup(const char *); #endif //_MSC_VER #if defined(__GNUC__) && defined(PLATFORM_UNIX) -// we set -fno-builtin on the command line. This requires that if -// we use alloca, with either have to call __builtin_alloca, or -// ensure that the alloca call doesn't happen in code which is -// modifying the stack (such as "memset (alloca(x), y, z)" - #define alloca __builtin_alloca #endif // __GNUC__ diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt index 9828d30433..aa68d81e4f 100644 --- a/src/pal/src/CMakeLists.txt +++ b/src/pal/src/CMakeLists.txt @@ -68,7 +68,6 @@ endif() # turn off capability to remove unused functions (which was enabled in debug build with sanitizers) set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -Wl,--no-gc-sections") -add_compile_options(-fno-builtin) add_compile_options(-fPIC) if(PAL_CMAKE_PLATFORM_ARCH_AMD64) diff --git a/src/pal/src/include/pal/palinternal.h b/src/pal/src/include/pal/palinternal.h index 070ffdf240..5b19ae6f1a 100644 --- a/src/pal/src/include/pal/palinternal.h +++ b/src/pal/src/include/pal/palinternal.h @@ -337,15 +337,15 @@ function_name() to call the system's implementation #undef _BitScanForward64 #endif -/* pal.h does "#define alloca _alloca", but we need access to the "real" - alloca */ -#undef alloca +/* pal.h defines alloca(3) as a compiler builtin. + Redefining it to native libc will result in undefined breakage because + a compiler is allowed to make assumptions about the stack and frame + pointers. */ /* Undef all functions and types previously defined so those functions and types could be mapped to the C runtime and socket implementation of the native OS */ #undef exit -#undef alloca #undef atexit #undef div #undef div_t |