Bug 16340 - aarch64: offset into GOT for TLS relocation computed inconsistently
Summary: aarch64: offset into GOT for TLS relocation computed inconsistently
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-18 03:26 UTC by Michael Hudson-Doyle
Modified: 2014-03-31 08:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
simple proposed fix (336 bytes, patch)
2013-12-18 03:26 UTC, Michael Hudson-Doyle
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Hudson-Doyle 2013-12-18 03:26:54 UTC
Created attachment 7328 [details]
simple proposed fix

Hi,

I don't have a non-gigantic test case but it's possible for the offset into the GOT used when accessing a __thread variable to be different from that written into the relocation (modulo confusions with terminology :).

This is the code that determines the offset to patch into the code (elfnn-aarch64.c line 3845):

                   value = (symbol_got_offset (input_bfd, h, r_symndx)
                            + globals->root.sgot->output_section->vma
                            + globals->root.sgot->output_section->output_offset);

and this is the code that determines the offset as written into the relocation (elfnn-aarch64.c line 4248):

                           off = symbol_got_offset (input_bfd, h, r_symndx);
                           ...
                               rela.r_offset = globals->root.sgot->output_section->vma +
                                 globals->root.sgot->output_offset + off;

The former is "root.sgot->output_section->output_offset", the latter is "root.sgot->output_offset".

I'll attach a very simple patch that seems to fix the problem.  A test case would be nice, but is beyond my knowledge currently.
Comment 1 Will Newton 2014-03-31 08:14:15 UTC
Fixed by this commit:

commit f44a1f8e513b37bcc52ba9ea0c172c3e94852756
Author: Christophe Lyon <christophe.lyon@st.com>
Date:   Tue Jan 14 15:53:50 2014 +0100

    2014-01-14  Michael Hudson-Doyle  <michael.hudson@linaro.org>
            Kugan Vivekanandarajah  <kugan.vivekanandarajah@linaro.org>
    
        bfd/
        * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Use correct
        offset while calculating relocation address.
        (elfNN_aarch64_create_small_pltn_entry): Likewise.
        (elfNN_aarch64_init_small_plt0_entry): Likewise.