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]

[gold patch] Fix problem with x86_64 TLS optimization when code is reordered


This patch fixes a problem with link-time GD-to-LE optimization of TLS
sequences on x86_64 when code has been reordered by the compiler.

The GD-to-LE optimization for x86_64 needs to optimize a series of
three relocations: R_X86_64_TLSGD/LD, R_X86_64_GOTPC32_TLSDESC, and
R_X86_64_DTPOFF32/64. The R_X86_64_DTPOFF32/64 relocations, however,
are used in debug sections, so gold sets a flag, saw_tls_block_reloc_,
when it sees any of the first relocations in the series, and applies
the optimization on the third only if the flag is set. The compiler,
however, might rearrange the code (and has been observed to do so at
-Os) such that the R_X86_64_DTPOFF32 appears in the section before
either of the other two relocations, causing gold to leave the
R_X86_64_DTPOFF32 unoptimized. It goes on to optimize the other two
relocations, however, leaving the code in an inconsistent state that
results in a crash when executed.

This patch changes the logic so that the optimization is applied
consistently -- we always apply it in executable sections, and never
apply it in non-executable sections. As a result, the lone use of
R_X86_64_DTPOFF32/64 in a debug section works as intended, and the
code sequence in an executable section is properly optimized
regardless of static code arrangement. The code sequence in a
non-executable section will still work, but will not be optimized.

OK?

(Ian, if you prefer, I can submit the original patch we discussed
offline, which test for is_executable in addition to the existing
saw_tls_block_reloc_ flag. I prefer the stateless nature of this
patch, though, as it's simpler to verify that we apply the related
relocations consistently.)

-cary

        * x86_64.cc (Target_x86_64::saw_tls_block_reloc_): Remove member.
        (Target_x86_64::Relocate::relocate_tls): Replace check for
        saw_tls_block_reloc_ with test for executable section.

Attachment: gold-tls-patch.txt
Description: Text document


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