This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed, PATCH] Set NOPIE_CFLAGS and NOPIE_LDFLAGS


GCC 6 can be configured to generate PIE by default.  But some linker
size tests expect non-PIE.  This patch defines NOPIE_CFLAGS to
"-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if target compiler supports
them.  Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS to linker size tests if
needed.

	* config/default.exp (NOPIE_CFLAGS): New.
	(NOPIE_LDFLAGS): Likewise.
	* ld-size/size.exp (run_cc_link_tests): Add $NOPIE_CFLAGS and
	$NOPIE_LDFLAGS if needed.
	(run_ld_link_exec_tests): Add $NOPIE_CFLAGS if needed.
---
 ld/testsuite/ChangeLog          |   8 +
 ld/testsuite/config/default.exp |  39 +++++
 ld/testsuite/ld-size/size.exp   | 323 ++++++++++++++++++++++++++++------------
 3 files changed, 276 insertions(+), 94 deletions(-)

diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 75c1547..e42477d 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,5 +1,13 @@
 2015-07-27  H.J. Lu  <hongjiu.lu@intel.com>
 
+	* config/default.exp (NOPIE_CFLAGS): New.
+	(NOPIE_LDFLAGS): Likewise.
+	* ld-size/size.exp (run_cc_link_tests): Add $NOPIE_CFLAGS and
+	$NOPIE_LDFLAGS if needed.
+	(run_ld_link_exec_tests): Add $NOPIE_CFLAGS if needed.
+
+2015-07-27  H.J. Lu  <hongjiu.lu@intel.com>
+
 	* ld-srec/srec.exp (CC): Save and restore.  Append $PLT_CFLAGS.
 	(CXX): Likewise.
 
diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 5acc963..5b3e29f 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -313,3 +313,42 @@ if { ![info exists PLT_CFLAGS] } then {
 	set PLT_CFLAGS ""
     }
 }
+
+# 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 ""
+    }
+}
diff --git a/ld/testsuite/ld-size/size.exp b/ld/testsuite/ld-size/size.exp
index 43bfd20..2a16c71 100644
--- a/ld/testsuite/ld-size/size.exp
+++ b/ld/testsuite/ld-size/size.exp
@@ -61,90 +61,240 @@ if { [which $CC] == 0 } {
     return
 }
 
-set build_tests {
-  {"Build libsize-1.so"
-   "-shared" "-fPIC"
-   {size-1a.c size-1b.c} {} "libsize-1.so"}
-  {"Build libsize-2.so"
-   "-shared" "-fPIC"
-   {size-2a.c size-2b.c} {} "libsize-2.so"}
-  {"Build libsize-3a.so"
-   "-shared" "-fPIC"
-   {size-3a.c} {} "libsize-3a.so"}
-  {"Build libsize-3b.so"
-   "-shared" "-fPIC"
-   {size-3b.c} {} "libsize-3b.so"}
-  {"Build libsize-3c.so"
-   "-shared" "-fPIC"
-   {size-3c.c} {} "libsize-3c.so"}
-  {"Build libsize-6b.so"
-   "-shared" "-fPIC"
-   {size-6b.c} {} "libsize-6b.so"}
-  {"Build libsize-7.so"
-   "-shared" "-fPIC"
-   {size-7b.c} {} "libsize-7.so"}
-  {"Build size-7"
-   "-Wl,--no-as-needed tmpdir/libsize-7.so" ""
-   {size-7a.c} {{readelf -rW size-7.rd}} "size-7.exe"}
-  {"Build libsize-8.so"
-   "-shared" "-fPIC"
-   {size-8b.c} {} "libsize-8.so"}
-  {"Build size-8"
-   "-Wl,--no-as-needed tmpdir/libsize-8.so" ""
-   {size-8a.c} {{readelf -rW size-8.rd}} "size-8.exe"}
-  {"Build libsize-9.so"
-   "-shared" "-fPIC"
-   {size-9b.c} {{readelf -rW size-9.rd}} "libsize-9.so"}
-  {"Build libsize-10.so"
-   "-shared" "-fPIC"
-   {size-10b.c} {{readelf -rW size-10.rd}} "libsize-10.so"}
-}
+# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
+global NOPIE_CFLAGS NOPIE_LDFLAGS
 
