[PATCH, ARM] Bugfix for general dynamic TLS model when static linking

Julian Brown julian@codesourcery.com
Wed Feb 20 16:24:00 GMT 2013


Hi,

This patch (by Nathan Sidwell) fixes a case where the linker would
erroneously try to allocate a dynamic relocation corresponding to a
general dynamic TLS reloc when linking a static binary, leading to an
assertion failure later on in linking.

The motivating testcase was a statically-linked executable linked with
an unoptimized build of libstdc++. The latter contains a fragment like
so:

int *Foo ()
{
  static __thread int var;
  return &var;
}

which, when compiled with -O0, results in a general dynamic reloc
against a local symbol:

.L3:
	.word	var.4115(tlsgd) + (. - .LPIC0 - 8)

(incidentally when compiled with -O2 -fno-section-anchors, this becomes
a local dynamic access, which works correctly:

.L2:
	.word	var.4115(tlsldm) + (. - .LPIC0 - 8)
	.word	var.4115(tlsldo)

so there's actually shortcoming in the compiler too, but that's an
orthogonal issue).

The linker doesn't support relaxing the GD reloc in this case, but the
attached patch serves to fix the crash seen previously.

Tested (ld/gas/binutils) cross to ARM Linux. The new test case fails
without the patch, passes with it.

OK to apply?

Thanks,

Julian

ChangeLog

    Nathan Sidwell  <nathan@codesourcery.com>

    bfd/
    * elf32-arm.c (elf32_arm_size_dynamic_sections): Don't call
    elf32_arm_allocate_dynrelocs for source reloc for non-dynamic link.

    ld/testsuite/
    * ld-arm/tls-local-static.s: New test.
    * ld-arm/tls-local-static.d: New.
    * ld-arm/arm-elf.exp (tls-local-static): Add test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tls-gd-local-static-fix-2.diff
Type: text/x-patch
Size: 3243 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20130220/07c3bb49/attachment.bin>


More information about the Binutils mailing list