From patchwork Mon Oct 7 20:28:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1172953 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-510420-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qDntw2a5"; 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 46nBrv1mVJz9sPV for ; Tue, 8 Oct 2019 07:28:44 +1100 (AEDT) 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:mime-version:subject :message-id:date:to; q=dns; s=default; b=lIJZ9Q4HOMWcPG1H47QWa2P O9K33BgBOJToTKsrjDPa2HAaNtIDltJumGED2aEo9Uiu+DT3sMrdM3F/uM90gJf2 Tps4obd7JhGTod5+Omd0vRHpT9cgJcPvSIkw6pGbDwCmGoKojvsJ+X3Avy1L6Lr1 flxlCxtHiHgiq1c+IzIc= 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:mime-version:subject :message-id:date:to; s=default; bh=r9ePUGJASKhQebkJsoCq+GdeGsA=; b= qDntw2a5urbtt581jkwnlu59H/pfrvWHEGsLYK5ghoe8EjnNevMRLUnlgwfIuF3A b09ykqgnsiJCGjc/ieJ5t05WpvNvHAcNWqVSrYlVeLBCAzMk9aDIbdXoowYVFHLi eOoY3CsW99gg9Dfv1qPvhbvEACfkVPE6h7TyGySG9kI= Received: (qmail 47607 invoked by alias); 7 Oct 2019 20:28:36 -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 47599 invoked by uid 89); 7 Oct 2019 20:28:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_COUK, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=pmode, Pmode, rebound X-HELO: smtp2.wavenetuk.net Received: from smtp.wavenetuk.net (HELO smtp2.wavenetuk.net) (195.26.37.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Oct 2019 20:28:33 +0000 Received: from [192.168.1.212] (host81-138-1-83.in-addr.btopenworld.com [81.138.1.83]) by smtp2.wavenetuk.net (Postfix) with ESMTPA id 82200600156 for ; Mon, 7 Oct 2019 21:28:25 +0100 (BST) From: Iain Sandoe Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [Darwin, machopic 0/n, committed] Initial tidy of Mach-O symbol handling. Message-Id: <4D744A3A-DA4A-42AF-B43E-0987DE02D139@sandoe.co.uk> Date: Mon, 7 Oct 2019 21:28:20 +0100 To: GCC Patches We want to improve the detection and caching of symbol-properties so that (a) we can make the compiler's output match the platform norms (b) we can improve efficiency by checking flags instead of inspecting strings. (c) The fix for PR71767 was a largish hammer and we want to reduce the number of symbols that are made linker- visible. This first patch is largely typographical changes with no functional difference intended: - Tries to ensure that there's no overlap between the symbols used in the Mach-O case and those declared in the i386 or rs6000 port trees. - Some improvement to comments. - Makes the naming of the symbol flags consistent with other uses. - Provides a predicate macro for each use. tested on x86_64-darwin16, applied to mainline, thanks Iain gcc/ChangeLog: 2019-10-07 Iain Sandoe * config/darwin.c (machopic_symbol_defined_p): Use symbol flag predicates instead of accessing bits directly. (machopic_indirect_call_target): Likewise. (machopic_output_indirection): Likewise. (darwin_encode_section_info): Improve description. Use renamed symbol flags. Use predicate macros for variables and functions. * config/darwin.h: Rename MACHO_SYMBOL_VARIABLE to MACHO_SYMBOL_FLAG_VARIABLE. Rename MACHO_SYMBOL_DEFINED to MACHO_SYMBOL_FLAG_DEFINED. Rename MACHO_SYMBOL_STATIC to MACHO_SYMBOL_FLAG_STATIC. (MACHO_SYMBOL_VARIABLE_P): New. (MACHO_SYMBOL_DEFINED_P):New. (MACHO_SYMBOL_STATIC_P): New. * config/i386/darwin.h (MACHO_SYMBOL_FLAG_VARIABLE): Delete. (SYMBOL_FLAG_SUBT_DEP): New. * config/rs6000/darwin.h (SYMBOL_FLAG_SUBT_DEP): New. diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 5673982394..45e0d744ad 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -76,7 +76,7 @@ along with GCC; see the file COPYING3. If not see setting the second word in the .non_lazy_symbol_pointer data structure to symbol. See indirect_data for the code that handles the extra indirection, and machopic_output_indirection and its use - of MACHO_SYMBOL_STATIC for the code that handles @code{static} + of MACHO_SYMBOL_FLAG_STATIC for the code that handles @code{static} symbol indirection. */ typedef struct GTY(()) cdtor_record { @@ -249,7 +249,7 @@ name_needs_quotes (const char *name) int machopic_symbol_defined_p (rtx sym_ref) { - if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_DEFINED) + if (MACHO_SYMBOL_DEFINED_P (sym_ref)) return true; /* If a symbol references local and is not an extern to this @@ -258,7 +258,7 @@ machopic_symbol_defined_p (rtx sym_ref) { /* If the symbol references a variable and the variable is a common symbol, then this symbol is not defined. */ - if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_VARIABLE) + if (MACHO_SYMBOL_VARIABLE_P (sym_ref)) { tree decl = SYMBOL_REF_DECL (sym_ref); if (!decl) @@ -797,8 +797,7 @@ machopic_indirect_call_target (rtx target) if (MACHOPIC_INDIRECT && GET_CODE (XEXP (target, 0)) == SYMBOL_REF - && !(SYMBOL_REF_FLAGS (XEXP (target, 0)) - & MACHO_SYMBOL_FLAG_DEFINED)) + && ! MACHO_SYMBOL_DEFINED_P (XEXP (target, 0))) { rtx sym_ref = XEXP (target, 0); const char *stub_name = machopic_indirection_name (sym_ref, @@ -1167,14 +1166,14 @@ machopic_output_indirection (machopic_indirection **slot, FILE *asm_out_file) assemble_name (asm_out_file, sym_name); fprintf (asm_out_file, "\n"); - /* Variables that are marked with MACHO_SYMBOL_STATIC need to + /* Variables that are marked with MACHO_SYMBOL_FLAG_STATIC need to have their symbol name instead of 0 in the second entry of the non-lazy symbol pointer data structure when they are defined. This allows the runtime to rebind newer instances of the translation unit with the original instance of the symbol. */ - if ((SYMBOL_REF_FLAGS (symbol) & MACHO_SYMBOL_STATIC) + if (MACHO_SYMBOL_STATIC_P (symbol) && machopic_symbol_defined_p (symbol)) init = gen_rtx_SYMBOL_REF (Pmode, sym_name); @@ -1205,23 +1204,37 @@ machopic_operand_p (rtx op) && XINT (XEXP (op, 0), 1) == UNSPEC_MACHOPIC_OFFSET); } -/* This function records whether a given name corresponds to a defined - or undefined function or variable, for machopic_classify_ident to - use later. */ +/* This function: + computes and caches a series of flags that characterise the symbol's + properties that affect Mach-O code gen (including accidental cases + from older toolchains). + + TODO: + Here we also need to do enough analysis to determine if a symbol's + name needs to be made linker-visible. This is more tricky - since + it depends on whether we've previously seen a global weak definition + in the same section. + */ void -darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED) +darwin_encode_section_info (tree decl, rtx rtl, int first) { - rtx sym_ref; + /* Careful not to prod global register variables. */ + if (!MEM_P (rtl)) + return; - /* Do the standard encoding things first. */ + /* Do the standard encoding things first; this sets: + SYMBOL_FLAG_FUNCTION, + SYMBOL_FLAG_LOCAL, (binds_local_p) + TLS_MODEL, SYMBOL_FLAG_SMALL + SYMBOL_FLAG_EXTERNAL. */ default_encode_section_info (decl, rtl, first); - if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL) + if (! VAR_OR_FUNCTION_DECL_P (decl)) return; - sym_ref = XEXP (rtl, 0); - if (TREE_CODE (decl) == VAR_DECL) + rtx sym_ref = XEXP (rtl, 0); + if (VAR_P (decl)) SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_VARIABLE; if (!DECL_EXTERNAL (decl) @@ -1234,7 +1247,7 @@ darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED) SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_DEFINED; if (! TREE_PUBLIC (decl)) - SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_STATIC; + SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_STATIC; } void diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 93dc638f8b..39c54cc720 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -812,21 +812,30 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS]; #undef TARGET_ASM_MARK_DECL_PRESERVED #define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved -/* Set on a symbol with SYMBOL_FLAG_FUNCTION or - MACHO_SYMBOL_FLAG_VARIABLE to indicate that the function or - variable has been defined in this translation unit. - When porting Mach-O to new architectures you need to make - sure these aren't clobbered by the backend. */ +/* Any port using this header needs to define the first available + subtarget symbol bit: SYMBOL_FLAG_SUBT_DEP. */ -#define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_MACH_DEP) -#define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_MACH_DEP) << 1) +/* Is a variable. */ +#define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_SUBT_DEP) +#define MACHO_SYMBOL_VARIABLE_P(RTX) \ + ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_VARIABLE) != 0) + +/* Set on a symbol with SYMBOL_FLAG_FUNCTION or MACHO_SYMBOL_FLAG_VARIABLE + to indicate that the function or variable is considered defined in this + translation unit. */ + +#define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_SUBT_DEP) << 2) +#define MACHO_SYMBOL_DEFINED_P(RTX) \ + ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_DEFINED) != 0) /* Set on a symbol to indicate when fix-and-continue style code generation is being used and the symbol refers to a static symbol that should be rebound from new instances of a translation unit to the original instance of the data. */ -#define MACHO_SYMBOL_STATIC ((SYMBOL_FLAG_MACH_DEP) << 2) +#define MACHO_SYMBOL_FLAG_STATIC ((SYMBOL_FLAG_SUBT_DEP) << 5) +#define MACHO_SYMBOL_STATIC_P(RTX) \ + ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_STATIC) != 0) /* Symbolic names for various things we might know about a symbol. */ diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h index 385d253692..bdb36f0095 100644 --- a/gcc/config/i386/darwin.h +++ b/gcc/config/i386/darwin.h @@ -324,10 +324,8 @@ along with GCC; see the file COPYING3. If not see } \ } -/* This needs to move since i386 uses the first flag and other flags are - used in Mach-O. */ -#undef MACHO_SYMBOL_FLAG_VARIABLE -#define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3) +/* First available SYMBOL flag bit for use by subtargets. */ +#define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP << 5) #undef MACHOPIC_NL_SYMBOL_PTR_SECTION #define MACHOPIC_NL_SYMBOL_PTR_SECTION \ diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h index a626325c2d..1081967bd6 100644 --- a/gcc/config/rs6000/darwin.h +++ b/gcc/config/rs6000/darwin.h @@ -506,6 +506,9 @@ do { \ this will need to be modified similar to the x86 case. */ #define TARGET_FOLD_BUILTIN SUBTARGET_FOLD_BUILTIN +/* First available SYMBOL flag bit for use by subtargets. */ +#define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP) + /* Use standard DWARF numbering for DWARF debugging information. */ #define RS6000_USE_DWARF_NUMBERING