From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id DF1DE3858C74 for ; Fri, 6 Jan 2023 21:14:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF1DE3858C74 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-x234.google.com with SMTP id r205so2098415oib.9 for ; Fri, 06 Jan 2023 13:14:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.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=JY6SErGBTwuZcRSvlG9Y7yBOeEZNsxxsapzrtU6vXXY=; b=fsdU5FjttzcpERsRixTuP24LE3z+6A5LbtF3urUkA57EoGmX4qBHyJSq5slr7t3xcl 2IRwnt+b/d46bhavOW4LnQqcbm/AdCU6xfddW874uDbHeiRhbRdge9UoKOhehS9FLgyI ofSnMRAnlV3y5nSdD7qiCsU3s4q+8S+5KUU4TSYOTv8dxZ1Z+uH7lIoiWeQ8/Idm/mfq lXvVJdfcfUtbTq6dzT+b+Do9jeOZHr3+l4l+uGoEfDKX1hLd+SRwzFtbVXg/D31f1pOQ G/F5/lhPSouQtu1oUpXWD7fkqCn/qiJaXQi821SDACyx3uNMzHDYtQeWektsEKy/tlTd SSRg== 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=JY6SErGBTwuZcRSvlG9Y7yBOeEZNsxxsapzrtU6vXXY=; b=ljZ5eRRH4KhL08nl1YyHaKWn/tpqu0jlgQNCsoZbTt53ci2u3vZWj394NP31Dcc+Vw 5UY1OhbI/U3aM1/d4516XzlaCwd+laQG/sbUVYUtwWXC/VXZCh82Orixpg2I0c0WynED GzChB14VDc4B2maoID80m+hEQsYZMtn6viGE/Okzq2fQ9rr0HgrGbdTAs5HPv4M16u9s UXV6vO27vUqJACfHB8OJRagjv9frnWTVk/B6JxeHU1/a75ON3gjkk+r1hCBhIgEcju7T 36dUjpd44BCD+waF3NsA+TUfZqey+ZJrm8rXkby4UeHRsciw7rXl44mXiU2cey/ub/ut 2DMg== X-Gm-Message-State: AFqh2kq4HWgpeu9tVdCWLQeny8+tXYhrl2CfXNQ+d/khYaJ+CBB5PHAU fKhCbAYmGdn/9VrUprRwDJIApgfzTjzLMIKBR1E= X-Google-Smtp-Source: AMrXdXsySCaGDc+wr9DgS6MlrvN7nE6t1KfYqDA1Wlzz6jGjexQdg5cmJoG9wprSIAcg/pCLd4PAUjJXaQhkd9hR9cw= X-Received: by 2002:a54:4596:0:b0:364:856:31a4 with SMTP id z22-20020a544596000000b00364085631a4mr350040oib.298.1673039673116; Fri, 06 Jan 2023 13:14:33 -0800 (PST) MIME-Version: 1.0 References: <20230105210542.3573076-1-maskray@google.com> In-Reply-To: From: "H.J. Lu" Date: Fri, 6 Jan 2023 13:13:57 -0800 Message-ID: Subject: Re: [PATCH] ld: Allow R_X86_64_GOTPCREL for call *__tls_get_addr@GOTPCREL(%rip) To: Fangrui Song Cc: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3021.5 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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 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=3Dno > > > /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 =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_X8= 6_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 sequ= ence. > > > > -- > > 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? > 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 --=20 H.J.