mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-30 12:44:10 +08:00
x86: Add run-time tests for -mtls-dialect=gnu2
* 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.
This commit is contained in:
parent
d6f48aed23
commit
1670f9c154
11
ld/ChangeLog
11
ld/ChangeLog
@ -1,3 +1,14 @@
|
||||
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.
|
||||
|
@ -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 ""
|
||||
}
|
||||
}
|
||||
|
@ -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" \
|
||||
] \
|
||||
]
|
||||
|
19
ld/testsuite/ld-i386/tlsdesc1a.c
Normal file
19
ld/testsuite/ld-i386/tlsdesc1a.c
Normal file
@ -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;
|
||||
}
|
8
ld/testsuite/ld-i386/tlsdesc1b.c
Normal file
8
ld/testsuite/ld-i386/tlsdesc1b.c
Normal file
@ -0,0 +1,8 @@
|
||||
__thread int yyy = 100;
|
||||
extern __thread int zzz;
|
||||
|
||||
int
|
||||
foo (void)
|
||||
{
|
||||
return zzz;
|
||||
}
|
@ -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" \
|
||||
] \
|
||||
]
|
||||
|
19
ld/testsuite/ld-x86-64/tlsdesc1a.c
Normal file
19
ld/testsuite/ld-x86-64/tlsdesc1a.c
Normal file
@ -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;
|
||||
}
|
8
ld/testsuite/ld-x86-64/tlsdesc1b.c
Normal file
8
ld/testsuite/ld-x86-64/tlsdesc1b.c
Normal file
@ -0,0 +1,8 @@
|
||||
__thread int yyy = 100;
|
||||
extern __thread int zzz;
|
||||
|
||||
int
|
||||
foo (void)
|
||||
{
|
||||
return zzz;
|
||||
}
|
Loading…
Reference in New Issue
Block a user