ld: Add NOCF_PROTECTION_CFLAGS to turn off -fcf-protection
[deliverable/binutils-gdb.git] / ld / testsuite / config / default.exp
index 7fa7911cc8e3fa1a37cc698bd9fb1ec4cadb64a0..7998f4efb851e51d065cd6a52f8f395751fb6777 100644 (file)
@@ -344,6 +344,44 @@ if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
     }
 }
 
+# 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 {
This page took 0.024373 seconds and 4 git commands to generate.