+2020-06-03 H.J. Lu <hongjiu.lu@intel.com>
+
+ * testsuite/config/default.exp (NOSANTIZE_CFLAGS): New.
+ * testsuite/ld-elf/linux-x86.exp: Add $NOSANTIZE_CFLAGS to
+ tests with run_ld_link_exec_tests.
+ * testsuite/ld-elf/shared.exp: Add $NOSANTIZE_CFLAGS to tests
+ with run_ld_link_tests.
+ * testsuite/ld-elf/tls.exp: Likewise.
+ * testsuite/ld-elfweak/elfweak.exp: Add $NOSANTIZE_CFLAGS to
+ tests with ld_link.
+ * testsuite/ld-gc/gc.exp: Add $NOSANTIZE_CFLAGS to cflags.
+ * testsuite/ld-plugin/lto.exp: Add $NOSANTIZE_CFLAGS to tests
+ with run_ld_link_tests.a
+ * testsuite/ld-plugin/plugin.exp: Append $NOSANTIZE_CFLAGS to
+ CFLAGS.
+ * testsuite/ld-selective/selective.exp: Add $NOSANTIZE_CFLAGS
+ to cflags and cxxflags.
+ * testsuite/ld-srec/srec.exp: Append $NOSANTIZE_CFLAGS to CC
+ and CXX.
+ * testsuite/ld-x86-64/plt-main-ibt-x32.dd: Updated for
+ -fsanitize=undefined.
+ * testsuite/ld-x86-64/plt-main-ibt.dd: Likewise.
+ * testsuite/ld-x86-64/x86-64.exp: Add $NOSANTIZE_CFLAGS to
+ tests with run_cc_link_tests and run_ld_link_tests.
+
2020-06-03 Fangrui Song <maskray@google.com>
H.J. Lu <hongjiu.lu@intel.com>
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 ""
+ }
+}
global PLT_CFLAGS
# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
global NOPIE_CFLAGS NOPIE_LDFLAGS
+global NOSANTIZE_CFLAGS
run_ld_link_exec_tests [list \
[list \
{ linux-x86.S pr23428.c dummy.s } \
"pr23428" \
"pass.out" \
- "$NOPIE_CFLAGS -fno-asynchronous-unwind-tables" \
+ "$NOPIE_CFLAGS $NOSANTIZE_CFLAGS -fno-asynchronous-unwind-tables" \
"asm" \
] \
]
# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
global NOPIE_CFLAGS NOPIE_LDFLAGS
+global NOSANTIZE_CFLAGS
set old_ASFLAGS $ASFLAGS
{ pr23161a.c } \
{{readelf {--dyn-syms -rW} pr23161a.rd}} \
"libpr23161a.so" \
- "-fPIC -O2" \
+ "-fPIC -O2 $NOSANTIZE_CFLAGS" \
] \
[list \
"Build pr23161a" \
{ pr23161b.c } \
{{readelf {--dyn-syms -rW} pr23161b.rd}} \
"pr23161a" \
- "-fPIC -O0" \
+ "-fPIC -O0 $NOSANTIZE_CFLAGS" \
] \
[list \
"Build libpr23161b.so" \
{ pr23161a.c } \
{{readelf {--dyn-syms -rW} pr23161a.rd}} \
"libpr23161b.so" \
- "-fPIC -O2" \
+ "-fPIC -O2 $NOSANTIZE_CFLAGS" \
] \
[list \
"Build pr23161b" \
{ pr23161b.c } \
{{readelf {--dyn-syms -rW} pr23161b.rd}} \
"pr23161b" \
- "-fPIC -O0" \
+ "-fPIC -O0 $NOSANTIZE_CFLAGS" \
] \
]
}
{ pr23161c.c } \
{{readelf {--dyn-syms -rW} pr23161c.rd}} \
"libpr23161c.so" \
- "-fPIC -O2" \
+ "-fPIC -O2 $NOSANTIZE_CFLAGS" \
] \
[list \
"Build pr23161c" \
{ pr23161b.c } \
{{readelf {--dyn-syms -rW} pr23161d.rd}} \
"pr23161c" \
- "-fPIC -O0" \
+ "-fPIC -O0 $NOSANTIZE_CFLAGS" \
] \
]
}
append AFLAGS_PIC " -K PIC"
}
+global NOSANTIZE_CFLAGS
+
run_ld_link_tests [list \
[list \
"Build pr22263-1" \
{ pr22263-1a.c pr22263-1b.c } \
{{readelf -r pr22263-1.rd}} \
"pr22263-1" \
- "-fPIE -O2" \
+ "-fPIE -O2 $NOSANTIZE_CFLAGS" \
] \
]
set SOBJDUMP_FLAGS --syms
set shared "--shared -Wl,--no-as-needed"
+global NOSANTIZE_CFLAGS
#
# objdump_symstuff
global srcdir
global subdir
global exec_output
+ global NOSANTIZE_CFLAGS
set files ""
foreach obj $objs {
set files "$files $tmpdir/$obj"
}
- if {![ld_link $CC $tmpdir/$execname "$flags $files"]} {
+ if {![ld_link $CC $tmpdir/$execname "$flags $NOSANTIZE_CFLAGS $files"]} {
fail "$test"
return
}
if {![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/alias.c $tmpdir/alias.o]
|| ![ld_link $CC $tmpdir/alias.so "$shared $tmpdir/alias.o"]
- || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/aliasmain.c $tmpdir/aliasmain.o]
+ || ![ld_compile "$CC $CFLAGS $NOSANTIZE_CFLAGS" $srcdir/$subdir/aliasmain.c $tmpdir/aliasmain.o]
|| ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/weakref1.c $tmpdir/weakref1.o]
|| ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/weakref2.c $tmpdir/weakref2.o]} then {
unresolved "ELF weak (alias)"
return
}
-set cflags "-ffunction-sections -fdata-sections"
+global NOSANTIZE_CFLAGS
+
+set cflags "-ffunction-sections -fdata-sections $NOSANTIZE_CFLAGS"
set objfile "tmpdir/gc.o"
# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS
regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS
+global NOSANTIZE_CFLAGS
+
proc restore_notify { } {
global saved_CFLAGS
global saved_CXXFLAGS
"-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \
{lto-1a.c lto-1b.c} {} "lto-1.exe"] \
[list "Compile 2" \
- "" "-O2 -flto -fuse-linker-plugin" \
+ "" "-O2 -flto -fuse-linker-plugin $NOSANTIZE_CFLAGS" \
{lto-2.c} {} ""] \
[list "LTO 2" \
- "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" "" \
+ "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" \
+ "$NOSANTIZE_CFLAGS" \
{dummy.c} {} "lto-2.exe"] \
[list "Compile 3a" \
"" "-flto" \
"" "" \
{pr12758a.s} {} ""] \
[list "Build libpr12758.a" \
- "" "-flto -O2 $lto_fat" \
+ "" "-flto -O2 $lto_fat $NOSANTIZE_CFLAGS" \
{pr12758b.c} {} "libpr12758.a"] \
[list "PR ld/12758" \
- "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" "" \
+ "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" \
+ "$NOSANTIZE_CFLAGS" \
{dummy.c} {} "pr12758.exe"] \
[list "Compile PR ld/12760" \
"" "-g -O0" \
set failed_compile 0
set _ ""
set plugin_nm_output ""
+global NOSANTIZE_CFLAGS
+set old_CFLAGS "$CFLAGS"
+append CFLAGS " $NOSANTIZE_CFLAGS"
if { $can_compile && \
(![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c tmpdir/main.o] \
|| ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/func.c tmpdir/func.o] \
# Defer fail until we have list of tests set.
set failed_compile 1
}
+set CFLAGS "$old_CFLAGS"
set dotsym 0
if { $can_compile && !$failed_compile } {
{A::foo() B::foo() dropme1() dropme2()} {*-*-*}}
}
-set cflags "-w -O -ffunction-sections -fdata-sections"
-set cxxflags "-fno-exceptions -fno-rtti"
+global NOSANTIZE_CFLAGS
+set cflags "-w -O -ffunction-sections -fdata-sections $NOSANTIZE_CFLAGS"
+set cxxflags "-fno-exceptions -fno-rtti $NOSANTIZE_CFLAGS"
set ldflags "--gc-sections -Bstatic"
if [istarget mips*-*] {
# Pass -fplt to CC and CXX since -fno-plt doesn't work with S-records
# tests. Also add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if PIE doesn't work
# with S-records. Also add $NOCF_PROTECTION_CFLAGS for S-records.
-global PLT_CFLAGS NOPIE_CFLAGS NOPIE_LDFLAGS NOCF_PROTECTION_CFLAGS
+# Also add $NOSANTIZE_CFLAGS for S-records.
+global PLT_CFLAGS NOPIE_CFLAGS NOPIE_LDFLAGS NOCF_PROTECTION_CFLAGS NOSANTIZE_CFLAGS
set old_CC "$CC"
-set CC "$CC $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS"
+set CC "$CC $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANTIZE_CFLAGS"
set old_CXX "$CXX"
-set CXX "$CXX $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS"
+set CXX "$CXX $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANTIZE_CFLAGS"
# S-records can't handle .note.gnu.property sections.
if { [is_elf_format] \
[a-f0-9]+ <[_a-z]+@plt>:
[ ]*[a-f0-9]+: f3 0f 1e fa endbr64
-[ ]*[a-f0-9]+: ff 25 .. .. 20 00 jmpq +\*0x20....\(%rip\) # ...... <[_a-z]+>
+[ ]*[a-f0-9]+: ff 25 .. .. 20 00 jmpq +\*0x20....\(%rip\) # ...... <.*>
#pass
[a-f0-9]+ <[_a-z]+@plt>:
[ ]*[a-f0-9]+: f3 0f 1e fa endbr64
-[ ]*[a-f0-9]+: f2 ff 25 .. .. 20 00 bnd jmpq \*0x20....\(%rip\) # ...... <[_a-z]+>
+[ ]*[a-f0-9]+: f2 ff 25 .. .. 20 00 bnd jmpq \*0x20....\(%rip\) # ...... <.*>
#pass
global NOPIE_CFLAGS NOPIE_LDFLAGS
# Add $NOCF_PROTECTION_CFLAGS if -fcf-protection=none is required.
global NOCF_PROTECTION_CFLAGS
+global NOSANTIZE_CFLAGS
# Must be native with the C compiler
if { [isnative] && [check_compiler_available] } {
- run_cc_link_tests {
- {"Helper X32 DSO from x86-64 object" "" "-m64 -fPIC -g"
- {simple.c} {} "libsimple.a"}
- }
+ run_cc_link_tests [list \
+ [list \
+ "Helper X32 DSO from x86-64 object" "" \
+ "-m64 $NOSANTIZE_CFLAGS -fPIC -g" \
+ {simple.c} {} "libsimple.a" \
+ ] \
+ ]
set convertx32 "$objcopy -O elf32-x86-64 tmpdir/simple.o tmpdir/simple-x32.o"
send_log "$convertx32\n"
return
}
- run_ld_link_tests {
- {"X32 DSO from x86-64 object"
- "-shared -melf32_x86_64 tmpdir/simple-x32.o" ""
- "--x32 -mx86-used-note=yes"
- {dummy.s} {{readelf {-s --wide} x86-64-x32.rd}} "x86-64-x32"}
- }
+ run_ld_link_tests [list \
+ [list \
+ "X32 DSO from x86-64 object" \
+ "-shared -melf32_x86_64 tmpdir/simple-x32.o" \
+ "$NOSANTIZE_CFLAGS" \
+ "--x32 -mx86-used-note=yes" \
+ {dummy.s} {{readelf {-s --wide} x86-64-x32.rd}} \
+ "x86-64-x32" \
+ ] \
+ ]
run_cc_link_tests [list \
[list \