This is the mail archive of the binutils@sourceware.org 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]

Re: PR22978, TLS local-dynamic incorrectly linked on hppa-linux


On Fri, Apr 20, 2018 at 10:54:57AM -0500, Carlos O'Donell wrote:
> On 04/20/2018 08:49 AM, Alan Modra wrote:
> > We were emitting dynamic relocs on the second word of a TLS GD GOT
> > entry pair (the dtprel offset), without the addend necessary when no
> > symbol is present on the dynamic reloc.  Unfortunately the simple
> > solution of providing the proper addend doesn't work due to an hppa
> > glibc ld.so bug that ignores such addends.  So instead optimize the
> > relocs.  The dtprel offset is known at link time for locally defined
> > symbols (the only case where we'll end up with no symbol on a dynamic
> > reloc) so we can omit the dynamic reloc in that case.
> > 
> > Furthermore, we can omit a dynamic reloc on the first word of a TLS GD
> > GOT entry pair (the module id) if the symbol is local and we are
> > producing an executable.  Similarly, a tprel reloc on a TLS IE GOT
> > entry is not needed for local symbols in an executable.  So the
> > condition for TLS GOT relocs can become bfd_link_dll(info) rather than
> > bfd_link_pic(info) as needed for normal GOT relocs.
> > 
> > This all presumes hppa ld.so doesn't need to differentiate TLS GD GOT
> > pairs from TLS LD GOT pairs, which is currently true.
> > 
> > 	PR 22978
> > 	* elf32-hppa.c (got_relocs_needed): Add extra param to special
> > 	case both dtprel and tprel relocs.
> > 	(allocate_dynrelocs): Adjust conditions for got relocs.
> > 	(elf32_hppa_relocate_section): Likewise for local sym got relocs.
> > 	Emit dynamic relocs on TLS GOT entries for shared libraries,
> > 	not when pic.  Omit dynamic reloc on dtprel entry when local,
> > 	and on tprel entry when local and executable.
> 
> This looks reasonable, but if we could fix the ld.so bug that would also
> be good!
> 
> How did you test this fix? Sometimes changes like this have surprises,
> and I would test it but my box is currently inaccessible and needs some
> cleanup.

I tested it along with the trivial glibc ld.so fix, on
phantom.parisc-linux.org with a binutils and glibc build plus
testsuite run.  There were some difficulties in testing, the machine
crashing a couple of times, and I forgot to increase the glibc
timeout..

