From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by sourceware.org (Postfix) with ESMTPS id EC9B63858D33 for ; Tue, 10 Jan 2023 20:40:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC9B63858D33 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-oa1-x29.google.com with SMTP id 586e51a60fabf-1442977d77dso13412154fac.6 for ; Tue, 10 Jan 2023 12:40:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=aViKBaz09KNNZwTNBvS7IjnzVUEyWCsJbSjRaMs973U=; b=Z8rt/BrFo1BWgGGl1K5qM0uM4nKb8YTCPgyKQvxhb6kINby7l0YuJizBOTMRU4Z4dK gF1tXd/V0clMXLa7XynBFZxVn6e5Csx9zUr3LUhI4a8AGR9uVcvFIN+i0buON6HHmDsl Ck9sDLynXppfUHI/3x4kgzP2OsY/DVZCswMAQC/JNJlw6ON47vtfq7VtB+x662NRmW+L J1hnTHSzqxlNosfrtnq6iF6dUdyq+GRl14qJaIjZB0PtHeOgu+yAW61yc8FdhVpafF3V CdoUOtvFvm6fcD90P0ix51uU7gcEHV27DnAR1otxwDeDpanNtZWCGRcj8rpK8kYJ+sII h/Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=aViKBaz09KNNZwTNBvS7IjnzVUEyWCsJbSjRaMs973U=; b=tvrZw/kIWaDRF5uUrMLImDtWnHBD/3NP5eQT4FL1QsOGxs60qplcQSzT0ZEYaFIwfb sE2lArgPtwhs1Wtct0KAOw4MLqsI0S33Kvy34oxHL61m2eYjteNF55Kly8Jg4VnvidTT gOEjlllnZizBLJt9itHypOj6KF8557O1Yrsz9uLxWBRneYO6B/gP3nPoJZByneEH+N48 275G1NZrFiEc0AdHdweBe+xIsbcE8ZT0RxqkeUg20F7sfuulPs63C+xm1GibmzVNHH5i Zbl6xPWE/2SY13OJUYRU/NFGuvD5epsD2njJ85kD14mcSY0Ql+X7LqxFeIApBeM6yG8H 2Pwg== X-Gm-Message-State: AFqh2koZV/58yPpg9ho6Uk3OD+W1hI6zflrd5BGz0AOHi6QejfWWbNNw MbgvNCDB6XjRopewf5tnQKoNHaHhYSO7znGC2SznfTk7i5M= X-Google-Smtp-Source: AMrXdXvSZp15oEuvrmYZxXE8EG/Yt7VwyazaZxSmSKaIhK4Yhm/HkogdT7jHeFp4e7XSIB4LJiJcnVMzFU4yLgpt+dM= X-Received: by 2002:a05:6870:d202:b0:148:2c02:5323 with SMTP id g2-20020a056870d20200b001482c025323mr7183946oac.298.1673383221326; Tue, 10 Jan 2023 12:40:21 -0800 (PST) MIME-Version: 1.0 References: <20230105210542.3573076-1-maskray@google.com> <0c9cd182-ce08-6720-1e51-d7171f075641@suse.com> In-Reply-To: <0c9cd182-ce08-6720-1e51-d7171f075641@suse.com> From: "H.J. Lu" Date: Tue, 10 Jan 2023 12:39:45 -0800 Message-ID: Subject: Re: [PATCH] ld: Allow R_X86_64_GOTPCREL for call *__tls_get_addr@GOTPCREL(%rip) To: Jan Beulich Cc: binutils@sourceware.org, Fangrui Song Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3022.7 required=5.0 tests=BAYES_00,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 Tue, Jan 10, 2023 at 1:16 AM Jan Beulich wrote: > > On 09.01.2023 22:14, H.J. Lu wrote: > > On Mon, Jan 9, 2023 at 12:15 AM Jan Beulich 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 > >>> 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.