Re: RFC: Ignore TLS symbols for non-TLS programs

Daniel Jacobowitz
2006-08-25T03:43:12Z

First a general note: please include changelogs with patches. Also in
the minor feedback area, updates to included files need to be reflected
in Makefile.in, and URLs to Red Hat's bugzilla are not appropriate for
the FSF GDB; if you want to describe the problem, just do so.

On Fri, Aug 25, 2006 at 04:13:11AM +0200, Jan Kratochvil wrote:
> * with -ggdb2 and less "errno" in fact does not exist anywhere as it was
> compiled to "(*__errno_location ())" and the macro definition is not present.
> Unfortunately gdb will find the TLS symbol and it will try to access it but
> as the program has been compiled without -lpthread the TLS base register
> (%gs on i386) is not setup and it will result in:
> Cannot access memory at address 0x8

That can't be correct. Every program using glibc references errno.
If the program can access it, then GDB ought to be able to also.
In this case, libc.so.6 exports a dynamic TLS symbol named errno.

Did you try this with the patch you posted earlier to access TLS
without debug info?

> --- gdb/minsyms.c 19 Jul 2006 02:17:23 -0000 1.46
> +++ gdb/minsyms.c 25 Aug 2006 01:42:27 -0000
> @@ -50,6 +50,7 @@
> #include "demangle.h"
> #include "value.h"
> #include "cp-abi.h"
> +#include "target.h"

This violates the abstraction layers. We're reading the symbols from
a file. Why should it matter what target we're connected to? In fact,
we probably aren't connected to a target yet. Decisions about what we
can access should only be made when we want to access it.

> +/* Test accessing TLS based variable without -lpthread / TLS setup. */
> +
> +#include <pthread.h>
> +
> +__thread int thread_local = 42;
> +
> +int main(void)
> +{
> + return 0;
> +}

It would be legal for main to return the value of thread_local, even
though it is not linked to pthread.c.

Oh, and you don't actually need <pthread.h> for this.

> +if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {

Did you try this? [] should give you a TCL syntax error.