From patchwork Sat Nov 28 21:58:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1407646 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=o/sU3INB; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (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 4Ck53P0jVMz9sSf for ; Sun, 29 Nov 2020 08:58:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF6693854838; Sat, 28 Nov 2020 21:58:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF6693854838 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1606600700; bh=FN/jkWeQlvUuuF6RVBUUr7IdXKsCkN/RM6xKynrJssw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=o/sU3INBAVcALpjtUBnsiuuuN9nnyQa7RXluYwALUaOQrLzPSTitxwxpjd7NCwhoG kHXX4iYiyMzFPfZDD09PNiDCkf/kTuJEq7wTVvIQYtJgC27w1mWRoBoFgYWPEkCnDw 0rzBbncw4gGnIDYl6el8fYop2MeKQDaaem2UutKs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050::465:201]) by sourceware.org (Postfix) with ESMTPS id A865E3858004 for ; Sat, 28 Nov 2020 21:58:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A865E3858004 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Ck53C0dPjzQjkp; Sat, 28 Nov 2020 22:58:15 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id Abl_xbG_56t1; Sat, 28 Nov 2020 22:58:11 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] d: Add darwin support for D language front-end Date: Sat, 28 Nov 2020 22:58:08 +0100 Message-Id: <20201128215808.176005-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -0.53 / 15.00 / 15.00 X-Rspamd-Queue-Id: BBAD2183E X-Rspamd-UID: b7a015 X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Cc: iain@sandoe.co.uk Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch adds necessary predefined version symbols and support for moduleinfo sections for darwin to allow testing libphobos support. OK for mainline? Regards Iain. --- gcc/ChangeLog: * config.gcc (*-*-darwin*): Set d_target_objs and target_has_targetdm. * config/elfos.h (TARGET_D_MINFO_SECTION): New macro. (TARGET_D_MINFO_START_NAME): New macro. (TARGET_D_MINFO_END_NAME): New macro. * config/t-darwin: Add darwin-d.o. * doc/tm.texi: Regenerate. * doc/tm.texi.in (D language and ABI): Add @hook for TARGET_D_MINFO_SECTION, TARGET_D_MINFO_START_NAME, and TARGET_D_MINFO_END_NAME. * config/darwin-d.c: New file. gcc/d/ChangeLog: * d-target.def (d_minfo_section): New hook. (d_minfo_start_name): New hook. (d_minfo_end_name): New hook. * modules.cc: Include d-target.h. (register_moduleinfo): Update to use new targetdm hooks. --- gcc/config.gcc | 2 ++ gcc/config/darwin-d.c | 49 +++++++++++++++++++++++++++++++++++++++++++ gcc/config/elfos.h | 6 ++++++ gcc/config/t-darwin | 3 +++ gcc/d/d-target.def | 25 ++++++++++++++++++++++ gcc/d/modules.cc | 14 ++++++++++--- gcc/doc/tm.texi | 20 ++++++++++++++++++ gcc/doc/tm.texi.in | 6 ++++++ 8 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 gcc/config/darwin-d.c diff --git a/gcc/config.gcc b/gcc/config.gcc index 0ae58482657..aacab0d9133 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -702,8 +702,10 @@ case ${target} in extra_options="${extra_options} darwin.opt" c_target_objs="${c_target_objs} darwin-c.o" cxx_target_objs="${cxx_target_objs} darwin-c.o" + d_target_objs="${d_target_objs} darwin-d.o" fortran_target_objs="darwin-f.o" target_has_targetcm=yes + target_has_targetdm=yes extra_objs="${extra_objs} darwin.o" extra_gcc_objs="darwin-driver.o" default_use_cxa_atexit=yes diff --git a/gcc/config/darwin-d.c b/gcc/config/darwin-d.c new file mode 100644 index 00000000000..90a9a4a0613 --- /dev/null +++ b/gcc/config/darwin-d.c @@ -0,0 +1,49 @@ +/* Darwin support needed only by D front-end. + Copyright (C) 2020 Free Software Foundation, Inc. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm_d.h" +#include "d/d-target.h" +#include "d/d-target-def.h" + +/* Implement TARGET_D_OS_VERSIONS for Glibc targets. */ + +static void +darwin_d_os_builtins (void) +{ + d_add_builtin_version ("Posix"); + d_add_builtin_version ("OSX"); + d_add_builtin_version ("darwin"); +} + +#undef TARGET_D_OS_VERSIONS +#define TARGET_D_OS_VERSIONS darwin_d_os_builtins + +/* Define TARGET_D_MINFO_SECTION for Darwin targets. */ + +#undef TARGET_D_MINFO_SECTION +#define TARGET_D_MINFO_SECTION "__DATA,__minfodata" + +#undef TARGET_D_MINFO_START_NAME +#define TARGET_D_MINFO_START_NAME "*section$start$__DATA$__minfodata" + +#undef TARGET_D_MINFO_END_NAME +#define TARGET_D_MINFO_END_NAME "*section$end$__DATA$__minfodata" + +struct gcc_targetdm targetdm = TARGETDM_INITIALIZER; diff --git a/gcc/config/elfos.h b/gcc/config/elfos.h index 74a3eafda6b..d8f169f54df 100644 --- a/gcc/config/elfos.h +++ b/gcc/config/elfos.h @@ -474,3 +474,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #undef TARGET_LIBC_HAS_FUNCTION #define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function + +/* ELF support needed only by D front-end. */ + +#define TARGET_D_MINFO_SECTION "minfo" +#define TARGET_D_MINFO_START_NAME "__start_minfo" +#define TARGET_D_MINFO_END_NAME "__stop_minfo" diff --git a/gcc/config/t-darwin b/gcc/config/t-darwin index 7f2ac282bfc..62ec5320f26 100644 --- a/gcc/config/t-darwin +++ b/gcc/config/t-darwin @@ -26,6 +26,9 @@ darwin-c.o: $(srcdir)/config/darwin-c.c $(COMPILE) $(PREPROCESSOR_DEFINES) $< $(POSTCOMPILE) +darwin-d.o: $(srcdir)/config/darwin-d.c + $(COMPILE) $< + $(POSTCOMPILE) darwin-f.o: $(srcdir)/config/darwin-f.c $(COMPILE) $< diff --git a/gcc/d/d-target.def b/gcc/d/d-target.def index 41b31723188..728cba70335 100644 --- a/gcc/d/d-target.def +++ b/gcc/d/d-target.def @@ -46,5 +46,30 @@ relating to the target operating system.", void, (void), hook_void_void) +/* ModuleInfo section name and brackets. */ +DEFHOOKPOD +(d_minfo_section, + "Contains the name of the section in which module info references should be\n\ +placed. This section is expected to be bracketed by two symbols to indicate\n\ +the start and end address of the section, so that the runtime library can\n\ +collect all modules for each loaded shared library and executable. The\n\ +default value of @code{NULL} disables the use of sections altogether.", + const char *, NULL) + +DEFHOOKPOD +(d_minfo_start_name, + "If @code{TARGET_D_MINFO_SECTION} is defined, then this must also be defined\n\ +as the name of the symbol indicating the start address of the module info\n\ +section", + const char *, NULL) + +/* The name of the ModuleInfo section. */ +DEFHOOKPOD +(d_minfo_end_name, + "If @code{TARGET_D_MINFO_SECTION} is defined, then this must also be defined\n\ +as the name of the symbol indicating the end address of the module info\n\ +section", + const char *, NULL) + /* Close the 'struct gcc_targetdm' definition. */ HOOK_VECTOR_END (C90_EMPTY_HACK) diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc index 4b48c19a90e..742a24ff0bb 100644 --- a/gcc/d/modules.cc +++ b/gcc/d/modules.cc @@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see #include "stringpool.h" #include "d-tree.h" +#include "d-target.h" /* D generates module information to inform the runtime library which modules @@ -405,6 +406,10 @@ build_dso_registry_var (const char * name, tree type) static void register_moduleinfo (Module *decl, tree minfo) { + /* No defined minfo section for target. */ + if (targetdm.d_minfo_section == NULL) + return; + if (!targetm_common.have_named_sections) sorry ("%<-fmoduleinfo%> is not supported on this target"); @@ -420,7 +425,8 @@ register_moduleinfo (Module *decl, tree minfo) DECL_EXTERNAL (mref) = 0; DECL_PRESERVE_P (mref) = 1; - set_decl_section_name (mref, "minfo"); + set_decl_section_name (mref, targetdm.d_minfo_section); + symtab_node::get (mref)->implicit_section = true; d_pushdecl (mref); rest_of_decl_compilation (mref, 1, 0); @@ -431,10 +437,12 @@ register_moduleinfo (Module *decl, tree minfo) if (!first_module) return; - start_minfo_node = build_dso_registry_var ("__start_minfo", ptr_type_node); + start_minfo_node = build_dso_registry_var (targetdm.d_minfo_start_name, + ptr_type_node); rest_of_decl_compilation (start_minfo_node, 1, 0); - stop_minfo_node = build_dso_registry_var ("__stop_minfo", ptr_type_node); + stop_minfo_node = build_dso_registry_var (targetdm.d_minfo_end_name, + ptr_type_node); rest_of_decl_compilation (stop_minfo_node, 1, 0); /* Declare dso_slot and dso_initialized. */ diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index d9502c2c607..9f700b1c774 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10822,6 +10822,26 @@ Similarly to @code{TARGET_D_CPU_VERSIONS}, but is used for versions relating to the target operating system. @end deftypefn +@deftypevr {D Target Hook} {const char *} TARGET_D_MINFO_SECTION +Contains the name of the section in which module info references should be +placed. This section is expected to be bracketed by two symbols to indicate +the start and end address of the section, so that the runtime library can +collect all modules for each loaded shared library and executable. The +default value of @code{NULL} disables the use of sections altogether. +@end deftypevr + +@deftypevr {D Target Hook} {const char *} TARGET_D_MINFO_START_NAME +If @code{TARGET_D_MINFO_SECTION} is defined, then this must also be defined +as the name of the symbol indicating the start address of the module info +section +@end deftypevr + +@deftypevr {D Target Hook} {const char *} TARGET_D_MINFO_END_NAME +If @code{TARGET_D_MINFO_SECTION} is defined, then this must also be defined +as the name of the symbol indicating the end address of the module info +section +@end deftypevr + @node Named Address Spaces @section Adding support for named address spaces @cindex named address spaces diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index b08923c8f28..012cb1c53f0 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7353,6 +7353,12 @@ floating-point support; they are not included in this mechanism. @hook TARGET_D_OS_VERSIONS +@hook TARGET_D_MINFO_SECTION + +@hook TARGET_D_MINFO_START_NAME + +@hook TARGET_D_MINFO_END_NAME + @node Named Address Spaces @section Adding support for named address spaces @cindex named address spaces