From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1298) id D36A93858439; Sun, 2 Oct 2022 09:25:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D36A93858439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664702753; bh=Rm8Z8fbuZcZ+WhDb+cex4b845DDiKQoSRQck2eHGf80=; h=From:To:Subject:Date:From; b=qZ1aPzx4kNgkuy3BmgDd9zpr0nPFbIanTJSw7U759XsTeXXW4MBDZgqBvuvIvDSfN u59jCe4E3edFQSqWztEdjH7ij2KlLvEDVXub2VmzY1YmDZcRXLb2rnu2EXZXqIeOck qKFJ4mW0/t93XJWgkvUezPsThwOyWYu1wL5bCNOQ= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Olivier Hainque To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3018] Define GCC_DRIVER_HOST_INITIALIZATION for VxWorks targets X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 372044a67ec8346f4f308c5fe79d9e1cb6e7e6c6 X-Git-Newrev: 2f26f5b584856927337728ddc598c44f1426fa32 Message-Id: <20221002092553.D36A93858439@sourceware.org> Date: Sun, 2 Oct 2022 09:25:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2f26f5b584856927337728ddc598c44f1426fa32 commit r13-3018-g2f26f5b584856927337728ddc598c44f1426fa32 Author: Marc Poulhiès Date: Tue Jan 4 14:56:27 2022 +0000 Define GCC_DRIVER_HOST_INITIALIZATION for VxWorks targets We need to perform static links by default on VxWorks, where the use of shared libraries involves unusual steps compared to standard native systems. This has to be conveyed before the lang_specific_driver code gets invoked (in particular for g++), so specs aren't available. This change defines the GCC_DRIVER_HOST_INITIALIZATION macro for VxWorks, to insert a -static option in case the user hasn't provided any explicit indication on the command line of the kind of link desired. While a HOST macro doesn't seem appropriate to control a target OS driven behavior, this matches other uses and won't conflict as VxWorks is not supported on any of the other configurations using this macro. gcc/ * config/vxworks-driver.cc: New. * config.gcc (*vxworks*): Add vxworks-driver.o in extra_gcc_objs. * config/t-vxworks: Add vxworks-driver.o. * config/vxworks.h (GCC_DRIVER_HOST_INITIALIZATION): New. Diff: --- gcc/config.gcc | 2 + gcc/config/t-vxworks | 4 ++ gcc/config/vxworks-driver.cc | 93 ++++++++++++++++++++++++++++++++++++++++++++ gcc/config/vxworks.h | 10 +++++ 4 files changed, 109 insertions(+) diff --git a/gcc/config.gcc b/gcc/config.gcc index 555f257c2e7..35dfc00fe4d 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -1021,6 +1021,8 @@ case ${target} in extra_headers="${extra_headers} ../vxworks/vxworks-predef.h" target_has_targetcm="yes" + extra_gcc_objs="vxworks-driver.o" + # This private header exposes a consistent interface for checks on # the VxWorks version our runtime header files need to perform, based on # what the system headers adverstise: diff --git a/gcc/config/t-vxworks b/gcc/config/t-vxworks index 40c6cc4185b..dc97a4e0f30 100644 --- a/gcc/config/t-vxworks +++ b/gcc/config/t-vxworks @@ -16,6 +16,10 @@ # along with GCC; see the file COPYING3. If not see # . +vxworks-driver.o: $(srcdir)/config/vxworks-driver.cc + $(COMPILE) $< + $(POSTCOMPILE) + vxworks.o: $(srcdir)/config/vxworks.cc $(COMPILE) $< $(POSTCOMPILE) diff --git a/gcc/config/vxworks-driver.cc b/gcc/config/vxworks-driver.cc new file mode 100644 index 00000000000..da5f015f1de --- /dev/null +++ b/gcc/config/vxworks-driver.cc @@ -0,0 +1,93 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + +This file is part of GCC. + +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.h" +#include "opts.h" + +/* Perform early driver flags initializations that can't be achieved + with specs. In particular, we need to explicitly request a static + link for rtps by default before lang_specific_driver gets control. */ + +void vxworks_driver_init (unsigned int *in_decoded_options_count, + struct cl_decoded_option **in_decoded_options) +{ + unsigned int i; + struct cl_decoded_option *decoded_options = *in_decoded_options; + + /* Arrange to add -static if we are going to link a rtp and there is no + trace of any explicit request for a specific kind of link. */ + bool wont_link = false; + bool mrtp = false; + bool link_kind_indication = false; + + /* The new argument list will be contained in this. */ + struct cl_decoded_option *new_decoded_options; + unsigned int num_options = *in_decoded_options_count; + + for (i = 1; i < num_options; i++) + { + if (decoded_options[i].errors & CL_ERR_MISSING_ARG) + continue; + + switch (decoded_options[i].opt_index) + { + case OPT_static: + case OPT_shared: + case OPT_Bdynamic: + case OPT_Bstatic: + case OPT_non_static: + link_kind_indication = true; + break; + + case OPT_c: + case OPT_r: + case OPT_S: + case OPT_E: + case OPT_M: + case OPT_MM: + case OPT_fsyntax_only: + wont_link = true; + break; + + case OPT_mrtp: + mrtp = true; + break; + + default: + break; + } + } + + if (!wont_link && mrtp && !link_kind_indication) + { + num_options++; + new_decoded_options = XNEWVEC(struct cl_decoded_option, num_options); + + for (i = 0; i < num_options - 1; i++) + new_decoded_options[i] = decoded_options[i]; + + generate_option(OPT_static, NULL, 1, CL_DRIVER, + &new_decoded_options[num_options - 1]); + + *in_decoded_options = new_decoded_options; + *in_decoded_options_count = num_options; + } +} diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h index f2103def448..84a9c93c6d3 100644 --- a/gcc/config/vxworks.h +++ b/gcc/config/vxworks.h @@ -28,6 +28,16 @@ along with GCC; see the file COPYING3. If not see #undef TARGET_VXWORKS #define TARGET_VXWORKS 1 +/* ??? Even though assigned to a HOST driver hook, this function + operates for all vxworks targets regardless of the current host. + We will get warnings at build time if the macro happens to be + redefined one way or another for a host. */ +struct cl_decoded_option; +extern void vxworks_driver_init (unsigned int *, struct cl_decoded_option **); + +#define GCC_DRIVER_HOST_INITIALIZATION \ + vxworks_driver_init (&decoded_options_count, &decoded_options) + /* In kernel mode, VxWorks provides all the libraries itself, as well as the functionality of startup files, etc. In RTP mode, it behaves more like a traditional Unix, with more external files. Most of our specs