Message ID | 7ff67b8d-4e01-6226-db47-e64828bed692@linux.vnet.ibm.com |
---|---|
State | New |
Headers | show |
On 06/20/2017 08:45 AM, Stefan Liebler wrote: > Hi, > > the testcases elf/tst-tls1-static and elf/tst-tls2-static > are failing on s390 if gcc is configured with --enable-default-pie: > set bar to 1 (LE) > get sum of foo and bar (IE) = 0 > bar = 0 > > The linker reports the following error without aborting: > elf/tst-tls1-static.o(.text+0x80): > invalid instruction for TLS relocation R_390_TLS_LOAD > > According to binutils, there are only four valid cases for IE -> LE > transition: > lg %rx,(0,%ry) -> sllg %rx,%ry,0 > lg %rx,(%ry,0) -> sllg %rx,%ry,0 > lg %rx,(%ry,%r12) -> sllg %rx,%ry,0 > lg %rx,(%r12,%ry) -> sllg %rx,%ry,0 > > Thus I've adjusted the TLS_IE macro in s390 tls-macros.h files in PIC > case in order to use r12 for the address of global offset table. > The adjusted macro definition is not used if gcc is not configured with > --enable-default-pie. > > Bye. > Stefan > > ChangeLog: > > * sysdeps/s390/s390-32/tls-macros.h (TLS_IE): > Use r12 for GOT address. > * sysdeps/s390/s390-64/tls-macros.h (TLS_IE): Likewise. Any objection? Otherwise I'll commit this patch. Bye. Stefan
On 06/26/2017 09:19 AM, Stefan Liebler wrote: > On 06/20/2017 08:45 AM, Stefan Liebler wrote: >> Hi, >> >> the testcases elf/tst-tls1-static and elf/tst-tls2-static >> are failing on s390 if gcc is configured with --enable-default-pie: >> set bar to 1 (LE) >> get sum of foo and bar (IE) = 0 >> bar = 0 >> >> The linker reports the following error without aborting: >> elf/tst-tls1-static.o(.text+0x80): >> invalid instruction for TLS relocation R_390_TLS_LOAD >> >> According to binutils, there are only four valid cases for IE -> LE >> transition: >> lg %rx,(0,%ry) -> sllg %rx,%ry,0 >> lg %rx,(%ry,0) -> sllg %rx,%ry,0 >> lg %rx,(%ry,%r12) -> sllg %rx,%ry,0 >> lg %rx,(%r12,%ry) -> sllg %rx,%ry,0 >> >> Thus I've adjusted the TLS_IE macro in s390 tls-macros.h files in PIC >> case in order to use r12 for the address of global offset table. >> The adjusted macro definition is not used if gcc is not configured >> with --enable-default-pie. >> >> Bye. >> Stefan >> >> ChangeLog: >> >> * sysdeps/s390/s390-32/tls-macros.h (TLS_IE): >> Use r12 for GOT address. >> * sysdeps/s390/s390-64/tls-macros.h (TLS_IE): Likewise. > > Any objection? > Otherwise I'll commit this patch. Committed > > Bye. > Stefan >
commit a4296064ced57e04172fa5b76675e2690ae03b1e Author: Stefan Liebler <stli@linux.vnet.ibm.com> Date: Mon Jun 19 17:05:15 2017 +0200 S390: Save and restore r12 in TLS_IE macro. The testcases elf/tst-tls1-static and elf/tst-tls2-static are failing on s390 if gcc is configured with --enable-default-pie. According to binutils, there are only four valid cases for IE -> LE transition: lg %rx,(0,%ry) -> sllg %rx,%ry,0 lg %rx,(%ry,0) -> sllg %rx,%ry,0 lg %rx,(%ry,%r12) -> sllg %rx,%ry,0 lg %rx,(%r12,%ry) -> sllg %rx,%ry,0 Thus I've adjusted the TLS_IE macro in s390 tls-macros.h files in PIC case in order to use r12 for the address of global offset table. The adjusted macro definition is not used if gcc is not configured with --enable-default-pie. ChangeLog: * sysdeps/s390/s390-32/tls-macros.h (TLS_IE): Use r12 for GOT address. * sysdeps/s390/s390-64/tls-macros.h (TLS_IE): Likewise. diff --git a/sysdeps/s390/s390-32/tls-macros.h b/sysdeps/s390/s390-32/tls-macros.h index a4c5fff..153523a 100644 --- a/sysdeps/s390/s390-32/tls-macros.h +++ b/sysdeps/s390/s390-32/tls-macros.h @@ -8,15 +8,17 @@ #ifdef PIC # define TLS_IE(x) \ - ({ unsigned long __offset, __got; \ + ({ unsigned long __offset, __save12; \ __asm__ ("bras %0,1f\n" \ "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \ ".long " #x "@gotntpoff\n" \ - "1:\tl %1,0(%0)\n\t" \ - "la %1,0(%1,%0)\n\t" \ + "1:\tlr %1,%%r12\n\t" \ + "l %%r12,0(%0)\n\t" \ + "la %%r12,0(%0,%%r12)\n\t" \ "l %0,4(%0)\n\t" \ - "l %0,0(%0,%1):tls_load:" #x "\n" \ - : "=&a" (__offset), "=&a" (__got) : : "cc" ); \ + "l %0,0(%0,%%r12):tls_load:" #x "\n\t" \ + "lr %%r12,%1\n" \ + : "=&a" (__offset), "=&a" (__save12) : : "cc" ); \ (int *) (__builtin_thread_pointer() + __offset); }) #else # define TLS_IE(x) \ diff --git a/sysdeps/s390/s390-64/tls-macros.h b/sysdeps/s390/s390-64/tls-macros.h index d70ea6c..449a843 100644 --- a/sysdeps/s390/s390-64/tls-macros.h +++ b/sysdeps/s390/s390-64/tls-macros.h @@ -8,13 +8,15 @@ #ifdef PIC # define TLS_IE(x) \ - ({ unsigned long __offset, __got; \ + ({ unsigned long __offset, __save12; \ __asm__ ("bras %0,0f\n\t" \ ".quad " #x "@gotntpoff\n" \ - "0:\tlarl %1,_GLOBAL_OFFSET_TABLE_\n\t" \ + "0:\tlgr %1,%%r12\n\t" \ + "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \ "lg %0,0(%0)\n\t" \ - "lg %0,0(%0,%1):tls_load:" #x "\n" \ - : "=&a" (__offset), "=&a" (__got) : : "cc" ); \ + "lg %0,0(%0,%%r12):tls_load:" #x "\n\t" \ + "lgr %%r12,%1\n" \ + : "=&a" (__offset), "=&a" (__save12) : : "cc" ); \ (int *) (__builtin_thread_pointer() + __offset); }) #else # define TLS_IE(x) \