This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] TLS brown paper bag


Hi!

The following patch fixes a bug in my 2002-08-08 patch. R_386_TLS_TPOFF32
is subtracted from %gs:0, so the addend has to be negated before storing
into the dso/binary.
Ok to commit?
Below is a testcase which demonstrates this bug. Both foo() and bar() ought
to return the same address if they are called from the same thread, but
foo() returns an address 8 bytes smaller.

2002-09-16  Jakub Jelinek  <jakub@redhat.com>

	* elf_i386_relocate_section (R_386_TLS_TPOFF32): Negate addend.

--- bfd/elf32-i386.c.jj	2002-09-11 12:45:43.000000000 +0200
+++ bfd/elf32-i386.c	2002-09-16 14:02:22.000000000 +0200
@@ -2579,7 +2579,7 @@ elf_i386_relocate_section (output_bfd, i
 	      else
 		dr_type = R_386_TLS_TPOFF32;
 	      if (dr_type == R_386_TLS_TPOFF32 && indx == 0)
-		bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
+		bfd_put_32 (output_bfd, dtpoff_base (info) - relocation,
 			    htab->sgot->contents + off);
 	      else
 		bfd_put_32 (output_bfd, 0,

#!/bin/sh
perl -p -e 's/        /\t/' > Makefile <<\EOF
C: C.c B.so
        $(CC) -O2 -o $@ -Wl,-rpath,. $^
B.so: B.c A.so
        $(CC) -shared -o $@ -O2 -Wl,-rpath,. -fpic -ftls-model=initial-exec $^
A.so: A.c
        $(CC) -shared -o $@ -O2 -fpic -ftls-model=initial-exec $^
clean:
        rm -f C *~ *.so core*
EOF
cat > A.c <<\EOF
__thread int a, b __attribute__((visibility ("hidden")));
extern __thread int c __attribute__((alias ("b")));

int *foo (void)
{
  return &b;
}
EOF
cat > B.c <<\EOF
extern __thread int c;

int *bar (void)
{
  return &c;
}
EOF
cat > C.c <<\EOF
extern int *foo (void), *bar (void);
extern void abort (void);

int main (void)
{
  if (foo () != bar ())
    abort ();
  return 0;
}
EOF
make
./C


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]