+2020-04-02 H.J. Lu <hongjiu.lu@intel.com>
+
+ * testsuite/config/default.exp (NOCF_PROTECTION_CFLAGS): New.
+ Set to "-fcf-protection=none" if target compiler supports it.
+ * testsuite/ld-srec/srec.exp: Add $NOCF_PROTECTION_CFLAGS to
+ CC and CXX.
+ * testsuite/ld-x86-64/x86-64.exp: Add $NOCF_PROTECTION_CFLAGS
+ to PLT BND tests.
+
2020-04-02 H.J. Lu <hongjiu.lu@intel.com>
* testsuite/ld-elf/linux-x86.exp (check_pr25749a): Compile with
}
}
+# 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/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 -fcf-protection=none $src -o $output"]
+ remote_file host delete $src
+ remote_file host delete $output
+ file delete $src
+
+ if { $nopie_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 {
# 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.
-global PLT_CFLAGS NOPIE_CFLAGS NOPIE_LDFLAGS
+# with S-records. Also add $NOCF_PROTECTION_CFLAGS for S-records.
+global PLT_CFLAGS NOPIE_CFLAGS NOPIE_LDFLAGS NOCF_PROTECTION_CFLAGS
set old_CC "$CC"
-set CC "$CC $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS"
+set CC "$CC $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS"
set old_CXX "$CXX"
-set CXX "$CXX $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS"
+set CXX "$CXX $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS"
# S-records can't handle .note.gnu.property sections.
if { [is_elf_format] \
global PLT_CFLAGS
# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
global NOPIE_CFLAGS NOPIE_LDFLAGS
+# Add $NOCF_PROTECTION_CFLAGS if -fcf-protection=none is required.
+global NOCF_PROTECTION_CFLAGS
# Must be native with the C compiler
if { [isnative] && [check_compiler_available] } {
"tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
tmpdir/plt-main4.o tmpdir/libplt-lib.so -z bndplt \
-z noseparate-code -z max-page-size=0x200000" \
- "-Wa,-mx86-used-note=yes" \
+ "-Wa,-mx86-used-note=yes $NOCF_PROTECTION_CFLAGS" \
{ plt-main5.c } \
{{objdump {-drw} plt-main-bnd.dd}} \
"plt-main-bnd" \
"tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
tmpdir/plt-main4.o tmpdir/libplt-lib.so -z bndplt -pie \
-z noseparate-code -z max-page-size=0x200000" \
- "-fPIC -Wa,-mx86-used-note=yes" \
+ "-fPIC -Wa,-mx86-used-note=yes $NOCF_PROTECTION_CFLAGS" \
{ plt-main5.c } \
{{objdump {-drw} plt-main-bnd.dd}} \
"plt-main-pie-bnd" \
"tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
tmpdir/plt-main4.o tmpdir/libplt-lib.so -z bndplt -z now \
-z noseparate-code -z max-page-size=0x200000" \
- "-Wa,-mx86-used-note=yes" \
+ "-Wa,-mx86-used-note=yes $NOCF_PROTECTION_CFLAGS" \
{ plt-main5.c } \
{{readelf {-SW} plt-main-bnd-now.rd} {objdump {-drw} plt-main-bnd.dd}} \
"plt-main-bnd-now" \
"tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
tmpdir/plt-main4.o tmpdir/libplt-lib.so -z bndplt -z now -pie \
-z noseparate-code -z max-page-size=0x200000" \
- "-fPIC -Wa,-mx86-used-note=yes" \
+ "-fPIC -Wa,-mx86-used-note=yes $NOCF_PROTECTION_CFLAGS" \
{ plt-main5.c } \
{{readelf {-SW} plt-main-bnd-now.rd} {objdump {-drw} plt-main-bnd.dd}} \
"plt-main-pie-bnd-now" \