From patchwork Tue Jan 17 11:25:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 44644 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1698473wrn; Tue, 17 Jan 2023 03:25:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXstOxxzFFCVJe3EDtGssKODUCmgfgf1nw7eFdqsDNmbLXF2zX7zWKUhwKINVEI9c/MyYIh5 X-Received: by 2002:aa7:d559:0:b0:492:bf3d:1a16 with SMTP id u25-20020aa7d559000000b00492bf3d1a16mr2544721edr.4.1673954733560; Tue, 17 Jan 2023 03:25:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673954733; cv=none; d=google.com; s=arc-20160816; b=FclgpN1hvRjJjLNgFE+3ROSGKxl/vfSm4cntNdoOQuS0CW4npu8aF0PotECYT8zfRI TIQP9x4OpWWUs9p3AdmLWJPfqrNNxL+QD9bvWVBYQXGwviGbNqXyFZQT05BSbBapXjeU 5lC+njrX8PyiBLEGPXC2VQuYZPF+Xo3ajBhSu9FgzaUHMDEojRV4BUKYUYCBGlclhGPX CK7a3YglDIgaEpNcsp+4oEzi3xeri2UW3v0VlH0RNw2fi5umJFgMQQPRi8RTRyzVuJiO xuLXLxpCzjBaiDgNaEdVH4EeU4EezV9EC5adc2bNL/YiKa5M+xq2BJ71nN/VCe76bJfU PZNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=kGjhwVqbMXb6vDC33kMInvehQL4doyqXhPzAwsPyRw8=; b=oou0n95SpbCrqsuuTJjHU+M9u0X0GN75jV1hfx4w5a9g/qra8EnG6umKAbpQHKMl8I wt+0JhUy35Lti5ZM2XkcvnfRDhpgu/K0O+oO4Z36bCBVj+FiNDC6SAzkQ46g2EliogpR SAVGB3peWknF1mjBp3DDVHIsX4a8KM4Xox2TojfuDEL8WCFEQ5DlyC9rCp6j6xyg6dFc f9joJ+oDoYw9LZrkywenVbgmIjuIt9RkgCt4+eNfEkMEtKbgRS3TXgaxUhbIh8mtP0f3 6v6W27mwAVhKFAvZSOZxHKVCn8h6gK5ZN8PIJkvES1+dV+OQOzueXG9L+jTGZFfM2mQ+ scrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CeBiTec.Uni-Bielefeld.DE header.s=20200306 header.b=boVGuiSe; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t4-20020a056402240400b00499b52316fesi27554166eda.326.2023.01.17.03.25.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 03:25:33 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@CeBiTec.Uni-Bielefeld.DE header.s=20200306 header.b=boVGuiSe; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71B123858C53 for ; Tue, 17 Jan 2023 11:25:32 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp.CeBiTec.Uni-Bielefeld.DE (smtp.CeBiTec.Uni-Bielefeld.DE [129.70.160.84]) by sourceware.org (Postfix) with ESMTPS id 4063E3858D28 for ; Tue, 17 Jan 2023 11:25:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4063E3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=CeBiTec.Uni-Bielefeld.DE Authentication-Results: sourceware.org; spf=none smtp.mailfrom=cebitec.uni-bielefeld.de Received: from localhost (localhost [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id 0063B14216; Tue, 17 Jan 2023 12:25:25 +0100 (CET) X-Virus-Scanned: amavisd-new at CeBiTec.Uni-Bielefeld.DE Received: from smtp.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (smtp.cebitec.uni-bielefeld.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 85dEKN0Lc1ZF; Tue, 17 Jan 2023 12:25:24 +0100 (CET) Received: from manam.CeBiTec.Uni-Bielefeld.DE (p508548b7.dip0.t-ipconnect.de [80.133.72.183]) (Authenticated sender: ro) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPSA id 2EF49140C2; Tue, 17 Jan 2023 12:25:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=CeBiTec.Uni-Bielefeld.DE; s=20200306; t=1673954724; bh=MD2nNFEHkvczU/GReYG+mid3XfSoLfe3UxVgYJMsOe8=; h=From:To:Cc:Subject:Date:From; b=boVGuiSe37GXFWB0noZNAjDEnkjK4Ne0vDJ5K41xlOxatgj6M0EeyYJ9FZCY8p5Zy jxpmYk0G3GuW/HFAIA4Ty9VwqBev/5hW0MJu/jJ6HGO6OvFE+3+2e5qap6d+M0U4Gq 4pGVXyZtWBnBWup6qZl1EyTyqifwuitdTmGt75XcCkbsL0CVsjgEpV9fl2PDA4ErXg XAjF7UYtnRyq+XmYMCIfU4xh/kMPJFqFIN5Vv38i4RmtzQQK/xZg4hzAR5CkEzNq2P DVYS3NLW3IFC+62M1iphjyZ+i6fLoVfxe95raNAAJbKwiPY+f2XxP7lTXuV4vW0UMt YZ5gAFARim34Q== From: Rainer Orth To: binutils@sourceware.org Cc: hjl.tools@gmail.com Subject: [PATCH] i386: Don't emit unsupported TLS relocs on Solaris [PR13671] Date: Tue, 17 Jan 2023 12:25:23 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1.90 (usg-unix-v) MIME-Version: 1.0 X-Spam-Status: No, score=-3794.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755268758293848338?= X-GMAIL-MSGID: =?utf-8?q?1755268758293848338?= As detailed in PR ld/13671, gld can emit R_386_TLS_TPOFF32 relocs which the Solaris/x86 ld.so.1 doesn't know about, so the resulting executables won't run. The following patch, which H.J. provided in the PR, fixes this. Tested on i386-pc-solaris2.11 (both with the binutils testsuite and a full gcc bootstrap) and i686-pc-linux-gnu. Already approved by H.J. in the PR, but it's probably best if someone double-checks the ChangeLog entry. Rainer diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -1062,6 +1062,7 @@ elf_i386_tls_transition (struct bfd_link unsigned int from_type = *r_type; unsigned int to_type = from_type; bool check = true; + unsigned int to_le_type, to_ie_type; /* Skip TLS transition for functions. */ if (h != NULL @@ -1069,6 +1070,18 @@ elf_i386_tls_transition (struct bfd_link || h->type == STT_GNU_IFUNC)) return true; + if (get_elf_backend_data (abfd)->target_os == is_solaris) + { + /* NB: Solaris only supports R_386_TLS_LE and R_386_TLS_IE. */ + to_le_type = R_386_TLS_LE; + to_ie_type = R_386_TLS_IE; + } + else + { + to_le_type = R_386_TLS_LE_32; + to_ie_type = R_386_TLS_IE_32; + } + switch (from_type) { case R_386_TLS_GD: @@ -1080,10 +1093,10 @@ elf_i386_tls_transition (struct bfd_link if (bfd_link_executable (info)) { if (h == NULL) - to_type = R_386_TLS_LE_32; + to_type = to_le_type; else if (from_type != R_386_TLS_IE && from_type != R_386_TLS_GOTIE) - to_type = R_386_TLS_IE_32; + to_type = to_ie_type; } /* When we are called from elf_i386_relocate_section, there may @@ -1093,7 +1106,7 @@ elf_i386_tls_transition (struct bfd_link unsigned int new_to_type = to_type; if (TLS_TRANSITION_IE_TO_LE_P (info, h, tls_type)) - new_to_type = R_386_TLS_LE_32; + new_to_type = to_le_type; if (to_type == R_386_TLS_GD || to_type == R_386_TLS_GOTDESC @@ -1102,7 +1115,7 @@ elf_i386_tls_transition (struct bfd_link if (tls_type == GOT_TLS_IE_POS) new_to_type = R_386_TLS_GOTIE; else if (tls_type & GOT_TLS_IE) - new_to_type = R_386_TLS_IE_32; + new_to_type = to_ie_type; } /* We checked the transition before when we were called from @@ -1116,7 +1129,7 @@ elf_i386_tls_transition (struct bfd_link case R_386_TLS_LDM: if (bfd_link_executable (info)) - to_type = R_386_TLS_LE_32; + to_type = to_le_type; break; default: @@ -2024,6 +2037,7 @@ elf_i386_relocate_section (bfd *output_b Elf_Internal_Rela *wrel; Elf_Internal_Rela *relend; bool is_vxworks_tls; + unsigned expected_tls_le; unsigned plt_entry_size; /* Skip if check_relocs or scan_relocs failed. */ @@ -2853,9 +2867,17 @@ elf_i386_relocate_section (bfd *output_b relend, h, r_symndx, true)) return false; - if (r_type_tls == R_386_TLS_LE_32) + expected_tls_le = htab->elf.target_os == is_solaris + ? R_386_TLS_LE : R_386_TLS_LE_32; + if (r_type_tls == expected_tls_le) { - BFD_ASSERT (! unresolved_reloc); + /* NB: Solaris only supports R_386_TLS_GD->R_386_TLS_LE. */ + BFD_ASSERT (! unresolved_reloc + && (htab->elf.target_os != is_solaris + || (htab->elf.target_os == is_solaris + && (r_type == R_386_TLS_GD + || r_type == R_386_TLS_IE + || r_type == R_386_TLS_GOTIE)))); if (r_type == R_386_TLS_GD) { unsigned int type; @@ -3352,7 +3374,9 @@ elf_i386_relocate_section (bfd *output_b into: movl %gs:0, %eax leal 0(%esi), %esi */ - BFD_ASSERT (r_type == R_386_TLS_LE_32); + expected_tls_le = htab->elf.target_os == is_solaris + ? R_386_TLS_LE : R_386_TLS_LE_32; + BFD_ASSERT (r_type == expected_tls_le); if (*(contents + rel->r_offset + 4) == 0xff || *(contents + rel->r_offset + 4) == 0x67) memcpy (contents + rel->r_offset - 2,