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: 85947 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06B803861862 for ; Mon, 19 Feb 2024 07:10:12 +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-Google-Smtp-Source: AGHT+IGxxVVJv0rekR0rBGsnvJT2Eo78pVkkmveNum8POJzhVIRWQqNDy5p73peKrrcwFSNJG+8rW88jMOu/ 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+patchwork=sourceware.org@sourceware.org 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