From: "H.J. Lu" <hjl.tools@gmail.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: binutils@sourceware.org, Fangrui Song <maskray@google.com>
Subject: Re: [PATCH] ld: Allow R_X86_64_GOTPCREL for call *__tls_get_addr@GOTPCREL(%rip)
Date: Tue, 10 Jan 2023 12:39:45 -0800 [thread overview]
Message-ID: <CAMe9rOoEWC=M6GOCsx-jgjYgVGmMRYUdriDTHVp-ZPMNusOBsQ@mail.gmail.com> (raw)
In-Reply-To: <0c9cd182-ce08-6720-1e51-d7171f075641@suse.com>
On Tue, Jan 10, 2023 at 1:16 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 09.01.2023 22:14, H.J. Lu wrote:
> > On Mon, Jan 9, 2023 at 12:15 AM Jan Beulich <jbeulich@suse.com> wrote:
> >>
> >> On 06.01.2023 18:03, H.J. Lu via Binutils wrote:
> >>> On Thu, Jan 5, 2023 at 1:06 PM Fangrui Song via Binutils
> >>> <binutils@sourceware.org> wrote:
> >>>>
> >>>> _Thread_local int a;
> >>>> int main() { return a; }
> >>>>
> >>>> % gcc -fno-plt -fpic a.c -fuse-ld=bfd -Wa,-mrelax-relocations=no
> >>>> /usr/bin/ld.bfd: /tmp/ccSSBgrg.o: TLS transition from R_X86_64_TLSGD to R_X86_64_GOTTPOFF against `a' at 0xd in section `.text' failed
> >>>> /usr/bin/ld.bfd: failed to set dynamic section sizes: bad value
> >>>> collect2: error: ld returned 1 exit status
> >>>>
> >>>> This commit fixes the issue.
> >>>>
> >>>> PR ld/24784
> >>>> * bfd/elf64-x86-64.c (elf_x86_64_check_tls_transition): Allow
> >>>> R_X86_64_GOTPCREL.
> >>>> ---
> >>>> bfd/elf64-x86-64.c | 2 +-
> >>>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>>>
> >>>> diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
> >>>> index 914f82d0151..095fe2e0fe6 100644
> >>>> --- a/bfd/elf64-x86-64.c
> >>>> +++ b/bfd/elf64-x86-64.c
> >>>> @@ -1241,7 +1241,7 @@ elf_x86_64_check_tls_transition (bfd *abfd,
> >>>> if (largepic)
> >>>> return r_type == R_X86_64_PLTOFF64;
> >>>> else if (indirect_call)
> >>>> - return r_type == R_X86_64_GOTPCRELX;
> >>>> + return (r_type == R_X86_64_GOTPCRELX || r_type == R_X86_64_GOTPCREL);
> >>>> else
> >>>> return (r_type == R_X86_64_PC32 || r_type == R_X86_64_PLT32);
> >>>> }
> >>>> --
> >>>> 2.39.0.314.g84b9a713c41-goog
> >>>>
> >>>
> >>> Since the new TLS sequence was added after R_X86_64_GOTPCRELX was
> >>> required for call, R_X86_64_GOTPCREL should be invalid in this TLS sequence.
> >>
> >> While this may well be, would you mind pointing out (more to Fangrui than to
> >> me) what bad his proposed change would do?
> >
> > The problem is caused by the combination of -fno-plt and
> > -Wa,-mrelax-relocations=no.
> > -Wa,-mrelax-relocations=no was added to generate object files to be
> > consumed by the
> > older linkers. On the other hand, -fno-plt requires newer linkers.
> > As the result,
> > -fno-plt -Wa,-mrelax-relocations=no generates object files which
> > aren't compatible
> > with neither older linkers nor newer linkers.
> > -Wa,-mrelax-relocations shouldn't be used
> > together with -fno-plt.
>
> Imo use of such option combinations should either be disallowed (warned
> about at the very least) or produce sensible output. I guess only the
> latter would help Fangrui ...
>
This isn't a supported combination. I believe -Wa,-mrelax-relocations=no
should be removed.
--
H.J.
next prev parent reply other threads:[~2023-01-10 20:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-05 21:05 Fangrui Song
2023-01-06 17:03 ` H.J. Lu
2023-01-06 18:48 ` Fangrui Song
2023-01-06 21:13 ` H.J. Lu
2023-01-06 21:25 ` Fangrui Song
2023-01-06 21:26 ` H.J. Lu
2023-01-06 21:44 ` Fangrui Song
2023-01-06 22:41 ` H.J. Lu
2023-01-06 23:02 ` Fangrui Song
2023-01-06 23:20 ` H.J. Lu
2023-01-06 23:52 ` Fangrui Song
2023-01-07 0:01 ` H.J. Lu
2023-01-09 8:15 ` Jan Beulich
2023-01-09 21:14 ` H.J. Lu
2023-01-10 9:16 ` Jan Beulich
2023-01-10 20:39 ` H.J. Lu [this message]
2023-01-10 21:02 ` Fangrui Song
2023-01-11 9:01 ` Jan Beulich
2023-01-11 8:10 ` Jan Beulich
2023-03-02 11:37 ` Jan Beulich
2023-03-02 20:10 ` [PATCH v2] " Fangrui Song
2023-03-10 9:10 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMe9rOoEWC=M6GOCsx-jgjYgVGmMRYUdriDTHVp-ZPMNusOBsQ@mail.gmail.com' \
--to=hjl.tools@gmail.com \
--cc=binutils@sourceware.org \
--cc=jbeulich@suse.com \
--cc=maskray@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).