gdb/ChangeLog 2016-10-09 Jan Kratochvil * parse.c (write_exp_msymbol): Fix ADDR computation. gdb/testsuite/ChangeLog 2016-10-09 Jan Kratochvil * gdb.threads/tls-nodebug-pie.c: New file. * gdb.threads/tls-nodebug-pie.exp: New file. --- a/gdb/parse.c +++ b/gdb/parse.c @@ -480,13 +480,17 @@ write_exp_msymbol (struct parser_state *ps, struct objfile *objfile = bound_msym.objfile; struct gdbarch *gdbarch = get_objfile_arch (objfile); - CORE_ADDR addr = BMSYMBOL_VALUE_ADDRESS (bound_msym); struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol); enum minimal_symbol_type type = MSYMBOL_TYPE (msymbol); - CORE_ADDR pc; + CORE_ADDR addr, pc; const int is_tls = (section != NULL && section->the_bfd_section->flags & SEC_THREAD_LOCAL); + if (is_tls) + addr = MSYMBOL_VALUE_RAW_ADDRESS (bound_msym.minsym); + else + addr = BMSYMBOL_VALUE_ADDRESS (bound_msym); + /* The minimal symbol might point to a function descriptor; resolve it to the actual code address instead. */ pc = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, ¤t_target); --- /dev/null +++ b/gdb/testsuite/gdb.threads/tls-nodebug-pie.c @@ -0,0 +1,27 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2016 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +__thread int thread_local = 42; + +int main(void) +{ + /* Ensure we link against pthreads even with --as-needed. */ + pthread_testcancel(); + return 0; +} --- /dev/null +++ b/gdb/testsuite/gdb.threads/tls-nodebug-pie.exp @@ -0,0 +1,29 @@ +# Copyright 2016 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +standard_testfile + +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \ + [list "additional_flags=-fPIE -pie"]] != "" } { + return -1 +} + +clean_restart ${binfile} +if ![runto_main] then { + return 0 +} + +# Formerly: Cannot access memory at address 0xd5554d5216fc +gdb_test "p thread_local" " = 42" "thread local storage"