-run_cc_link_tests $build_tests
+run_cc_link_tests [list \
+    [list \
+	"Build libsize-1.so" \
+	"-shared" \
+	"-fPIC" \
+	{size-1a.c size-1b.c} \
+	{} \
+	"libsize-1.so" \
+    ] \
+    [list \
+	"Build libsize-2.so" \
+	"-shared" \
+	"-fPIC" \
+	{size-2a.c size-2b.c} \
+	{} \
+	"libsize-2.so" \
+    ] \
+    [list \
+	"Build libsize-3a.so" \
+	"-shared" "-fPIC" \
+	{size-3a.c} \
+	{} \
+	"libsize-3a.so" \
+    ] \
+    [list \
+	"Build libsize-3b.so" \
+	"-shared" \
+	"-fPIC" \
+	{size-3b.c} \
+	{} \
+	"libsize-3b.so" \
+    ] \
+    [list \
+	"Build libsize-3c.so" \
+	"-shared" \
+	"-fPIC" \
+	{size-3c.c} \
+	{} \
+	"libsize-3c.so" \
+    ] \
+    [list \
+	"Build libsize-6b.so" \
+	"-shared" \
+	"-fPIC" \
+	{size-6b.c} \
+	{} \
+	"libsize-6b.so" \
+    ] \
+    [list \
+	"Build libsize-7.so" \
+	"-shared" \
+	"-fPIC" \
+	{size-7b.c} \
+	{} \
+	"libsize-7.so" \
+    ] \
+    [list \
+	"Build size-7" \
+	"$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-7.so" \
+	"$NOPIE_CFLAGS" \
+	{size-7a.c} \
+	{{readelf -rW size-7.rd}} \
+	"size-7.exe" \
+    ] \
+    [list \
+	"Build libsize-8.so" \
+	"-shared" "-fPIC" \
+	{size-8b.c} \
+	{} \
+	"libsize-8.so" \
+    ] \
+    [list \
+	"Build size-8" \
+	"$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-8.so" \
+	"$NOPIE_CFLAGS" \
+	{size-8a.c} \
+	{{readelf -rW size-8.rd}} \
+	"size-8.exe" \
+    ] \
+    [list \
+	"Build libsize-9.so" \
+	"-shared" \
+	"-fPIC" \
+	{size-9b.c} \
+	{{readelf -rW size-9.rd}} \
+	"libsize-9.so" \
+    ] \
+    [list \
+	"Build libsize-10.so" \
+	"-shared" \
+	"-fPIC" \
+	{size-10b.c} \
+	{{readelf -rW size-10.rd}} \
+	"libsize-10.so" \
+    ] \
+]
 
