From patchwork Fri Jan 6 21:42:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaius Mulley X-Patchwork-Id: 62823 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7D8863858D39 for ; Fri, 6 Jan 2023 21:42:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D8863858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673041366; bh=+nS0POFq8TLjRmp+bOKHVAOVRiI1OVApf2Zr7gzZJPk=; h=To:Subject:CC:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=lEgf4lwV3roIIF1VlOwGD7uH9p0QpkM4cf68UgNwToKpQskqZpjJw2xtyo0ATbAIW Pvx6vbroMArtXrTL5/lCKyDexwWVoOXgNQuRobkoNq2whr/jwVCAhJ4VuZI/dHM5Mn cjJkdqY6dOtBSyqfVb0PY6olsPpeBBdJ0Zqhnexg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 0D02B3858D28 for ; Fri, 6 Jan 2023 21:42:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D02B3858D28 Received: by mail-wm1-x332.google.com with SMTP id ay40so1993067wmb.2 for ; Fri, 06 Jan 2023 13:42:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:date:cc:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+nS0POFq8TLjRmp+bOKHVAOVRiI1OVApf2Zr7gzZJPk=; b=vs28n19D9ndtFWmDEdsZHX7e0V0SJIQexabs9+EoLJ8JY0rNgQBmLkjTbqEALKcMtH S4zBwSyK+pPUASyTNmLK6ofnvP/ifN4FaNTc22XG3078Aa5GQlm9kz9r2X8LzytOa4l2 pJYJSBOdXIfhKoXirEiPBNKcz9kjiD+s4RHZzSiJ83jYqWWcp7EwYkLfgi600S2Mxd4M 8Njds3L2puu8mCDZLvazDCXY7aCrNR9zBVNfYY2+UfZMlETvsHBweBGNV8ja5CiUHD0i Rpk8mThWK495tjgDUG/nbhzdTSabTDPAhoR7ZG9BLv0fS1uWNEAvO4DihIgFKPbB3Qhw evrQ== X-Gm-Message-State: AFqh2kpfV4+UCaZK/aYqp8EcX5thUq1suHF00lWJDDSGygywIipCW8QE uHZu6M+8mZJuT1WdOSgR0NI0NAyMMs8= X-Google-Smtp-Source: AMrXdXsYCqOwk36RctFqEzT3bEsRNX7/1Zj+5l78eaah/vszag7YMK678VrQtGKkTnbVhdERUAP/ow== X-Received: by 2002:a05:600c:4d25:b0:3d3:5b7a:1791 with SMTP id u37-20020a05600c4d2500b003d35b7a1791mr49963523wmp.41.1673041336755; Fri, 06 Jan 2023 13:42:16 -0800 (PST) Received: from lancelot ([195.147.220.46]) by smtp.gmail.com with ESMTPSA id f15-20020a7bcd0f000000b003d9a71ee54dsm2908187wmj.36.2023.01.06.13.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 13:42:16 -0800 (PST) Received: from gaius by lancelot with local (Exim 4.94.2) (envelope-from ) id 1pDuTf-003wBP-5h; Fri, 06 Jan 2023 21:42:15 +0000 To: GCC Patches Subject: [PATCH, modula2] PR-108182 gm2 driver mishandles target and multilib options CC: Iain Sandoe Date: Fri, 06 Jan 2023 21:42:15 +0000 Message-ID: <87wn5zs5l4.fsf@debian> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Gaius Mulley via Gcc-patches From: Gaius Mulley Reply-To: Gaius Mulley Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, here are some patches which attempt to allow target specific include paths and library paths in the gm2 driver. I admit that the patch has flaws in that it only processes options -f, -m in the lang_specific_driver. [Called after driver::set_up_specs but before read_specs is called]. I suspect a better implementation might include a language callback (lang_post_spec) which could fixup target related paths. Nevertheless as a stage3 bugfix (workaround) they are presented below: I wonder if they would be suitable for master? Tested on Darwin (prior cleanup) and X86_64 Linux regards, Gaius ----- o< ----- o< ----- o< ----- o< ----- o< ----- o< ----- o< ----- o< -------- diff --git a/gcc/gcc.cc b/gcc/gcc.cc index d629ca5e424..362a6a96b63 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -3849,7 +3849,7 @@ alloc_switch (void) /* Save an option OPT with N_ARGS arguments in array ARGS, marking it as validated if VALIDATED and KNOWN if it is an internal switch. */ -static void +void save_switch (const char *opt, size_t n_args, const char *const *args, bool validated, bool known) { @@ -9559,6 +9559,24 @@ default_arg (const char *p, int len) return 0; } +/* Return the value of multilib_dir. */ + +const char * +get_multilib_dir (void) +{ + set_multilib_dir (); + return multilib_dir; +} + +/* Reset the mdswitches array to empty. */ + +void +reset_mdswitches (void) +{ + n_mdswitches = 0; + mdswitches = NULL; +} + /* Work out the subdirectory to use based on the options. The format of multilib_select is a list of elements. Each element is a subdirectory name followed by a list of options followed by a semicolon. The format diff --git a/gcc/gcc.h b/gcc/gcc.h index 19a61b373ee..03646ff2d87 100644 --- a/gcc/gcc.h +++ b/gcc/gcc.h @@ -73,6 +73,11 @@ struct spec_function extern int do_spec (const char *); extern void record_temp_file (const char *, int, int); extern void set_input (const char *); +extern const char *get_multilib_dir (void); +extern void reset_mdswitches (void); +extern void save_switch (const char *opt, size_t n_args, + const char *const *args, + bool validated, bool known); /* Spec files linked with gcc.cc must provide definitions for these. */ diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc index 583723da416..dbfd1cacccc 100644 --- a/gcc/m2/gm2spec.cc +++ b/gcc/m2/gm2spec.cc @@ -797,8 +797,14 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, if ((decoded_options[i].orig_option_with_args_text != NULL) && (strncmp (decoded_options[i].orig_option_with_args_text, "-m", 2) == 0)) - multilib_dir = xstrdup (decoded_options[i].orig_option_with_args_text - + 2); + save_switch (decoded_options[i].orig_option_with_args_text, + 0, NULL, true, true); + else if ((decoded_options[i].orig_option_with_args_text != NULL) + && (strncmp (decoded_options[i].orig_option_with_args_text, + "-f", 2) == 0)) + save_switch (decoded_options[i].orig_option_with_args_text, + 0, NULL, true, true); + break; } } if (language != NULL && (strcmp (language, "modula-2") != 0)) @@ -864,10 +870,13 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, if ((! (seen_uselist || seen_gen_module_list)) && linking) append_option (OPT_fgen_module_list_, "-", 1); + multilib_dir = get_multilib_dir (); + reset_mdswitches (); if (allow_libraries) { /* If the libraries have not been specified by the user but the - dialect has been specified then select the appropriate libraries. */ + dialect has been specified then select the appropriate + libraries. */ if (libraries == NULL) { if (strcmp (dialect, "iso") == 0)