]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - ld/testsuite/config/default.exp
Emit a warning when -z relro is unsupported
[thirdparty/binutils-gdb.git] / ld / testsuite / config / default.exp
index 1d3ce6a03f1462704a17c87f17bdb9524068d7e6..9e89ca1283472c2ab071fb65104007e3246f7a1a 100644 (file)
@@ -1,6 +1,5 @@
 # Basic expect script for LD Regression Tests
-#   Copyright 1993, 1994, 1995, 1997, 1998, 1999, 2001, 2003, 2005, 2007, 2009
-#   2011, 2012 Free Software Foundation, Inc.
+#   Copyright (C) 1993-2020 Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
@@ -50,33 +49,30 @@ if ![info exists strip] then {
     set strip [findfile $base_dir/../binutils/strip-new $base_dir/../binutils/strip-new [transform strip]]
 }
 
-remote_exec host "mkdir -p tmpdir"
-
-# Make a symlink from tmpdir/as to the assembler in the build tree, so
-# that we can use a -B option to gcc to force it to use the newly
-# built assembler.
-if {![file isdirectory tmpdir/gas]} then {
-    catch "exec mkdir tmpdir/gas" status
-    catch "exec ln -s ../../../gas/as-new tmpdir/gas/as" status
+if ![info exists size] then {
+    set size [findfile $base_dir/../binutils/size]
 }
-set gcc_gas_flag "-B[pwd]/tmpdir/gas/"
 
-# Make a symlink from tmpdir/ld to the linker in the build tree, so
-# that we can use a -B option to gcc to force it to use the newly
-# built linker. 
+remote_exec host "mkdir -p tmpdir"
+
+# Make symlinks from tmpdir/ld to the linker and assembler in the
+# build tree, so that we can use a -B option to gcc to force it to use
+# the newly built linker and assembler. 
 if {![file isdirectory tmpdir/ld]} then {
     catch "exec mkdir tmpdir/ld" status
     catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
     catch "exec ln -s ld tmpdir/ld/collect-ld" status
+    catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
 }
-set gcc_ld_flag "-B[pwd]/tmpdir/ld/"
+set gcc_B_opt "-B[pwd]/tmpdir/ld/"
 
 # load the linker path
+set ld_L_opt ""
 if {[file exists tmpdir/libpath.exp]} {
     load_lib tmpdir/libpath.exp
 
     foreach dir $libpath {
-       set gcc_ld_flag "$gcc_ld_flag -L$dir"
+       append ld_L_opt " -L$dir"
     }
 }
 
@@ -96,6 +92,55 @@ if {![info exists CXXFLAGS]} {
     set CXXFLAGS ""
 }
 
+# This allows us to run the linker testsuite with clang as the compilation
+# driver instead of gcc.  The syntax of the overrides are as follows, one
+# per line:
+#
+#  '#': Silence information about the changes to the command line arguments.
+#
+#  '^': Add FOO as a new argument at the beginning of the command line.
+#
+#  '+': Add FOO as a new argument at the end of the command line.
+#
+#  's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
+#  line.
+#
+#  'xOPTION': Removes all instances of the literal argument OPTION.
+#
+#  'XOPTION': Removes all instances of the literal argument OPTION,
+#  and the following argument.
+#
+#  'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
+#  at the end of the command line.
+#
+# \param OS - The stream to write edit information to.
+# \param Args - The vector of command line arguments.
+# \param Edit - The override command to perform.
+# \param SavedStrings - Set to use for storing string representations.
+
+# Only set up the environment variable if the user has not already provided one.
+if {! [info exists env(CCC_OVERRIDE_OPTIONS)]} {
+    set env(CCC_OVERRIDE_OPTIONS) "#\
+  +-Wno-unused-command-line-argument \
+  +-Wno-unknown-attributes \
+  +-Wno-tautological-compare \
+  +-Wno-ignored-optimization-argument \
+  +-Wno-deprecated \
+  +-fuse-ld=$ld \
+  x-Wa,--elf-stt-common=yes \
+  x-Wa,-mx86-used-note=no \
+  x-Wa,-mx86-used-note=yes \
+  x-Wa,-madd-bnd-prefix \
+  x-fno-early-inlining \
+  x-fno-toplevel-reorder \
+  x-flto-partition=none \
+  x-feliminate-dwarf2-dups \
+  s/-Wa,-mrelax-relocations=yes,-mx86-used-note=yes/-Wa,-mrelax-relocations=yes/ \
+  s/-Wa,--compress-debug-sections=zlib/-Wa,-compress-debug-sections=zlib/ \
+  s/-Wa,--compress-debug-sections=zlib-gabi/-Wa,-compress-debug-sections=zlib-gabi/ \
+"
+}
+
 # The mips64-*-linux-gnu compiler defaults to the N32 ABI after
 # installed, but to the O32 ABI in the build tree, because of some
 # specs-file hacks.  Make sure we use an ABI that is compatible with
@@ -104,32 +149,17 @@ if {[istarget mips64*-*-linux*] &&
     (![board_info [target_info name] exists multilib_flags] ||
      ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
    } {
-    append gcc_gas_flag " -mabi=n32"
+    append gcc_B_opt " -mabi=n32"
+}
+
+if { [istarget rx-*-*] } {
+    global ASFLAGS
+    set ASFLAGS "-muse-conventional-section-names"
 }
 
 # load the utility procedures
 load_lib ld-lib.exp
 
-proc get_link_files {varname} {
-    global $varname
-    global target_triplet
-    global srcdir
-    global CC
-    if ![info exists $varname] {
-       #configure.host returns variables that can be substituted into
-       #makefile rules, with embedded shell variable expansions.
-       #make wants $$shell_var, we want $shell_var ...
-       set cmd "host='$target_triplet' && . $srcdir/../configure.host && sed -e 's,\\\$\\\$,\$,g' <<EOF\n\$$varname\nEOF"
-       set status [catch "exec sh -c [list $cmd]" result]
-       if $status { error "Error getting native link files: $result" }
-       set cmd "CC='$CC' && eval echo \"$result\""
-       set status [catch "exec sh -c [list $cmd]" result]
-       if $status { error "Error getting native link files: $result" }
-       set $varname $result
-       send_log "$varname = $result\n"
-    }
-}
-
 proc get_target_emul {} {
     global target_triplet
     global srcdir
@@ -138,13 +168,6 @@ proc get_target_emul {} {
     return $result
 }
 
-if [isnative] {
-    foreach x {HOSTING_CRT0 HOSTING_SCRT0 HOSTING_LIBS HOSTING_SLIBS} {
-       get_link_files $x
-    }
-} else {
-    foreach x {HOSTING_CRT0 HOSTING_SCRT0 HOSTING_LIBS HOSTING_SLIBS} { set $x "" }
-}
 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
 
 #
@@ -185,14 +208,6 @@ proc ld_link { ld target objects } {
        default_ld_link $ld $target $objects
 }
 
-#
-# ld_simple_link 
-#      link a program using ld, without including any libraries
-#
-proc ld_simple_link { ld target objects } {
-       default_ld_simple_link $ld $target $objects
-}
-
 #
 # ld_compile 
 #      compile an object using $cc
@@ -238,10 +253,6 @@ if ![info exists AS] then {
     set AS $as
 }
 
-if ![info exists GASP] then {
-    set GASP [findfile $base_dir/../gas/gasp-new $base_dir/../gas/gasp-new [transform gasp]]
-}
-
 if ![info exists ASFLAGS] then {
     set ASFLAGS ""
 }
@@ -278,6 +289,10 @@ if ![info exists READELFFLAGS] then {
     set READELFFLAGS {}
 }
 
+if ![info exists ELFEDIT] then {
+    set ELFEDIT [findfile $base_dir/../binutils/elfedit]
+}
+
 if ![info exists LD] then {
     set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
 }
@@ -285,3 +300,316 @@ if ![info exists LD] then {
 if ![info exists LDFLAGS] then {
     set LDFLAGS {}
 }
+
+# Set LD_CLASS to "64bit" for a 64-bit *host* linker.
+if { ![info exists LD_CLASS] } then {
+    set REAL_LD [findfile $base_dir/.libs/ld-new .libs/ld-new $LD [transform ld]]
+    set readelf_output [run_host_cmd "$READELF" "-h $REAL_LD"]
+    if { [regexp {[ \t]+Class:[ \t]+ELF64} $readelf_output] } then {
+       set LD_CLASS "64bit"
+    } else {
+       set LD_CLASS "32bit"
+    }
+}
+
+# Set PLT_CFLAGS to "-fplt" if target compiler supports it.
+
+if { ![info exists PLT_CFLAGS] } then {
+    if { [check_compiler_available] } {
+       # Check if gcc supports -fplt
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/plt[pid]"
+       set src ${basename}.c
+       set output ${basename}.o
+       set f [open $src "w"]
+       puts $f ""
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set plt_available [run_host_cmd_yesno "$CC" "$flags -c -fplt $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+
+       if { $plt_available == 1 } then {
+           set PLT_CFLAGS "-fplt"
+       } else {
+           set PLT_CFLAGS ""
+       }
+    } else {
+       set PLT_CFLAGS ""
+    }
+}
+
+# Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
+# target compiler supports them.
+
+if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
+    if { [check_compiler_available] } {
+       # Check if gcc supports -fno-PIE -no-pie.
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/nopie[pid]"
+       set src ${basename}.c
+       set output ${basename}
+       set f [open $src "w"]
+       puts $f "int main (void) { return 0; }"
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set nopie_available [run_host_cmd_yesno "$CC" "$flags -fno-PIE -no-pie $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+
+       if { $nopie_available == 1 } then {
+           set NOPIE_CFLAGS "-fno-PIE"
+           set NOPIE_LDFLAGS "-no-pie"
+       } else {
+           set NOPIE_CFLAGS ""
+           set NOPIE_LDFLAGS ""
+       }
+    } else {
+       set NOPIE_CFLAGS ""
+       set NOPIE_LDFLAGS ""
+    }
+}
+
+# Set NOCF_PROTECTION_CFLAGS to "-fcf-protection=none" if target compiler
+# supports it.
+
+if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
+    if { [check_compiler_available] } {
+       # Check if gcc supports -fcf-protection=none.
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/available[pid]"
+       set src ${basename}.c
+       set output ${basename}
+       set f [open $src "w"]
+       puts $f "int main (void) { return 0; }"
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set available [run_host_cmd_yesno "$CC" "$flags -fcf-protection=none $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+
+       if { $available == 1 } then {
+           set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
+       } else {
+           set NOCF_PROTECTION_CFLAGS ""
+       }
+    } else {
+       set NOCF_PROTECTION_CFLAGS ""
+    }
+}
+
+# Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
+
+if { ![info exists GNU2_CFLAGS] } then {
+    if { [check_compiler_available] } {
+       # Check if gcc supports -mtls-dialect=gnu2
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/gnu2[pid]"
+       set src ${basename}.c
+       set output ${basename}.o
+       set f [open $src "w"]
+       puts $f "__thread int yyy = 100;"
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set gnu2_available [run_host_cmd_yesno "$CC" "$flags -c -mtls-dialect=gnu2 $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+
+       if { $gnu2_available == 1 } then {
+           set GNU2_CFLAGS "-mtls-dialect=gnu2"
+       } else {
+           set GNU2_CFLAGS ""
+       }
+    } else {
+       set GNU2_CFLAGS ""
+    }
+}
+
+# Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
+
+if { ![info exists INT128_CFLAGS] } then {
+    if { [check_compiler_available] } {
+       # Check if gcc supports __int128.
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/int128[pid]"
+       set src ${basename}.c
+       set output ${basename}.o
+       set f [open $src "w"]
+       puts $f "__int128 a = 42;"
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set int128_available [run_host_cmd_yesno "$CC" "$flags -c $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+
+       if { $int128_available == 1 } then {
+           set INT128_CFLAGS "-DHAS_INT128"
+       } else {
+           set INT128_CFLAGS ""
+       }
+    } else {
+       set INT128_CFLAGS ""
+    }
+}
+
+# Set STATIC_LDFLAGS to "-static" if target compiler supports it.
+
+if { ![info exists STATIC_LDFLAGS] } then {
+    if { [check_compiler_available] } {
+       # Check if gcc supports -static.
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/static[pid]"
+       set src ${basename}.c
+       set output ${basename}
+       set f [open $src "w"]
+       puts $f "int main (void) { return 0; }"
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set static_available [run_host_cmd_yesno "$CC" "-static $flags $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+
+       if { $static_available == 1 } then {
+           set STATIC_LDFLAGS "-static"
+       } else {
+           set STATIC_LDFLAGS ""
+       }
+    } else {
+       set STATIC_LDFLAGS ""
+    }
+}
+
+# Set STATIC_PIE_LDFLAGS to "-static-pie" if target compiler supports it.
+
+if { ![info exists STATIC_PIE_LDFLAGS] } then {
+    if { [check_compiler_available] } {
+       # Check if gcc supports -static-pie.
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/static[pid]"
+       set src ${basename}.c
+       set output ${basename}
+       set f [open $src "w"]
+       puts $f "int main (void) { return 0; }"
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set static_available [run_host_cmd_yesno "$CC" "-static-pie $flags $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+
+       if { $static_available == 1 } then {
+           set STATIC_PIE_LDFLAGS "-static-pie"
+       } else {
+           set STATIC_PIE_LDFLAGS ""
+       }
+    } else {
+       set STATIC_PIE_LDFLAGS ""
+    }
+}
+
+# Set NOSANTIZE_CFLAGS to "-fno-sanitize=all" if target compiler
+# supports it.
+
+if { ![info exists NOSANTIZE_CFLAGS] } then {
+    if { [check_compiler_available] } {
+       # Check if gcc supports -fno-sanitize=all.
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/available[pid]"
+       set src ${basename}.c
+       set output ${basename}
+       set f [open $src "w"]
+       puts $f "int main (void) { return 0; }"
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set available [run_host_cmd_yesno "$CC" "$flags -fno-sanitize=all $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+
+       if { $available == 1 } then {
+           set NOSANTIZE_CFLAGS "-fno-sanitize=all"
+       } else {
+           set NOSANTIZE_CFLAGS ""
+       }
+    } else {
+       set NOSANTIZE_CFLAGS ""
+    }
+}