From patchwork Sat Jan 7 17:39:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaius Mulley X-Patchwork-Id: 40426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1390670wrt; Sat, 7 Jan 2023 09:39:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXs+9PeOPEevJbHxLncu6BMD+t6BQwJ+gaECtk8KIUz8/yG/JXcJYjpgaWkmzD5SHeJvI+Nq X-Received: by 2002:a05:6402:1f89:b0:47b:16c7:492c with SMTP id c9-20020a0564021f8900b0047b16c7492cmr57799077edc.25.1673113194451; Sat, 07 Jan 2023 09:39:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673113194; cv=none; d=google.com; s=arc-20160816; b=LcIFFBw7K3Kf9KT/2DarMpojU4nZ1zAPB+7bTkFC0og7cchj/DaJq9gU8a+ZYMdwMA otDXX1KjdOeKdtUmhtjg2ebB06mvTJMXBDOUp5m/C8kEUDlr3Lc98Xgc8oyiKNJeSl7Q JQE1S63l4AHLYR8IdJ/pdA2TmfPRg+ZX1NFjb3H+4bXWvsu2J9kYLpB80y6CLeSuNe43 wMpWCE5dxIazAEa7yilAhPSc8PlPEkswKtmxKYpjcTxu9VQG0Q/ahZ8242elZa7IYJir B/zdehk9tZnpBcrcQLJ+p0kpjPNccMjDSlE05PuFC/Gruyuyua5yUJW5nbIeRHE6FE9g 24bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:message-id:date:subject:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=VOKAVgB+QbXrwa+9t1nn+W7WCa6UynAgtagwYxj5Tv0=; b=jv7DNbbcPvDePtuzSRVopXvEjKcqbmNs99PRBlbJdRG4AviEZD1Zz4MOo4lzqocDvP PShq5FjVJim6g6DPQsfo96Ee45dVWnXTnlWYqFWR185CK9XJkLV1cwUz6S8anL+204xf 5U7brSNKftmgVi5HJ742rEJ3Cna7GqVN6Gj8hJYKTUHem4A28A793cuvtQercJhmh/O5 mSuEYEVvDREp32Ewx7JcUWSxK6aoxDn21s6JrRWS67k9s9xNeyCaggEvKZKByHOobAZJ E7cloThtRcSaE0T4OQDU/SUNxB62qjxOzhIEoMlOs4ag3ztIeumlaVl8eHSRY5rntkWO KYfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FY1VATkY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h2-20020a056402280200b00493969bd008si5510437ede.121.2023.01.07.09.39.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 09:39:54 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FY1VATkY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 73AD1385842E for ; Sat, 7 Jan 2023 17:39:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 73AD1385842E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673113193; bh=VOKAVgB+QbXrwa+9t1nn+W7WCa6UynAgtagwYxj5Tv0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FY1VATkYXEUbWipUMQbKNnZ8mY6FqarPck7TWsVVcVuWaEcReKAQ3hg0wyNbgmF4g vDrVi3ImX/qpq1OUkeuRWtkOpLnS66vkqJpKVoQlfnRulaAOt5GxVwpfZlqduCxOd9 eNH36uD/BMhEWjpTjNzYLQYzSo1TKOARuJjhYTBY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 89F243858D35 for ; Sat, 7 Jan 2023 17:39:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89F243858D35 Received: by mail-wr1-x42e.google.com with SMTP id bn26so4082883wrb.0 for ; Sat, 07 Jan 2023 09:39:09 -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:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VOKAVgB+QbXrwa+9t1nn+W7WCa6UynAgtagwYxj5Tv0=; b=qK/9NSYG0TOy7SBBlaJbrJ+9Ran0QEdI97lj4/fBmBnltbiXf3GU5sW7dUGmVpMZ6r UJCF/JF51YlKo8vI8WCxdCCGyBtmT6nNPmV3PDzkNyKJLdBuC9pPPHSg0qTIGpZBbzGp keqWE9uDjOp48NOrTQKUp7X7Ynef4KFnNwLWp++Doobwdg6UY9JFyBo7qokdcBz3LQC+ 0eKeL++w0HemAcgIl2gMpEpf/8Sn/QtE2R4QIsNQ0POWfllPrgpQMRxI382SPQctcGMU DNU+nLJumotf6MRhIQ+krC+ir/UuhnwPL5/0/Arfz3PF63j3AlOCPjzyoDdFyWvlEOVn xD2w== X-Gm-Message-State: AFqh2krxoxInQLmfH2JRzaTFIN9FbsAjSkjNHeR+ym6tlWUm4TWP/AHv gwoCY3w4cwhmuDFVoVc/5UQXRah7cQc= X-Received: by 2002:adf:e50c:0:b0:296:3eb0:f91f with SMTP id j12-20020adfe50c000000b002963eb0f91fmr16499077wrm.2.1673113148284; Sat, 07 Jan 2023 09:39:08 -0800 (PST) Received: from lancelot ([195.147.220.46]) by smtp.gmail.com with ESMTPSA id i10-20020adff30a000000b0024228b0b932sm5159795wro.27.2023.01.07.09.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 09:39:07 -0800 (PST) Received: from gaius by lancelot with local (Exim 4.94.2) (envelope-from ) id 1pED9u-007M6D-UH; Sat, 07 Jan 2023 17:39:06 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH, modula2] v2 PR-108182 gm2 driver mishandles target and multilib options Date: Sat, 07 Jan 2023 17:39:06 +0000 Message-ID: <87fscmckhx.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.6 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754386340887249602?= X-GMAIL-MSGID: =?utf-8?q?1754386340887249602?= Hi, This is version 2 with the SKIPOPT applied to every option given to save_switch. ok for master? Bootstrapped on x86_64 gnu/linux and darwin. regards, Gaius PR-108182 gm2 driver mishandles target and multilib options 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 be to use a spec function to fixup the paths. gcc/ChangeLog: * gcc.cc (save_switch): Remove static declaration. (get_multilib_dir): New function. (reset_mdswitches): New function. * gcc/gcc.h (save_switch): Declare extern. (get_multilib_dir): New extern. (reset_mdswitches): New extern. gcc/m2/ChangeLog: * gm2spec.cc (lang_specific_driver): Detect -m and -f options and call save_switch and SKIPOPT. Assign multilib_dir with the result of get_multilib_dir. Call reset_mdswitches afterwards. 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..d813de4ab46 100644 --- a/gcc/m2/gm2spec.cc +++ b/gcc/m2/gm2spec.cc @@ -797,8 +797,20 @@ 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); + args[i] |= SKIPOPT; + } + 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); + args[i] |= SKIPOPT; + } + break; } } if (language != NULL && (strcmp (language, "modula-2") != 0)) @@ -864,10 +876,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)