From patchwork Wed Sep 5 11:48:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 966329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-485165-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="hFDvJK4l"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42528D66bwz9sCf for ; Wed, 5 Sep 2018 21:50:36 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references:mime-version :content-type; q=dns; s=default; b=yTJnyp2pSZDJh+oDIiPpZiEw2ZX88 yuV7cjG0W6G6W3Gc7jT/St6LSIBUfowyDOYeZUjW5p47rQdBeqaHrjbmufnjg/LS zM7wkf0Ga4aEnEMHWsHZMKDDpjp5QwPW8Xi/zlmLBOnBoMm2bEV1Dkj0CllJL0Rq rOHeSEOrEoHxiw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references:mime-version :content-type; s=default; bh=0hwo2AORhuVg412b+WgLNJQ77kU=; b=hFD vJK4lY23E054dTj6PJNeBvrE+zkzmwv4DycCjoTk2gw0D5Ti0PZwIoSjrMSSVUQz KDVoWaOgMpb6QwFezyOfLgKfHlzTikvc1jfjGK+1q+CjyZZT3Cv2nGzt+soVk/aN COURaYvk3EBDi7uniEmJeckbK8g4O8gCBKZDizi8= Received: (qmail 80897 invoked by alias); 5 Sep 2018 11:49:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 80429 invoked by uid 89); 5 Sep 2018 11:49:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:handle_, drivers X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Sep 2018 11:49:23 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-01.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1fxWJ6-0005Tk-Hv from Andrew_Stubbs@mentor.com for gcc-patches@gcc.gnu.org; Wed, 05 Sep 2018 04:49:12 -0700 Received: from build6-trusty-cs.sje.mentorg.com (137.202.0.90) by svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Wed, 5 Sep 2018 12:49:08 +0100 From: To: Subject: [PATCH 03/25] Improve TARGET_MANGLE_DECL_ASSEMBLER_NAME. Date: Wed, 5 Sep 2018 12:48:51 +0100 Message-ID: <328b94cd7d15c4d2113a676a3a70ce640b37333a.1536144068.git.ams@codesourcery.com> In-Reply-To: References: MIME-Version: 1.0 The HSA GPU drivers can't cope with binaries that have the same symbol defined multiple times, even though the names are not exported. This happens whenever there are file-scope static variables with matching names. I believe it's also an issue with switch tables. This is a bug, but outside our control, so we must work around it when multiple translation units have the same symbol defined. Therefore, we've implemented name mangling via TARGET_MANGLE_DECL_ASSEMBLER_NAME, but found some places where the middle-end assumes that the decl name matches the name in the source. This patch fixes up those cases by falling back to comparing the unmangled name, when a lookup fails. 2018-09-05 Julian Brown gcc/ * cgraphunit.c (handle_alias_pairs): Scan for aliases by DECL_NAME if decl assembler name doesn't match. gcc/c-family/ * c-pragma.c (maye_apply_pending_pragma_weaks): Scan for aliases with DECL_NAME if decl assembler name doesn't match. --- gcc/c-family/c-pragma.c | 14 ++++++++++++++ gcc/cgraphunit.c | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c index 84e4341..1c0be0c 100644 --- a/gcc/c-family/c-pragma.c +++ b/gcc/c-family/c-pragma.c @@ -323,6 +323,20 @@ maybe_apply_pending_pragma_weaks (void) continue; target = symtab_node::get_for_asmname (id); + + /* Try again if ID didn't match an assembler name by looking through + decl names. */ + if (!target) + { + symtab_node *node; + FOR_EACH_SYMBOL (node) + if (strcmp (IDENTIFIER_POINTER (id), node->name ()) == 0) + { + target = node; + break; + } + } + decl = build_decl (UNKNOWN_LOCATION, target ? TREE_CODE (target->decl) : FUNCTION_DECL, alias_id, default_function_type); diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index ec490d7..fc3f34e 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -1393,6 +1393,21 @@ handle_alias_pairs (void) { symtab_node *target_node = symtab_node::get_for_asmname (p->target); + /* If the alias target didn't match a symbol's assembler name (e.g. + because it has been mangled by TARGET_MANGLE_DECL_ASSEMBLER_NAME), + try again with the unmangled decl name. */ + if (!target_node) + { + symtab_node *node; + FOR_EACH_SYMBOL (node) + if (strcmp (IDENTIFIER_POINTER (p->target), + node->name ()) == 0) + { + target_node = node; + break; + } + } + /* Weakrefs with target not defined in current unit are easy to handle: they behave just as external variables except we need to note the alias flag to later output the weakref pseudo op into asm file. */