Worse, on investigating a little more this morning, I think my newly
built and installed ld wasn't even used for the glibc build and
testsuite run.  "make check" doesn't always do what you think it
should be doing.  :-(

It seems that the system collect2 doesn't honour PATH.  For example:

amodra@phantom:~/src/glibc/elf$ which ld
/home/amodra/gnu/bin/ld
amodra@phantom:~/src/glibc/elf$ which hppa-linux-gnu-ld    
/home/amodra/gnu/bin/hppa-linux-gnu-ld
amodra@phantom:~/src/glibc/elf$ hppa-linux-gnu-gcc -nostdlib -nostartfiles -o /home/amodra/build/glibc32/elf/tst-tls2    -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both /home/amodra/build/glibc32/csu/crt1.o /home/amodra/build/glibc32/csu/crti.o `hppa-linux-gnu-gcc  --print-file-name=crtbegin.o` /home/amodra/build/glibc32/elf/tst-tls2.o /home/amodra/build/glibc32/support/libsupport_nonshared.a  -Wl,-dynamic-linker=/home/amodra/gnu/hppa-linux-gnu/lib/ld.so.1 -Wl,-rpath-link=/home/amodra/build/glibc32:/home/amodra/build/glibc32/math:/home/amodra/build/glibc32/elf:/home/amodra/build/glibc32/dlfcn:/home/amodra/build/glibc32/nss:/home/amodra/build/glibc32/nis:/home/amodra/build/glibc32/rt:/home/amodra/build/glibc32/resolv:/home/amodra/build/glibc32/crypt:/home/amodra/build/glibc32/mathvec:/home/amodra/build/glibc32/support:/home/amodra/build/glibc32/nptl /home/amodra/build/glibc32/libc.so.6 /home/amodra/build/glibc32/libc_nonshared.a -Wl,--as-needed /home/amodra/build/glibc32/elf/ld.so -Wl,--no-as-needed -lgcc -Wl,--as-needed -lgcc_s  -Wl,--no-as-needed `hppa-linux-gnu-gcc  --print-file-name=crtend.o` /home/amodra/build/glibc32/csu/crtn.o -v -Wl,-v
Using built-in specs.
COLLECT_GCC=hppa-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/hppa-linux-gnu/7/lto-wrapper
Target: hppa-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 7.3.0-16' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --with-as=/usr/bin/hppa-linux-gnu-as --with-ld=/usr/bin/hppa-linux-gnu-ld --program-suffix=-7 --program-prefix=hppa-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libssp --disable-libitm --disable-libsanitizer --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-libstdcxx-pch --enable-checking=release --build=hppa-linux-gnu --host=hppa-linux-gnu --target=hppa-linux-gnu
Thread model: posix
gcc version 7.3.0 (Debian 7.3.0-16) 
COMPILER_PATH=/usr/lib/gcc/hppa-linux-gnu/7/:/usr/lib/gcc/hppa-linux-gnu/7/:/usr/lib/gcc/hppa-linux-gnu/:/usr/lib/gcc/hppa-linux-gnu/7/:/usr/lib/gcc/hppa-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/hppa-linux-gnu/7/:/usr/lib/gcc/hppa-linux-gnu/7/../../../hppa-linux-gnu/:/usr/lib/gcc/hppa-linux-gnu/7/../../../:/lib/hppa-linux-gnu/:/lib/:/usr/lib/hppa-linux-gnu/:/usr/lib/
COLLECT_GCC_OPTIONS='-nostdlib' '-nostartfiles' '-o' '/home/amodra/build/glibc32/elf/tst-tls2' '-v'
 /usr/lib/gcc/hppa-linux-gnu/7/collect2 -plugin /usr/lib/gcc/hppa-linux-gnu/7/liblto_plugin.so -plugin-opt=/usr/lib/gcc/hppa-linux-gnu/7/lto-wrapper -plugin-opt=-fresolution=/tmp/cct34pSM.res --sysroot=/ --build-id --eh-frame-hdr -dynamic-linker /lib/ld.so.1 -o /home/amodra/build/glibc32/elf/tst-tls2 -L/usr/lib/gcc/hppa-linux-gnu/7 -L/usr/lib/gcc/hppa-linux-gnu/7/../../../hppa-linux-gnu -L/usr/lib/gcc/hppa-linux-gnu/7/../../.. -L/lib/hppa-linux-gnu -L/usr/lib/hppa-linux-gnu -z combreloc -z relro --hash-style=both /home/amodra/build/glibc32/csu/crt1.o /home/amodra/build/glibc32/csu/crti.o /usr/lib/gcc/hppa-linux-gnu/7/crtbegin.o /home/amodra/build/glibc32/elf/tst-tls2.o /home/amodra/build/glibc32/support/libsupport_nonshared.a -dynamic-linker=/home/amodra/gnu/hppa-linux-gnu/lib/ld.so.1 -rpath-link=/home/amodra/build/glibc32:/home/amodra/build/glibc32/math:/home/amodra/build/glibc32/elf:/home/amodra/build/glibc32/dlfcn:/home/amodra/build/glibc32/nss:/home/amodra/build/glibc32/nis:/home/amodra/build/glibc32/rt:/home/amodra/build/glibc32/resolv:/home/amodra/build/glibc32/crypt:/home/amodra/build/glibc32/mathvec:/home/amodra/build/glibc32/support:/home/amodra/build/glibc32/nptl /home/amodra/build/glibc32/libc.so.6 /home/amodra/build/glibc32/libc_nonshared.a --as-needed /home/amodra/build/glibc32/elf/ld.so --no-as-needed -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/hppa-linux-gnu/7/crtend.o /home/amodra/build/glibc32/csu/crtn.o -v
collect2 version 7.3.0
/usr/bin/hppa-linux-gnu-ld -plugin /usr/lib/gcc/hppa-linux-gnu/7/liblto_plugin.so -plugin-opt=/usr/lib/gcc/hppa-linux-gnu/7/lto-wrapper -plugin-opt=-fresolution=/tmp/cct34pSM.res --sysroot=/ --build-id --eh-frame-hdr -dynamic-linker /lib/ld.so.1 -o /home/amodra/build/glibc32/elf/tst-tls2 -L/usr/lib/gcc/hppa-linux-gnu/7 -L/usr/lib/gcc/hppa-linux-gnu/7/../../../hppa-linux-gnu -L/usr/lib/gcc/hppa-linux-gnu/7/../../.. -L/lib/hppa-linux-gnu -L/usr/lib/hppa-linux-gnu -z combreloc -z relro --hash-style=both /home/amodra/build/glibc32/csu/crt1.o /home/amodra/build/glibc32/csu/crti.o /usr/lib/gcc/hppa-linux-gnu/7/crtbegin.o /home/amodra/build/glibc32/elf/tst-tls2.o /home/amodra/build/glibc32/support/libsupport_nonshared.a -dynamic-linker=/home/amodra/gnu/hppa-linux-gnu/lib/ld.so.1 -rpath-link=/home/amodra/build/glibc32:/home/amodra/build/glibc32/math:/home/amodra/build/glibc32/elf:/home/amodra/build/glibc32/dlfcn:/home/amodra/build/glibc32/nss:/home/amodra/build/glibc32/nis:/home/amodra/build/glibc32/rt:/home/amodra/build/glibc32/resolv:/home/amodra/build/glibc32/crypt:/home/amodra/build/glibc32/mathvec:/home/amodra/build/glibc32/support:/home/amodra/build/glibc32/nptl /home/amodra/build/glibc32/libc.so.6 /home/amodra/build/glibc32/libc_nonshared.a --as-needed /home/amodra/build/glibc32/elf/ld.so --no-as-needed -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/hppa-linux-gnu/7/crtend.o /home/amodra/build/glibc32/csu/crtn.o -v
GNU ld (GNU Binutils for Debian) 2.30
COLLECT_GCC_OPTIONS='-nostdlib' '-nostartfiles' '-o' '/home/amodra/build/glibc32/elf/tst-tls2' '-v'

Oh yeah, configured with --with-ld=/usr/bin/hppa-linux-gnu-ld
Blah, so I'll need to build my own gcc to do proper testing on that
box.

> I've included Dave on the TO, to see if he's interested in testing this
> a little more widely.
> 
> -- 
> Cheers,
> Carlos.

-- 
Alan Modra
Australia Development Lab, IBM


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