diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2014-05-21 16:25:53 +0200 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2014-05-21 16:25:53 +0200 |
commit | 5876f5032f60c45c4bd19e7ea7d0c14d0346b93e (patch) | |
tree | 52545ba82ab64b43cdf7f0765d4764c39bdeac06 /gdb/testsuite | |
parent | 0256a6ac4b25d56da14cbbe3cda9977f9c7c13eb (diff) | |
download | gdb-5876f5032f60c45c4bd19e7ea7d0c14d0346b93e.zip gdb-5876f5032f60c45c4bd19e7ea7d0c14d0346b93e.tar.gz gdb-5876f5032f60c45c4bd19e7ea7d0c14d0346b93e.tar.bz2 |
Fix TLS access for -static -pthread
I have posted:
TLS variables access for -static -lpthread executables
https://sourceware.org/ml/libc-help/2014-03/msg00024.html
and the GDB patch below has been confirmed as OK for current glibcs.
Further work should be done for newer glibcs:
Improve TLS variables glibc compatibility
https://sourceware.org/bugzilla/show_bug.cgi?id=16954
Still the patch below implements the feature in a fully functional way backward
compatible with current glibcs, it depends on the following glibc source line:
csu/libc-tls.c
main_map->l_tls_modid = 1;
gdb/
2014-05-21 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix TLS access for -static -pthread.
* linux-thread-db.c (struct thread_db_info): Add td_thr_tlsbase_p.
(try_thread_db_load_1): Initialize it.
(thread_db_get_thread_local_address): Call it if LM is zero.
* target.c (target_translate_tls_address): Remove LM_ADDR zero check.
* target.h (struct target_ops) (to_get_thread_local_address): Add
load_module_addr comment.
gdb/gdbserver/
2014-05-21 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix TLS access for -static -pthread.
* gdbserver/thread-db.c (struct thread_db): Add td_thr_tlsbase_p.
(thread_db_get_tls_address): Call it if LOAD_MODULE is zero.
(thread_db_load_search, try_thread_db_load_1): Initialize it.
gdb/testsuite/
2014-05-21 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix TLS access for -static -pthread.
* gdb.threads/staticthreads.c <HAVE_TLS> (tlsvar): New.
<HAVE_TLS> (thread_function, main): Initialize it.
* gdb.threads/staticthreads.exp: Try gdb_compile_pthreads for $have_tls.
Add clean_restart.
<$have_tls != "">: Check TLSVAR.
Message-ID: <20140410115204.GB16411@host2.jankratochvil.net>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/staticthreads.c | 12 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/staticthreads.exp | 30 |
3 files changed, 45 insertions, 6 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 1e39142..56b6cc5 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2014-05-21 Jan Kratochvil <jan.kratochvil@redhat.com> + + Fix TLS access for -static -pthread. + * gdb.threads/staticthreads.c <HAVE_TLS> (tlsvar): New. + <HAVE_TLS> (thread_function, main): Initialize it. + * gdb.threads/staticthreads.exp: Try gdb_compile_pthreads for $have_tls. + Add clean_restart. + <$have_tls != "">: Check TLSVAR. + 2014-05-21 Pedro Alves <palves@redhat.com> * gdb.base/dcache-line-read-error.c: New. diff --git a/gdb/testsuite/gdb.threads/staticthreads.c b/gdb/testsuite/gdb.threads/staticthreads.c index e834d7f..5c8eabe 100644 --- a/gdb/testsuite/gdb.threads/staticthreads.c +++ b/gdb/testsuite/gdb.threads/staticthreads.c @@ -28,10 +28,17 @@ sem_t semaphore; +#ifdef HAVE_TLS +__thread int tlsvar; +#endif + void * thread_function (void *arg) { - printf ("Thread executing\n"); +#ifdef HAVE_TLS + tlsvar = 2; +#endif + printf ("Thread executing\n"); /* tlsvar-is-set */ while (sem_wait (&semaphore) != 0) { if (errno != EINTR) @@ -57,6 +64,9 @@ main (int argc, char **argv) return -1; } +#ifdef HAVE_TLS + tlsvar = 1; +#endif /* Create a thread, wait for it to complete. */ { diff --git a/gdb/testsuite/gdb.threads/staticthreads.exp b/gdb/testsuite/gdb.threads/staticthreads.exp index 80b0ba8..9fa625a 100644 --- a/gdb/testsuite/gdb.threads/staticthreads.exp +++ b/gdb/testsuite/gdb.threads/staticthreads.exp @@ -22,11 +22,16 @@ standard_testfile set static_flag "-static" -if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ - executable \ - [list debug "additional_flags=${static_flag}" \ - ]] != "" } { - return -1 +foreach have_tls { "-DHAVE_TLS" "" } { + if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ + executable \ + [list debug "additional_flags=${static_flag} ${have_tls}" \ + ]] == "" } { + break + } + if { $have_tls == "" } { + return -1 + } } clean_restart ${binfile} @@ -89,3 +94,18 @@ gdb_test_multiple "quit" "$test" { pass "$test" } } +clean_restart ${binfile} + + +if { "$have_tls" != "" } { + if ![runto_main] { + return -1 + } + gdb_breakpoint [gdb_get_line_number "tlsvar-is-set"] + gdb_continue_to_breakpoint "tlsvar-is-set" ".* tlsvar-is-set .*" + gdb_test "p tlsvar" " = 2" "tlsvar in thread" + gdb_test "thread 1" ".*" + # Unwind from pthread_join. + gdb_test "up 10" " in main .*" + gdb_test "p tlsvar" " = 1" "tlsvar in main" +} |