< prev index next >

make/autoconf/flags-ldflags.m4

Print this page
8209817: stack is executable when building with Clang on Linux
Reviewed-by: dholmes, martin, mikael, ihse
Contributed-by: Arthur Eubanks <aeubanks@google.com>


  57   AC_SUBST(LDFLAGS_TESTEXE)
  58 ])
  59 
  60 ################################################################################
  61 
  62 # CPU independent LDFLAGS setup, used for both target and build toolchain.
  63 AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
  64 [
  65   # Setup basic LDFLAGS
  66   if test "x$TOOLCHAIN_TYPE" = xgcc; then
  67     # If this is a --hash-style=gnu system, use --hash-style=both, why?
  68     # We have previously set HAS_GNU_HASH if this is the case
  69     if test -n "$HAS_GNU_HASH"; then
  70       BASIC_LDFLAGS="-Wl,--hash-style=both"
  71       LIBJSIG_HASHSTYLE_LDFLAGS="-Wl,--hash-style=both"
  72     fi
  73 
  74     # Add -z defs, to forbid undefined symbols in object files.
  75     BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,-z,defs"
  76 
  77     BASIC_LDFLAGS_JVM_ONLY="-Wl,-z,noexecstack -Wl,-O1 -Wl,-z,relro"
  78 
  79     BASIC_LDFLAGS_JDK_LIB_ONLY="-Wl,-z,noexecstack"
  80     LIBJSIG_NOEXECSTACK_LDFLAGS="-Wl,-z,noexecstack"
  81 
  82   elif test "x$TOOLCHAIN_TYPE" = xclang; then
  83     BASIC_LDFLAGS_JVM_ONLY="-mno-omit-leaf-frame-pointer -mstack-alignment=16 \
  84         -fPIC"
  85 
  86   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
  87     BASIC_LDFLAGS="-Wl,-z,defs"
  88     BASIC_LDFLAGS_ONLYCXX="-norunpath"
  89     BASIC_LDFLAGS_ONLYCXX_JDK_ONLY="-xnolib"
  90 
  91     BASIC_LDFLAGS_JDK_ONLY="-ztext"
  92     BASIC_LDFLAGS_JVM_ONLY="-library=%none -mt -z noversion"
  93 
  94   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
  95     BASIC_LDFLAGS="-b64 -brtl -bnolibpath -bexpall -bernotok -btextpsize:64K \
  96         -bdatapsize:64K -bstackpsize:64K"
  97     # libjvm.so has gotten too large for normal TOC size; compile with qpic=large and link with bigtoc
  98     BASIC_LDFLAGS_JVM_ONLY="-Wl,-lC_r -bbigtoc"
  99 
 100   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 101     BASIC_LDFLAGS="-nologo -opt:ref"
 102     BASIC_LDFLAGS_JDK_ONLY="-incremental:no"
 103     BASIC_LDFLAGS_JVM_ONLY="-opt:icf,8 -subsystem:windows"






 104   fi
 105 
 106   # Setup OS-dependent LDFLAGS
 107   if test "x$TOOLCHAIN_TYPE" = xclang || test "x$TOOLCHAIN_TYPE" = xgcc; then
 108     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 109       # Assume clang or gcc.
 110       # FIXME: We should really generalize SET_SHARED_LIBRARY_ORIGIN instead.
 111       OS_LDFLAGS_JVM_ONLY="-Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/.."
 112       OS_LDFLAGS_JDK_ONLY="-mmacosx-version-min=$MACOSX_VERSION_MIN"
 113     fi
 114   fi
 115 
 116   # Setup debug level-dependent LDFLAGS
 117   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 118     if test "x$OPENJDK_TARGET_OS" = xlinux; then
 119       if test x$DEBUG_LEVEL = xrelease; then
 120         DEBUGLEVEL_LDFLAGS_JDK_ONLY="$DEBUGLEVEL_LDFLAGS_JDK_ONLY -Wl,-O1"
 121       else
 122         # mark relocations read only on (fast/slow) debug builds
 123         DEBUGLEVEL_LDFLAGS_JDK_ONLY="-Wl,-z,relro"




  57   AC_SUBST(LDFLAGS_TESTEXE)
  58 ])
  59 
  60 ################################################################################
  61 
  62 # CPU independent LDFLAGS setup, used for both target and build toolchain.
  63 AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
  64 [
  65   # Setup basic LDFLAGS
  66   if test "x$TOOLCHAIN_TYPE" = xgcc; then
  67     # If this is a --hash-style=gnu system, use --hash-style=both, why?
  68     # We have previously set HAS_GNU_HASH if this is the case
  69     if test -n "$HAS_GNU_HASH"; then
  70       BASIC_LDFLAGS="-Wl,--hash-style=both"
  71       LIBJSIG_HASHSTYLE_LDFLAGS="-Wl,--hash-style=both"
  72     fi
  73 
  74     # Add -z defs, to forbid undefined symbols in object files.
  75     BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,-z,defs"
  76 
  77     BASIC_LDFLAGS_JVM_ONLY="-Wl,-O1 -Wl,-z,relro"
  78 


  79 
  80   elif test "x$TOOLCHAIN_TYPE" = xclang; then
  81     BASIC_LDFLAGS_JVM_ONLY="-mno-omit-leaf-frame-pointer -mstack-alignment=16 \
  82         -fPIC"
  83 
  84   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
  85     BASIC_LDFLAGS="-Wl,-z,defs"
  86     BASIC_LDFLAGS_ONLYCXX="-norunpath"
  87     BASIC_LDFLAGS_ONLYCXX_JDK_ONLY="-xnolib"
  88 
  89     BASIC_LDFLAGS_JDK_ONLY="-ztext"
  90     BASIC_LDFLAGS_JVM_ONLY="-library=%none -mt -z noversion"
  91 
  92   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
  93     BASIC_LDFLAGS="-b64 -brtl -bnolibpath -bexpall -bernotok -btextpsize:64K \
  94         -bdatapsize:64K -bstackpsize:64K"
  95     # libjvm.so has gotten too large for normal TOC size; compile with qpic=large and link with bigtoc
  96     BASIC_LDFLAGS_JVM_ONLY="-Wl,-lC_r -bbigtoc"
  97 
  98   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
  99     BASIC_LDFLAGS="-nologo -opt:ref"
 100     BASIC_LDFLAGS_JDK_ONLY="-incremental:no"
 101     BASIC_LDFLAGS_JVM_ONLY="-opt:icf,8 -subsystem:windows"
 102   fi
 103 
 104   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 105     if test -n "$HAS_NOEXECSTACK"; then
 106       BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,-z,noexecstack"
 107     fi
 108   fi
 109 
 110   # Setup OS-dependent LDFLAGS
 111   if test "x$TOOLCHAIN_TYPE" = xclang || test "x$TOOLCHAIN_TYPE" = xgcc; then
 112     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 113       # Assume clang or gcc.
 114       # FIXME: We should really generalize SET_SHARED_LIBRARY_ORIGIN instead.
 115       OS_LDFLAGS_JVM_ONLY="-Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/.."
 116       OS_LDFLAGS_JDK_ONLY="-mmacosx-version-min=$MACOSX_VERSION_MIN"
 117     fi
 118   fi
 119 
 120   # Setup debug level-dependent LDFLAGS
 121   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 122     if test "x$OPENJDK_TARGET_OS" = xlinux; then
 123       if test x$DEBUG_LEVEL = xrelease; then
 124         DEBUGLEVEL_LDFLAGS_JDK_ONLY="$DEBUGLEVEL_LDFLAGS_JDK_ONLY -Wl,-O1"
 125       else
 126         # mark relocations read only on (fast/slow) debug builds
 127         DEBUGLEVEL_LDFLAGS_JDK_ONLY="-Wl,-z,relro"


< prev index next >