From patchwork Sun Nov 6 19:37:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 691680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3tBm8F4z80z9t1h for ; Mon, 7 Nov 2016 06:38:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wEeXBsfK"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :content-type:content-transfer-encoding:subject:date:message-id :cc:to:mime-version; q=dns; s=default; b=Xb2SeS4SQdXoe7Trg0iUgdX j8Zt412W2nkbhAtR0+nw27Z+ufZc6ggkauOzvTFtfZ84y/6S64zWXpz3YBArv5tI RHL3XNv0jpva6WXkhXpGQFa2LqfhFaofLSaGLSEp1fn4l3AW98yJNXiprYjLmeyS ISTDhhbp0VB2dvaDqPUc= 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 :content-type:content-transfer-encoding:subject:date:message-id :cc:to:mime-version; s=default; bh=0/ARh7YrcuMxog+Jo6QIEymQoG8=; b= wEeXBsfKIkfdDtQJtO3Fg3vqiYbrf5NFg/bessHyskPR2JEffpnv8LA6W02m9ocR usnvoECIbwK4dCRqDQ6Xz1UxsHk6AsEQN2ZBQE7HoazgnF4vK7V/4x1FzvZcbFTD zNdTFkuOTm08mAoqgXdZFG8UVCJiRS1k1Z6HKk0k37E= Received: (qmail 21161 invoked by alias); 6 Nov 2016 19:38:12 -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 21148 invoked by uid 89); 6 Nov 2016 19:38:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=invisible, Hx-languages-length:5096 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; Sun, 06 Nov 2016 19:38:00 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1c3TGR-0000jT-6v from Iain_Sandoe@mentor.com ; Sun, 06 Nov 2016 11:37:59 -0800 Received: from [127.0.0.1] (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Sun, 6 Nov 2016 19:37:55 +0000 From: Iain Sandoe Subject: [PATCH fix PR71767 1/4 : ld64 atoms] Make PIC indirections and constant labels linker-visible. Date: Sun, 6 Nov 2016 11:37:54 -0800 Message-ID: CC: Mike Stump To: GCC Patches MIME-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) Hi Folks, (in Darwin) If we have a situation like: global_weak_symbol: .... Lnon_weak_local: .... ld64 will be unable to split this into two atoms (because the "L" makes the second symbol 'invisible'). This means that legitimate direct accesses to the second symbol will appear to be non-allowed direct accesses to an atom of type weak, global which are not allowed. To avoid this, we make the indirections have a leading 'l' (lower-case L) which has a special meaning: linker can see this and use it to determine atoms, but it is not placed into the final symbol table. The implementation here is somewhat heavy-handed in that it will also mark indirections to the __IMPORT,__pointers section the same way which is really unnecessary, since ld64 _can_ split those into atoms as they are fixed size. FIXME: determine if this is a penalty worth extra code to figure out. Similarly, with: .const weak_global_constant: .... LCxx: ... ld64 can't split the second, causing a warning when it's directly accessed. We solve this by making the two cases emit a linker-visible symbol (where the L becomes ā€˜lā€™). TODO: there are also some cases in Objective-C meta-data that need similar treatment, but those need to be caught in the objc runtime lowering. OK for trunk? OK for open branches? Iain gcc/ 2016-11-06 Iain Sandoe PR target/71767 * config/darwin.c (imachopic_indirection_name): Make data section indirections linker-visible. * config/darwin.h (ASM_GENERATE_INTERNAL_LABEL): Make local constant labels linker-visible. --- gcc/config/darwin.c | 37 +++++++++++++++++++++++++++++++++---- gcc/config/darwin.h | 9 ++++++++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index ff8600c..210c2da 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -474,7 +474,31 @@ indirection_hasher::equal (machopic_indirection *s, const char *k) } /* Return the name of the non-lazy pointer (if STUB_P is false) or - stub (if STUB_B is true) corresponding to the given name. */ + stub (if STUB_B is true) corresponding to the given name. + + If we have a situation like: + +global_weak_symbol: + .... +Lnon_weak_local: + .... + + ld64 will be unable to split this into two atoms (because the "L" makes + the second symbol 'invisible'). This means that legitimate direct accesses + to the second symbol will appear to be non-allowed direct accesses to an + atom of type weak, global which are not allowed. + + To avoid this, we make the indirections have a leading 'l' (lower-case L) + which has a special meaning: linker can see this and use it to determine + atoms, but it is not placed into the final symbol table. + + The implementation here is somewhat heavy-handed in that it will also mark + indirections to the __IMPORT,__pointers section the same way which is + really unnecessary, since ld64 _can_ split those into atoms as they are + fixed size. FIXME: determine if this is a penalty worth extra code to + fix. + +*/ const char * machopic_indirection_name (rtx sym_ref, bool stub_p) @@ -485,6 +509,7 @@ machopic_indirection_name (rtx sym_ref, bool stub_p) machopic_indirection *p; bool needs_quotes; const char *suffix; + char L_or_l = 'L'; const char *prefix = user_label_prefix; const char *quote = ""; tree id; @@ -519,9 +544,13 @@ machopic_indirection_name (rtx sym_ref, bool stub_p) if (stub_p) suffix = STUB_SUFFIX; else - suffix = NON_LAZY_POINTER_SUFFIX; + { + suffix = NON_LAZY_POINTER_SUFFIX; + /* Let the linker see this. */ + L_or_l = 'l'; + } - buffer = XALLOCAVEC (char, strlen ("&L") + buffer = XALLOCAVEC (char, 2 /* strlen ("&L") or ("&l") */ + strlen (prefix) + namelen + strlen (suffix) @@ -529,7 +558,7 @@ machopic_indirection_name (rtx sym_ref, bool stub_p) + 1 /* '\0' */); /* Construct the name of the non-lazy pointer or stub. */ - sprintf (buffer, "&%sL%s%s%s%s", quote, prefix, name, suffix, quote); + sprintf (buffer, "&%s%c%s%s%s%s", quote, L_or_l, prefix, name, suffix, quote); if (!machopic_indirections) machopic_indirections = hash_table::create_ggc (37); diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 98d2382..045f70b 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -716,9 +716,16 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS]; { "weak_import", 0, 0, true, false, false, \ darwin_handle_weak_import_attribute, false } +/* Make local constant labels linker-visible, so that if one follows a + weak_global constant, ld64 will be able to separate the atoms. */ #undef ASM_GENERATE_INTERNAL_LABEL #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \ - sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM)) + do { \ + if (strcmp ("LC", PREFIX) == 0) \ + sprintf (LABEL, "*%s%ld", "lC", (long)(NUM)); \ + else \ + sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM)); \ + } while (0) #undef TARGET_ASM_MARK_DECL_PRESERVED #define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved