# Basic expect script for LD Regression Tests
-# Copyright (C) 1993-2018 Free Software Foundation, Inc.
+# Copyright (C) 1993-2021 Free Software Foundation, Inc.
#
# This file is part of the GNU Binutils.
#
}
}
-# Many ELF testcases expect that "-z relro" is off.
-set ld_elf_shared_opt "-z norelro"
-
# The "make check" target in the Makefile passes in
# "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
# (as when testing an installed linker), these flags may not be set.
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
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]]
}
}
}
-# Set PLT_CFLAGS to "-fplt" if target compiler supports it.
-
-if { ![info exists PLT_CFLAGS] } then {
- if { [which $CC] != 0 } {
- # Check if gcc supports -fplt
+# Compiler tests
+proc compiler_supports { flag args } {
+ if { [check_compiler_available] } {
+ global CC
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"
+ set fn "cs[pid].c"
+ set f [open $fn "w"]
+ if { [llength $args] > 0 } {
+ puts $f [lindex $args 0]
} else {
- set PLT_CFLAGS ""
+ puts $f "int main (void) { return 0; }"
}
- } else {
- set PLT_CFLAGS ""
+ close $f
+ set rfn [remote_download host $fn]
+ set avail [run_host_cmd_yesno "$CC" "$flags $flag $rfn -o /dev/null"]
+ remote_file host delete $rfn
+ file delete $fn
+ return $avail
}
+ return 0
}
-# Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
-# target compiler supports them.
+if { ![info exists PLT_CFLAGS] } then {
+ set PLT_CFLAGS ""
+ if [compiler_supports "-c -fplt"] {
+ set PLT_CFLAGS "-fplt"
+ }
+}
if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
- if { [which $CC] != 0 } {
- # 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 NOPIE_CFLAGS ""
+ set NOPIE_LDFLAGS ""
+ if [compiler_supports "-fno-PIE -no-pie"] {
+ set NOPIE_CFLAGS "-fno-PIE"
+ set NOPIE_LDFLAGS "-no-pie"
}
}
-# Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
+if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
+ set NOCF_PROTECTION_CFLAGS ""
+ if [compiler_supports "-fcf-protection=none"] {
+ set NOCF_PROTECTION_CFLAGS "-fcf-protection=none"
+ }
+}
if { ![info exists GNU2_CFLAGS] } then {
- if { [which $CC] != 0 } {
- # 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 GNU2_CFLAGS ""
+ if [compiler_supports "-c -mtls-dialect=gnu2" "__thread int y = 1;"] {
+ set GNU2_CFLAGS "-mtls-dialect=gnu2"
+ }
+}
- 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]
+if { ![info exists INT128_CFLAGS] } then {
+ set INT128_CFLAGS ""
+ if [compiler_supports "-c" "__int128 a = 42;"] {
+ set INT128_CFLAGS "-DHAS_INT128"
+ }
+}
+
+if { ![info exists STATIC_LDFLAGS] } then {
+ set STATIC_LDFLAGS ""
+ if [compiler_supports "-static"] {
+ set STATIC_LDFLAGS "-static"
+ }
+}
+
+if { ![info exists STATIC_PIE_LDFLAGS] } then {
+ set STATIC_PIE_LDFLAGS ""
+ if [compiler_supports "-static-pie"] {
+ set STATIC_PIE_LDFLAGS "-static-pie"
+ }
+}
+
+if { ![info exists NOSANITIZE_CFLAGS] } then {
+ set NOSANITIZE_CFLAGS ""
+ if [compiler_supports "-fno-sanitize=all"] {
+ set NOSANITIZE_CFLAGS "-fno-sanitize=all"
+ }
+}
+
+if { ![info exists NOLTO_CFLAGS] } then {
+ set NOLTO_CFLAGS ""
+ if [compiler_supports "-fno-lto"] {
+ set NOLTO_CFLAGS "-fno-lto"
+ }
+}
+
+# Provide dummy libraries that alpha-vms-ld always loads
+if { [istarget alpha*-*-*vms*] } {
+ set src tmpdir/empty.s
+ set f [open $src "w"]
+ close $f
+ if { [ld_assemble $as $src tmpdir/empty.o]
+ && ![ld_link $LD tmpdir/empty tmpdir/empty.o]
+ && [regsub -all {[^\n]*: cannot find -l([^\n]*)} $exec_output {tmpdir/lib\1.a } missing_libs] } {
+ regsub -all {\$} $missing_libs {\\\$} missing_libs
+ for { set i 0 } { $i < [llength $missing_libs] } { incr i } {
+ set f [lindex $missing_libs $i]
+ verbose -log "creating dummy $f"
+ ar_simple_create $ar {} $f tmpdir/empty.o
}
- 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
+ append LDFLAGS " -Ltmpdir"
+ unset i missing_libs
+ }
+ unset f src
+}
- if { $gnu2_available == 1 } then {
- set GNU2_CFLAGS "-mtls-dialect=gnu2"
- } else {
- set GNU2_CFLAGS ""
+set plug_opt ""
+if { [check_compiler_available] } {
+ set plugin_names {
+ liblto_plugin.so
+ liblto_plugin-0.dll
+ cyglto_plugin-0.dll
+ }
+ foreach plug $plugin_names {
+ set plug_so [run_host_cmd $CC "--print-prog-name $plug"]
+ if { $plug_so eq $plug } then {
+ set plug_so [run_host_cmd $CC "--print-file-name $plug"]
+ }
+ if { $plug_so ne $plug } then {
+ set plug_opt "--plugin $plug_so"
+ break
}
- } else {
- set GNU2_CFLAGS ""
}
}
+
+if {[file exists .libs/libdep.so]} {
+ set dep_plug_opt "--plugin .libs/libdep.so"
+} elseif {[file exists .libs/libdep.dll]} {
+ set dep_plug_opt "--plugin .libs/libdep.dll"
+} else {
+ set dep_plug_opt ""
+}