-set run_tests {
-    {"Run size-1"
-     "tmpdir/libsize-1.so" ""
-     {size-1.c} "size-1" "size-1.out"}
-    {"Run size-2"
-     "tmpdir/libsize-2.so" ""
-     {size-2.c} "size-2" "size-2.out"}
-    {"Run size-3a"
-     "" ""
-     {size-3.c size-3a.c} "size-3a" "size-3.out"}
-    {"Run size-3b"
-     "tmpdir/libsize-3a.so" ""
-     {size-3.c} "size-3b" "size-3.out"}
-    {"Run size-3c"
-     "" ""
-     {size-3.c size-3b.c} "size-3c" "size-3.out"}
-    {"Run size-3d"
-     "tmpdir/libsize-3b.so" ""
-     {size-3.c} "size-3d" "size-3.out"}
-    {"Run size-3d"
-     "" ""
-     {size-3.c size-3c.c} "size-3d" "size-3.out"}
+# Run-time size relocation tests.
+run_ld_link_exec_tests [] [list \
+    [list \
+	"Run size-1" \
+	"tmpdir/libsize-1.so" \
+	"" \
+	{size-1.c} \
+	"size-1" \
+	"size-1.out" \
+    ] \
+    [list \
+	"Run size-2" \
+	"tmpdir/libsize-2.so" \
+	"" \
+	{size-2.c} \
+	"size-2" \
+	"size-2.out" \
+    ] \
+    [list \
+	"Run size-3a" \
+	"" \
+	"" \
+	{size-3.c size-3a.c} \
+	"size-3a" \
+	"size-3.out" \
+    ] \
+    [list \
+	"Run size-3b" \
+	"tmpdir/libsize-3a.so" \
+	"" \
+	{size-3.c} \
+	"size-3b" \
+	"size-3.out" \
+    ] \
+    [list \
+	"Run size-3c" \
+	"" \
+	"" \
+	{size-3.c size-3b.c} \
+	"size-3c" \
+	"size-3.out" \
+    ] \
+    [list \
+	"Run size-3d (1)" \
+	"tmpdir/libsize-3b.so" \
+	"" \
+	{size-3.c} \
+	"size-3d1" \
+	"size-3.out" \
+    ] \
+    [list \
+	"Run size-3d (2)" \
+	"" \
+	"" \
+	{size-3.c size-3c.c} \
+	"size-3d2" \
+	"size-3.out" \
+    ] \
+    [list \
     {"Run size-3e"
      "tmpdir/libsize-3c.so" ""
      {size-3.c} "size-3e" "size-3.out"}
-    {"Run size-4a"
-     "" ""
-     {size-4a.c size-4b.c} "size-4a" "size-4.out"}
-    {"Run size-4b"
-     "" ""
-     {size-4b.c size-4a.c} "size-4b" "size-4.out"}
-    {"Run size-5a"
-     "" ""
-     {size-5a.c size-5b.c} "size-5a" "size-5.out"}
-    {"Run size-5b"
-     "" ""
-     {size-5b.c size-5a.c} "size-5b" "size-5.out"}
-    {"Run size-6"
-     "tmpdir/libsize-6b.so" ""
-     {size-6a.c} "size-6" "size-6.out"}
-}
-
-run_ld_link_exec_tests [] $run_tests
+    ] \
+    [list \
+	"Run size-4a" \
+	"" \
+	"" \
+	{size-4a.c size-4b.c} \
+	"size-4a" \
+	"size-4.out" \
+	"$NOPIE_CFLAGS" \
+    ] \
+    [list \
+	"Run size-4b" \
+	"" \
+	"" \
+	{size-4b.c size-4a.c} \
+	"size-4b" \
+	"size-4.out" \
+	"$NOPIE_CFLAGS" \
+    ] \
+    [list \
+	"Run size-5a" \
+	"" \
+	"" \
+	{size-5a.c size-5b.c} \
+	"size-5a" \
+	"size-5.out" \
+	"$NOPIE_CFLAGS" \
+    ] \
+    [list \
+	"Run size-5b" \
+	"" \
+	"" \
+	{size-5b.c size-5a.c} \
+	"size-5b" \
+	"size-5.out" \
+	"$NOPIE_CFLAGS" \
+    ] \
+    [list \
+	"Run size-6" \
+	"tmpdir/libsize-6b.so" \
+	"" \
+	{size-6a.c} \
+	"size-6" \
+	"size-6.out" \
+	"$NOPIE_CFLAGS" \
+    ] \
+    [list \
+	"Run size-8" \
+	"tmpdir/libsize-8.so --hash-styl=gnu" \
+	"" \
+	{size-8a.c} \
+	"size-8" \
+	"size-8.out" \
+	"$NOPIE_CFLAGS" \
+    ] \
+    [list \
+	"Run size-9" \
+	"tmpdir/libsize-9.so" \
+	"" \
+	{size-9a.c} \
+	"size-9" \
+	"size-9.out" \
+    ] \
+    [list \
+	"Run size-10" \
+	"tmpdir/libsize-10.so" \
+	"" \
+	{size-10a.c} \
+	"size-10" \
+	"size-10.out" \
+    ] \
+]
 
 # Check if size relocation works at run-time.
 catch "exec tmpdir/size-7.exe > tmpdir/dump.out" exec_output
@@ -159,18 +309,3 @@ if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/size-7.out" ] } then {
     fail "Run-time size relocation"
     return
 }
-
-# Run-time size relocation tests.
-set run_time_tests {
-    {"Run size-8"
-     "tmpdir/libsize-8.so --hash-styl=gnu" ""
-     {size-8a.c} "size-8" "size-8.out"}
-    {"Run size-9"
-     "tmpdir/libsize-9.so" ""
-     {size-9a.c} "size-9" "size-9.out"}
-    {"Run size-10"
-     "tmpdir/libsize-10.so" ""
-     {size-10a.c} "size-10" "size-10.out"}
-}
-
-run_ld_link_exec_tests [] $run_time_tests
-- 
2.4.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]