From patchwork Mon Feb 19 07:09:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 202913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1121987dyc; Sun, 18 Feb 2024 23:09:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVmnAa2E0TfxPSUGN91KRnJOBjjGh5s3YoC1KAEZnWHBhRxqOx3U0FjFTCEV1Gg9jlpktXafMcGKN94RzNE9yB14V/2ZQ== X-Google-Smtp-Source: AGHT+IGyKdjsfEgal/LnIfN3amrij7Tu2uLKuWBKgohm0qGC2ifcpWLro3kRYLUgfb8wbWI6viOI X-Received: by 2002:a05:620a:22e8:b0:787:3e08:bbc with SMTP id p8-20020a05620a22e800b007873e080bbcmr9518349qki.20.1708326595346; Sun, 18 Feb 2024 23:09:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708326595; cv=pass; d=google.com; s=arc-20160816; b=hyHLymWVWjmj2Qzq2avzBSBrRCIgCMqo8AEHQWb3Pgm00WEKe+ym4AzBgue4STQ9rD lHFM4/17+AFSAp3vtyPXmeze7kzyGv9PZ9pgZ2sF44bmR0HUraQZj6oH9A/jEmEt3l9A ShK2GWkifUX1/M9BdHoQjQKbxAFQxVhZqw7i/NYFsZYZyilWzwbvQHQ/QQO91R1zPlJm iYYUs7zrU+08UKa6z+MB4oLPMXaymKckrnxmcP/eOVtEV8Kg1Y1ow/VjcemIrakcDOIL 89V/xCtJzAOP0SP4jGau5I2zbxKgxT8ZexyCPGIBerDLtrfq4S52aPS+6Qu9/m1X918M Vg4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding:cc:to :from:subject:message-id:mime-version:date:dkim-signature:arc-filter :dmarc-filter:delivered-to; bh=afBcEpSmB0GluOsU5W0bin/5rsOQYjEagkk21S0Fn10=; fh=XYDXTIH7ZSjycsIOTWBnD8dbcaLzkKmghgMQXh5YpoQ=; b=Ve3SCRXDfjpoXdvngJlC/GrPrAImnnkxmhgEjoy2cf4p3fSPDcxhng4Rsi/mlWjxe4 H5eve3F3f4yt1szvvmNc9sQ/Rs890bXXojVcVOEfLphXqmORrz/bD7RBkjPF0t37COFv UP4ukQjLbnSWwFztTr68+IN5l0FM6VAQxG0fFSRaiNZnb8bomcUtKO5hB9DLdoyshL4H ihv71kn9nkpOFGHob5su56Dbr7gpy+7wSG96CrU5fcujD277QEaMlZeD4aJRaa6K4ySR QZKxj6JtRbRm3F73w5wi30khlhtGEcK72fvfi8yaHeUwvvelxD1ReByDNq3Idkb5H+2Z 3Yqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cSVPDrKK; arc=pass (i=1); 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"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w1-20020a05620a444100b007876fd89d56si135570qkp.474.2024.02.18.23.09.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 23:09:55 -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=@google.com header.s=20230601 header.b=cSVPDrKK; arc=pass (i=1); 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"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 129CB3861863 for ; Mon, 19 Feb 2024 07:09:55 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by sourceware.org (Postfix) with ESMTPS id 17BFA385801C for ; Mon, 19 Feb 2024 07:09:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17BFA385801C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=flex--maskray.bounces.google.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 17BFA385801C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1149 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708326585; cv=none; b=bQRPKww/WaQKVnFEtIl+rGxCqYH1kdLOPuSV8+0xlI0YNTZMw+552CtoA1ZafWHiy+DzO+Ge2l/UKCqCHd7bSoSD+6b8WU2nBEj94bb16Fh783hFtW3ExDUw+sbCjhuDggmTfGCmVmbTROFAtuCXXUOKqZpkaPsrbJWYYA2jwpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708326585; c=relaxed/simple; bh=yfH0wowgM+JpSd7sfIKuQqbnJeNXMMXdNm7fljyGO/Y=; h=DKIM-Signature:Date:Mime-Version:Message-ID:Subject:From:To; b=DwMwiLUNPdI4yorxBIadzd4MCUeUeEZyh5BFhbdP1bhcQRlBd+sXo+HrNPvHuLxtk4WoY5tCpkD0/q6w7BtuwmDGCNhqlgwgOfVSaDZ60vMsHFqLaDqkMJ/gVsqdUm3KwRbd/VWGiKnB+YytaXbMB+DuntefzHYpP+ANbpws6qU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-60770007e52so38537717b3.1 for ; Sun, 18 Feb 2024 23:09:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708326583; x=1708931383; darn=sourceware.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=afBcEpSmB0GluOsU5W0bin/5rsOQYjEagkk21S0Fn10=; b=cSVPDrKK5Fihy/XNacbyqEliHCQSXoD/NrxyUVjYtsAN3FEYvOUptGPd+9qp39xEUc AR8cqO17DVC0v+gxltnsqHdYFUuGLA8Bpl2pEpwglLCiT1EJc8t6vVP4txCS5FBmf5ax b8Ms47uTwBoUSA0CsBduEgB038Dsgczya2PfQkWCPkPGrBBUurwbzFhvYVJ9S2Ymp3+W Yd7Rxx4W0XeAcAg+qBGoYypsUmYWx3RqXGw1b4uM5tUgUhc+cG5zCKO+05tfmtN5Hepn u6gg946jlXlTqlvJPm8yQ4kL+vpbXHZrJuiJsO6tN3/6B4pA6msYwc7z9iHzLeepMzC3 CYxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708326583; x=1708931383; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=afBcEpSmB0GluOsU5W0bin/5rsOQYjEagkk21S0Fn10=; b=ZJZ76/WhySO9X6pWoAeWgaBHNra9ovj/qtqjnhPMgRDGmdRSvJuEhGT30kWTCatBnV GMzaOKUYxOh6hLjjekkWbUqS0aBiNiI9FnoIsWPwEe9PdliwgRDiUTJm8J4h3wXTva4E 1OygA213fxkVpDAqrpA6X8WOMpo/Bw+hlzioqH5vxh6gpFlpqeAUl3mWlMf+jU0buToS P0G3RAjtjzOa5I9f0UxxRvHkOy+MnISgmlWKETQy03KjzY4zHuzmA4BSi+bBPiRtBnXz bDZOm0iBsZv6W6zIkeYUXBn8xfnnCOLEMP0GdId+HIZieJ3/0hNTcqx1QGWiNCEexfPb CPLA== X-Forwarded-Encrypted: i=1; AJvYcCXRyjQ0RdEBlfivn0nQDUWViAbJPar5S5onBm4pGLOeEms4CcooSRiAGyFBPst/TSUo17n/z96KXP2EWZ4aTg2ASslMxIe5Vg== X-Gm-Message-State: AOJu0YyxKcew6mEkh3QLIqog0/syHk4vh4jOSmWPXgkMSq7Bw4OYcYh0 A1FcaCEIV83fwXP35qSTU+6gcJf2Bp42K8dybG/8VIbQvvm3/HK7JQdP1GBpmlmxbIrCsL8ym12 I2EMF0A== X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:51c0:c0d7:f683:5be5]) (user=maskray job=sendgmr) by 2002:a0d:db4b:0:b0:607:81e1:8b83 with SMTP id d72-20020a0ddb4b000000b0060781e18b83mr2159545ywe.8.1708326583453; Sun, 18 Feb 2024 23:09:43 -0800 (PST) Date: Sun, 18 Feb 2024 23:09:40 -0800 Mime-Version: 1.0 Message-ID: <20240219070941.2254076-1-maskray@google.com> Subject: [PATCH] sh: Make protected symbols local for FDPIC -shared From: Fangrui Song To: Joseph Myers , Alexandre Oliva , binutils@sourceware.org Cc: Fangrui Song X-Spam-Status: No, score=-18.9 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791310267940011029 X-GMAIL-MSGID: 1791310267940011029 From: Fangrui Song __attribute__((visibility("protected"))) void protected_fun() {} void *get_protected_fun() { return protected_fun; } links fine in the non-FDPIC mode but not in the FDPIC mode: R_SH_GOTOFFFUNCDESC relocation against external symbol "protected_fun" The issue is similar to the x86 issue fixed by commit d19a265487eda186b6977d9d15648cda9fad3298 ("x86: Make protected symbols local for -shared"). SYMBOL_FUNCDESC_LOCAL in the R_SH_GOTOFFFUNCDESC check unnecessarily considers protected symbols non-local. elf32-frv.c:FRVFDPIC_SYM_LOCAL avoids the issue by setting local_protected. Set local_protected for sh as well. It seems that the condition `! elf_hash_table (INFO)->dynamic_sections_created` is redundant as `h->dynindx` should be -1. Let's remove the condition. --- bfd/elf32-sh.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index bf4cb2a8242..7d35144cdc3 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -64,8 +64,7 @@ static bfd_vma tpoff not. If the symbol is protected, we want the local address, but its function descriptor must be assigned by the dynamic linker. */ #define SYMBOL_FUNCDESC_LOCAL(INFO, H) \ - (SYMBOL_REFERENCES_LOCAL (INFO, H) \ - || ! elf_hash_table (INFO)->dynamic_sections_created) + _bfd_elf_symbol_refs_local_p (H, INFO, 1) #define SH_PARTIAL32 true #define SH_SRC_MASK32 0xffffffff