+
+# 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 { [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
+ 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 ""
+ }
+}