From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 8E09A3858D28 for ; Fri, 6 Jan 2023 21:25:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E09A3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=google.com Received: by mail-pl1-x62c.google.com with SMTP id p24so2978537plw.11 for ; Fri, 06 Jan 2023 13:25:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BZ6D8FenOaqN16F1pikunCMLb662BHJvIQw8lVnppuo=; b=RLFRsXQpE48WAvsngWngr6PiDGbCvTi547t7ruAbNQZFCAyZW2Cf9hr8j5qGRCCPz6 y4iJCpjtrjBwKUDgw9/tDCDb7sZUM7J49sdr1pVm9cik/s4vBUhALlx5I74B7dT8JNiF bxmiPwHkUGNk4GvA4pcJoCt6Ofvjet7vancV9qCJOkgUKzfQL6wOBLW1Sj5BAbJRF4Jo tJrl/9DHYtGenvHrwLe8nxIkJoMp1IG7Yj1CeS4oDLZ2b1c/N8+FlvQqKMktLYMBkgEZ ByL6WVq9+49bv0QGY8ZZKZyop/I9cGGxZ/U8ht/JNy54kZ6k9BakdvY0dWIFUpt2xl2u 9syA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BZ6D8FenOaqN16F1pikunCMLb662BHJvIQw8lVnppuo=; b=RrlnrKGnZ2fAZm/2KJy082jWRJbRrEiKFrBY1Br7WrYrw+weNDos4uBYmjIjmWsPBe WZRKeAhwxar6ZhBvRqbVTyLFTemyOIzlfwPxl3vLqO6FVVUuX4EpYtS5iJeqLoEJiNpw rsahUwEaJux5O7njd8Hzj64SmY83ZmC7vvtMvC6GnGZJ8iqGxzyfuNx2yFgM9jHzxc2a 3oS7ikNpy7PE4VTkEL1ceD8qdAMg/h2UpgZFAGwRfs5yNdNUBgQXvBrA6glcwherxATz VAfp6udahjGzcaxw1Md9Ir/1YRZAg1bRoz3iq6FYVcmXPpvtdjNr9Wgr1CbbronKnpHp A3vQ== X-Gm-Message-State: AFqh2krHKakBemC2akXmfGHMThk2d/CCxbTELrli/3q3L4pvodxLhNUK QUIsfpyO0a45d3qSkWBLxJxSTrECVolb0YTe0CcaDbVAP4QrbX/n X-Google-Smtp-Source: AMrXdXt4ZasuPEMr1y7I3cCHKG5HxUfKJraAOTNBr4NdvXcme8FO7kceUkaZDqXFkx88BQRE6doX+XixUSyey0A6NM8= X-Received: by 2002:a17:902:ce10:b0:192:9568:a700 with SMTP id k16-20020a170902ce1000b001929568a700mr2192893plg.42.1673040324464; Fri, 06 Jan 2023 13:25:24 -0800 (PST) MIME-Version: 1.0 References: <20230105210542.3573076-1-maskray@google.com> In-Reply-To: From: Fangrui Song Date: Fri, 6 Jan 2023 13:25:12 -0800 Message-ID: Subject: Re: [PATCH] ld: Allow R_X86_64_GOTPCREL for call *__tls_get_addr@GOTPCREL(%rip) To: "H.J. Lu" Cc: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-23.4 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Jan 6, 2023 at 1:14 PM H.J. Lu wrote: > > On Fri, Jan 6, 2023 at 10:48 AM Fangrui Song wrote: > > > > On Fri, Jan 6, 2023 at 9:04 AM H.J. Lu wrote: > > > > > > On Thu, Jan 5, 2023 at 1:06 PM Fangrui Song via Binutils > > > wrote: > > > > > > > > _Thread_local int a; > > > > int main() { return a; } > > > > > > > > % gcc -fno-plt -fpic a.c -fuse-ld=3Dbfd -Wa,-mrelax-relocations=3Dn= o > > > > /usr/bin/ld.bfd: /tmp/ccSSBgrg.o: TLS transition from R_X86_64_TLSG= D 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 =3D=3D R_X86_64_PLTOFF64; > > > > else if (indirect_call) > > > > - return r_type =3D=3D R_X86_64_GOTPCRELX; > > > > + return (r_type =3D=3D R_X86_64_GOTPCRELX || r_type =3D= =3D R_X86_64_GOTPCREL); > > > > else > > > > return (r_type =3D=3D R_X86_64_PC32 || r_type =3D=3D 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 se= quence. > > > > > > -- > > > H.J. > > > > I have multiple arguments (albeit no single one is very strong) that > > this 1-deletion-1-addition change provides benefits for users (IMHO > > with no burden to binutils at all). > > > > Some projects may add -Wa,-mrelax-relocations=3Dno to work around older > > GNU ld. Then the project's toolchain requirement may increase and no > > longer need to work around older GNU ld. > > But a distribution may for some reason use a global -fno-plt (e.g. > > Arch Linux) and then run into this TLS GD/LD->IE/LE optimization > > issue. > > > > rust src/ci/docker/host-x86_64/*musl/Dockerfile > > openjdk/jdk19u make/autoconf/flags-cflags.m4 (this file appears to be > > copied into quite a few projects) > > Linux kernel arch/x86/boot/compressed/Makefile (not a good example as > > it doesn't use TLS AFAICT) > > > > R_X86_64_GOTPCREL isn't purely usefull. It may help linker design: for > > R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX, the linker can make a > > decision upfront whether a GOT entry is needed > > (this affects the size of .got, which may affect section layout and > > whether other relocations may overflow). > > This may increase risk of 32-bit relocation overflow. > > R_X86_64_GOTPCREL can mitigate the risk while being aware to the user. > > > > rustc somehow disables x86 relaxed relocations and defaults to `-Z > > Why is that? It's assuredly a rust's problem and I am trying to fix that in https://github.com/rust-lang/rust/pull/106511 The -Wa,-mrelax-relocations=3Dno problem may affect more packages. > > plt=3Dno` and now relies on llvm-project to work around the GNU ld > > compatibility issue. > > > > > > > > > > -- > > =E5=AE=8B=E6=96=B9=E7=9D=BF > > > > -- > H.J. --=20 =E5=AE=8B=E6=96=B9=E7=9D=BF