From patchwork Fri Aug 27 16:04:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1521707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gx4L72scQz9sSs for ; Sat, 28 Aug 2021 02:05:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F550385740D for ; Fri, 27 Aug 2021 16:05:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp001-out.apm-internet.net (smtp001-out.apm-internet.net [85.119.248.222]) by sourceware.org (Postfix) with ESMTPS id D94203858C60 for ; Fri, 27 Aug 2021 16:04:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D94203858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=sandoe.co.uk Received: (qmail 69020 invoked from network); 27 Aug 2021 16:04:35 -0000 X-APM-Out-ID: 16300802756901 X-APM-Authkey: 257869/1(257869/1) 12 Received: from unknown (HELO ?192.168.1.214?) (81.138.1.83) by smtp001.apm-internet.net with SMTP; 27 Aug 2021 16:04:35 -0000 From: Iain Sandoe Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.21\)) Subject: [pushed] Darwin : Mark the mod init/term section starts with a linker-visible sym. Message-Id: Date: Fri, 27 Aug 2021 17:04:34 +0100 To: GCC Patches X-Mailer: Apple Mail (2.3445.104.21) X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_COUK, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, Some newer assemblers emit section start temp symbols for mod init and term sections if there is no suitable symbol present already. The temp symbols are linker visible and therefore appear in the symbol tables. Since the temp symbol number can vary when debug is enabled, that causes compare-debug fails. The solution is to provide a stable linker-visible symbol. tested on powerpc, i686, x86_64-darwin, x8-64-linux pushed to master, thanks Iain Signed-off-by: Iain Sandoe gcc/ChangeLog: * config/darwin.c (finalize_ctors): Add a section-start linker- visible symbol. (finalize_dtors): Likewise. * config/darwin.h (MIN_LD64_INIT_TERM_START_LABELS): New. --- gcc/config/darwin.c | 37 ++++++++++++++++++++++++++++++++----- gcc/config/darwin.h | 3 +++ 2 files changed, 35 insertions(+), 5 deletions(-) -- diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 5d1d13c80aa..667fda79a60 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -109,6 +109,9 @@ static bool ld_uses_coal_sects = false; each FDE. */ static bool ld_needs_eh_markers = false; +/* Emit a section-start symbol for mod init and term sections. */ +static bool ld_init_term_start_labels = false; + /* Section names. */ section * darwin_sections[NUM_DARWIN_SECTIONS]; @@ -1838,6 +1841,11 @@ finalize_ctors () else switch_to_section (darwin_sections[constructor_section]); + /* Where needed, provide a linker-visible section-start symbol so that we + have stable output between debug and non-debug. */ + if (ld_init_term_start_labels) + fputs (MACHOPIC_INDIRECT ? "_Mod.init:\n" : "_CTOR.sect:\n", asm_out_file); + if (vec_safe_length (ctors) > 1) ctors->qsort (sort_cdtor_records); FOR_EACH_VEC_SAFE_ELT (ctors, i, elt) @@ -1858,6 +1866,11 @@ finalize_dtors () else switch_to_section (darwin_sections[destructor_section]); + /* Where needed, provide a linker-visible section-start symbol so that we + have stable output between debug and non-debug. */ + if (ld_init_term_start_labels) + fputs (MACHOPIC_INDIRECT ? "_Mod.term:\n" : "_DTOR.sect:\n", asm_out_file); + if (vec_safe_length (dtors) > 1) dtors->qsort (sort_cdtor_records); FOR_EACH_VEC_SAFE_ELT (dtors, i, elt) @@ -3228,11 +3241,25 @@ darwin_override_options (void) /* Earlier versions are not specifically accounted, until required. */ } - /* Older Darwin ld could not coalesce weak entities without them being - placed in special sections. */ - if (darwin_target_linker - && (strverscmp (darwin_target_linker, MIN_LD64_NO_COAL_SECTS) < 0)) - ld_uses_coal_sects = true; + /* Some codegen needs to account for the capabilities of the target + linker. */ + if (darwin_target_linker) + { + /* Older Darwin ld could not coalesce weak entities without them being + placed in special sections. */ + if (strverscmp (darwin_target_linker, MIN_LD64_NO_COAL_SECTS) < 0) + ld_uses_coal_sects = true; + + /* Some newer assemblers emit section start temp symbols for mod init + and term sections if there is no suitable symbol present already. + The temp symbols are linker visible and therefore appear in the + symbol tables. Since the temp symbol number can vary when debug is + enabled, that causes compare-debug fails. The solution is to provide + a stable linker-visible symbol. */ + if (strverscmp (darwin_target_linker, + MIN_LD64_INIT_TERM_START_LABELS) >= 0) + ld_init_term_start_labels = true; + } /* In principle, this should be c-family only. However, we really need to set sensible defaults for LTO as well, since the section selection stuff diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index b1be561e854..f1d92f87e9a 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -1104,6 +1104,9 @@ extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **); needed, and there is no need for the compiler to emit them. */ #define MIN_LD64_OMIT_STUBS "62.1" +/* Emit start labels for init and term sections from this version. */ +#define MIN_LD64_INIT_TERM_START_LABELS "136.0" + /* If we have no definition for the linker version, pick the minimum version that will bootstrap the compiler. */ #ifndef LD64_VERSION