* [committed, PATCH] x86: Add run-time tests for -mtls-dialect=gnu2
@ 2017-04-28 19:44 H.J. Lu
2017-05-01 18:06 ` H.J. Lu
0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2017-04-28 19:44 UTC (permalink / raw)
To: binutils
I checked in this patch to add run-time tests for -mtls-dialect=gnu2.
H.J.
---
* testsuite/config/default.exp (GNU2_CFLAGS): New. Set
to -mtls-dialect=gnu2 if target compiler supports it.
* testsuite/ld-i386/tls.exp: Run -mtls-dialect=gnu2 tests.
* testsuite/ld-x86-64/tls.exp: Likewise.
* testsuite/ld-i386/tlsdesc1a.c: New file.
* testsuite/ld-i386/tlsdesc1b.c: Likewise.
* testsuite/ld-x86-64/tlsdesc1a.c: Likewise.
* testsuite/ld-x86-64/tlsdesc1b.c: Likewise.
---
ld/ChangeLog | 11 +++++++
ld/testsuite/config/default.exp | 37 ++++++++++++++++++++++
ld/testsuite/ld-i386/tls.exp | 58 +++++++++++++++++++++++++++++++++++
ld/testsuite/ld-i386/tlsdesc1a.c | 19 ++++++++++++
ld/testsuite/ld-i386/tlsdesc1b.c | 8 +++++
ld/testsuite/ld-x86-64/tls.exp | 63 ++++++++++++++++++++++++++++++++++++++
ld/testsuite/ld-x86-64/tlsdesc1a.c | 19 ++++++++++++
ld/testsuite/ld-x86-64/tlsdesc1b.c | 8 +++++
8 files changed, 223 insertions(+)
create mode 100644 ld/testsuite/ld-i386/tlsdesc1a.c
create mode 100644 ld/testsuite/ld-i386/tlsdesc1b.c
create mode 100644 ld/testsuite/ld-x86-64/tlsdesc1a.c
create mode 100644 ld/testsuite/ld-x86-64/tlsdesc1b.c
diff --git a/ld/ChangeLog b/ld/ChangeLog
index be412ed..e15ee0a 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,16 @@
2017-04-28 H.J. Lu <hongjiu.lu@intel.com>
+ * testsuite/config/default.exp (GNU2_CFLAGS): New. Set
+ to -mtls-dialect=gnu2 if target compiler supports it.
+ * testsuite/ld-i386/tls.exp: Run -mtls-dialect=gnu2 tests.
+ * testsuite/ld-x86-64/tls.exp: Likewise.
+ * testsuite/ld-i386/tlsdesc1a.c: New file.
+ * testsuite/ld-i386/tlsdesc1b.c: Likewise.
+ * testsuite/ld-x86-64/tlsdesc1a.c: Likewise.
+ * testsuite/ld-x86-64/tlsdesc1b.c: Likewise.
+
+2017-04-28 H.J. Lu <hongjiu.lu@intel.com>
+
* testsuite/ld-elf/shared.exp: Add run-time tests for -z now.
* testsuite/ld-i386/tls.exp: Likewise.
* testsuite/ld-ifunc/ifunc.exp: Likewise.
diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 899943c..f5cb188 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -328,3 +328,40 @@ if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
set NOPIE_LDFLAGS ""
}
}
+
+# Set GNU2_CFLAGS to "-mtls-dialect=gnu2" if target compiler supports it.
+
+if { ![info exists GNU2_CFLAGS] } then {
+ if { [which $CC] != 0 } {
+ # Check if gcc supports -mtls-dialect=gnu2
+ 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/gnu2[pid]"
+ set src ${basename}.c
+ set output ${basename}.o
+ set f [open $src "w"]
+ puts $f "__thread int yyy = 100;"
+ close $f
+ if [is_remote host] {
+ set src [remote_download host $src]
+ }
+ set gnu2_available [run_host_cmd_yesno "$CC" "$flags -c -mtls-dialect=gnu2 $src -o $output"]
+ remote_file host delete $src
+ remote_file host delete $output
+ file delete $src
+
+ if { $gnu2_available == 1 } then {
+ set GNU2_CFLAGS "-mtls-dialect=gnu2"
+ } else {
+ set GNU2_CFLAGS ""
+ }
+ } else {
+ set GNU2_CFLAGS ""
+ }
+}
diff --git a/ld/testsuite/ld-i386/tls.exp b/ld/testsuite/ld-i386/tls.exp
index 4430821..504b0f6 100644
--- a/ld/testsuite/ld-i386/tls.exp
+++ b/ld/testsuite/ld-i386/tls.exp
@@ -176,3 +176,61 @@ run_ld_link_exec_tests [list \
"pass.out" \
] \
]
+
+run_cc_link_tests [list \
+ [list \
+ "Build libtlsdesc1.so" \
+ "-shared" \
+ "-fPIC $GNU2_CFLAGS" \
+ { tlsdesc1b.c } \
+ {} \
+ "libtlsdesc1.so" \
+ ] \
+ [list \
+ "Build libtlsdesc1n.so" \
+ "-Wl,-z,now -shared" \
+ "-fPIC $GNU2_CFLAGS" \
+ { tlsdesc1b.c } \
+ {} \
+ "libtlsdesc1n.so" \
+ ] \
+]
+
+run_ld_link_exec_tests [list \
+ [list \
+ "Run tlsdesc1" \
+ "-Wl,--no-as-needed tmpdir/libtlsdesc1.so" \
+ "" \
+ { tlsdesc1a.c } \
+ "tlsdesc1a" \
+ "pass.out" \
+ "$GNU2_CFLAGS" \
+ ] \
+ [list \
+ "Run tlsdesc1 (-z now)" \
+ "-Wl,-z,now -Wl,--no-as-needed tmpdir/libtlsdesc1n.so" \
+ "" \
+ { tlsdesc1a.c } \
+ "tlsdesc1b" \
+ "pass.out" \
+ "$GNU2_CFLAGS" \
+ ] \
+ [list \
+ "Run tlsdesc1 with PIE" \
+ "-pie -Wl,--no-as-needed tmpdir/libtlsdesc1.so" \
+ "" \
+ { tlsdesc1a.c } \
+ "tlsdesc1c" \
+ "pass.out" \
+ "-fPIE $GNU2_CFLAGS" \
+ ] \
+ [list \
+ "Run tlsdesc1 with PIE (-z now)" \
+ "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/libtlsdesc1n.so" \
+ "" \
+ { tlsdesc1a.c } \
+ "tlsdesc1d" \
+ "pass.out" \
+ "-fPIE $GNU2_CFLAGS" \
+ ] \
+]
diff --git a/ld/testsuite/ld-i386/tlsdesc1a.c b/ld/testsuite/ld-i386/tlsdesc1a.c
new file mode 100644
index 0000000..7d2f4f6
--- /dev/null
+++ b/ld/testsuite/ld-i386/tlsdesc1a.c
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+extern int foo (void);
+
+extern __thread int yyy;
+
+__thread int zzz = 20;
+
+int
+main (void)
+{
+ if (foo () != zzz)
+ abort ();
+ if (yyy != 100)
+ abort ();
+ printf ("PASS\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-i386/tlsdesc1b.c b/ld/testsuite/ld-i386/tlsdesc1b.c
new file mode 100644
index 0000000..fe428af
--- /dev/null
+++ b/ld/testsuite/ld-i386/tlsdesc1b.c
@@ -0,0 +1,8 @@
+__thread int yyy = 100;
+extern __thread int zzz;
+
+int
+foo (void)
+{
+ return zzz;
+}
diff --git a/ld/testsuite/ld-x86-64/tls.exp b/ld/testsuite/ld-x86-64/tls.exp
index e578645..6b4852b 100644
--- a/ld/testsuite/ld-x86-64/tls.exp
+++ b/ld/testsuite/ld-x86-64/tls.exp
@@ -176,3 +176,66 @@ run_ld_link_exec_tests [list \
"pass.out" \
] \
]
+
+# -mtls-dialect=gnu2 isn't supported on x32.
+if [istarget "x86_64-*-linux*-gnux32"] {
+ return
+}
+
+run_cc_link_tests [list \
+ [list \
+ "Build libtlsdesc1.so" \
+ "-shared" \
+ "-fPIC $GNU2_CFLAGS" \
+ { tlsdesc1b.c } \
+ {} \
+ "libtlsdesc1.so" \
+ ] \
+ [list \
+ "Build libtlsdesc1n.so" \
+ "-Wl,-z,now -shared" \
+ "-fPIC $GNU2_CFLAGS" \
+ { tlsdesc1b.c } \
+ {} \
+ "libtlsdesc1n.so" \
+ ] \
+]
+
+run_ld_link_exec_tests [list \
+ [list \
+ "Run tlsdesc1" \
+ "-Wl,--no-as-needed tmpdir/libtlsdesc1.so" \
+ "" \
+ { tlsdesc1a.c } \
+ "tlsdesc1a" \
+ "pass.out" \
+ "$GNU2_CFLAGS" \
+ ] \
+ [list \
+ "Run tlsdesc1 (-z now)" \
+ "-Wl,-z,now -Wl,--no-as-needed tmpdir/libtlsdesc1n.so" \
+ "" \
+ { tlsdesc1a.c } \
+ "tlsdesc1b" \
+ "pass.out" \
+ "$GNU2_CFLAGS" \
+ ] \
+ [list \
+ "Run tlsdesc1 with PIE" \
+ "-pie -Wl,--no-as-needed tmpdir/libtlsdesc1.so" \
+ "" \
+ { tlsdesc1a.c } \
+ "tlsdesc1c" \
+ "pass.out" \
+ "-fPIE $GNU2_CFLAGS" \
+ ] \
+ [list \
+ "Run tlsdesc1 with PIE (-z now)" \
+ "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/libtlsdesc1n.so" \
+ "" \
+ { tlsdesc1a.c } \
+ "tlsdesc1d" \
+ "pass.out" \
+ "-fPIE $GNU2_CFLAGS" \
+ ] \
+]
diff --git a/ld/testsuite/ld-x86-64/tlsdesc1a.c b/ld/testsuite/ld-x86-64/tlsdesc1a.c
new file mode 100644
index 0000000..7d2f4f6
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsdesc1a.c
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+extern int foo (void);
+
+extern __thread int yyy;
+
+__thread int zzz = 20;
+
+int
+main (void)
+{
+ if (foo () != zzz)
+ abort ();
+ if (yyy != 100)
+ abort ();
+ printf ("PASS\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-x86-64/tlsdesc1b.c b/ld/testsuite/ld-x86-64/tlsdesc1b.c
new file mode 100644
index 0000000..fe428af
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsdesc1b.c
@@ -0,0 +1,8 @@
+__thread int yyy = 100;
+extern __thread int zzz;
+
+int
+foo (void)
+{
+ return zzz;
+}
--
2.9.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [committed, PATCH] x86: Add run-time tests for -mtls-dialect=gnu2
2017-04-28 19:44 [committed, PATCH] x86: Add run-time tests for -mtls-dialect=gnu2 H.J. Lu
@ 2017-05-01 18:06 ` H.J. Lu
0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2017-05-01 18:06 UTC (permalink / raw)
To: binutils
On Fri, Apr 28, 2017 at 12:44:35PM -0700, H.J. Lu wrote:
> I checked in this patch to add run-time tests for -mtls-dialect=gnu2.
>
>
> H.J.
> ---
> * testsuite/config/default.exp (GNU2_CFLAGS): New. Set
> to -mtls-dialect=gnu2 if target compiler supports it.
> * testsuite/ld-i386/tls.exp: Run -mtls-dialect=gnu2 tests.
> * testsuite/ld-x86-64/tls.exp: Likewise.
> * testsuite/ld-i386/tlsdesc1a.c: New file.
> * testsuite/ld-i386/tlsdesc1b.c: Likewise.
> * testsuite/ld-x86-64/tlsdesc1a.c: Likewise.
> * testsuite/ld-x86-64/tlsdesc1b.c: Likewise.
I checked in this patch to check if GNU2 TLS really works before
running GNU2 TLS tests.
* testsuite/ld-i386/tls.exp: Run GNU2 TLS tests only if there
is working GNU2 TLS support.
* testsuite/ld-x86-64/tls.exp: Likewise.
* testsuite/lib/ld-lib.exp (check_gnu2_tls_available): New proc.
---
ld/ChangeLog | 7 +++++
ld/testsuite/ld-i386/tls.exp | 5 ++++
ld/testsuite/ld-x86-64/tls.exp | 5 ++++
ld/testsuite/lib/ld-lib.exp | 64 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 81 insertions(+)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index e15ee0a..238404d 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2017-05-01 H.J. Lu <hongjiu.lu@intel.com>
+
+ * testsuite/ld-i386/tls.exp: Run GNU2 TLS tests only if there
+ is working GNU2 TLS support.
+ * testsuite/ld-x86-64/tls.exp: Likewise.
+ * testsuite/lib/ld-lib.exp (check_gnu2_tls_available): New proc.
+
2017-04-28 H.J. Lu <hongjiu.lu@intel.com>
* testsuite/config/default.exp (GNU2_CFLAGS): New. Set
diff --git a/ld/testsuite/ld-i386/tls.exp b/ld/testsuite/ld-i386/tls.exp
index 504b0f6..7a99e46 100644
--- a/ld/testsuite/ld-i386/tls.exp
+++ b/ld/testsuite/ld-i386/tls.exp
@@ -177,6 +177,11 @@ run_ld_link_exec_tests [list \
] \
]
+# Run-time tests which require working GNU2 TLS support.
+if { ![check_gnu2_tls_available] } {
+ return
+}
+
run_cc_link_tests [list \
[list \
"Build libtlsdesc1.so" \
diff --git a/ld/testsuite/ld-x86-64/tls.exp b/ld/testsuite/ld-x86-64/tls.exp
index 6b4852b..5282146 100644
--- a/ld/testsuite/ld-x86-64/tls.exp
+++ b/ld/testsuite/ld-x86-64/tls.exp
@@ -201,6 +201,11 @@ run_cc_link_tests [list \
] \
]
+# Run-time tests which require working GNU2 TLS support.
+if { ![check_gnu2_tls_available] } {
+ return
+}
+
run_ld_link_exec_tests [list \
[list \
"Run tlsdesc1" \
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index b60fcad..aecc700 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -2210,3 +2210,67 @@ proc check_libdl_available { } {
}
return $libdl_available_saved
}
+
+# Returns true if GNU2 TLS works.
+
+proc check_gnu2_tls_available { } {
+ global gnu2_tls_available_saved
+ global CC
+ global GNU2_CFLAGS
+
+ if {![info exists gnu2_tls_available_saved]} {
+ if { [which $CC] == 0 || "$GNU2_CFLAGS" == "" } {
+ set gnu2_tls_available_saved 0
+ return 0
+ }
+ # Check if GNU2 TLS works.
+ set flags "$GNU2_CFLAGS"
+ 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/gnu2_tls[pid]"
+ set src1 ${basename}1.c
+ set output1 ${basename}.so
+ set f [open $src1 "w"]
+ puts $f "extern __thread int zzz;"
+ puts $f "int foo (void)"
+ puts $f "{"
+ puts $f " return zzz;"
+ puts $f "}"
+ close $f
+ if [is_remote host] {
+ set src1 [remote_download host $src1]
+ }
+ set src2 ${basename}2.c
+ set output2 ${basename}.exe
+ set f [open $src2 "w"]
+ puts $f "__thread int zzz = 20;"
+ puts $f "extern int foo (void);"
+ puts $f "int main (void)"
+ puts $f "{"
+ puts $f " if (foo () != 20) __builtin_abort ();"
+ puts $f " return 0; "
+ puts $f "}"
+ close $f
+ if [is_remote host] {
+ set src2 [remote_download host $src2]
+ }
+ set gnu2_tls_available_saved [run_host_cmd_yesno "$CC" "-fPIC -shared $flags $src1 -o $output1"]
+ if { $gnu2_tls_available_saved == 1 } {
+ set gnu2_tls_available_saved [run_host_cmd_yesno "$CC" "$flags $src2 $output1 -o $output2"]
+ if { $gnu2_tls_available_saved == 1 } {
+ set gnu2_tls_available_saved [run_host_cmd_yesno "$output2" ""]
+ }
+ }
+ remote_file host delete $src1
+ remote_file host delete $output1
+ remote_file host delete $src2
+ remote_file host delete $output2
+ file delete $src1 $src2
+ }
+ return $gnu2_tls_available_saved
+}
--
2.9.3
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-05-01 18:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-28 19:44 [committed, PATCH] x86: Add run-time tests for -mtls-dialect=gnu2 H.J. Lu
2017-05-01 18:06 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).