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: 40270 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1038021wrt; Fri, 6 Jan 2023 13:43:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXu3TW68GL9nRcRpGKe+HjaYk8x54nbcc8wmTd6XfAKZnQtlKcnBoNEdYUajQd5ISTfvWSnr X-Received: by 2002:a05:6402:520b:b0:48b:58be:472c with SMTP id s11-20020a056402520b00b0048b58be472cmr35980199edd.18.1673041381976; Fri, 06 Jan 2023 13:43:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673041381; cv=none; d=google.com; s=arc-20160816; b=gTt3NAmE5jgbm7H3Dxc+ypDhj0nwqhd8wC6e7qs3P1ByiMhoCteFiTuXSHiUaN7WAg YzJpuKaNQHBZ7qju+NxE7JjdJhqFNRR5ENC3LmTgWazp9jzzB3hCL5SRs7n7ULp3h+fL RxjakqGvhTXi0LKznBbCeAAD9pCM0DsgE/+SbkvHsPwAs+x91xSSdFPYuCMPAMfV+Sz+ bSFcqrTnfdfRgEu7Y4ncmr5QeZ/xBiABbR6QjpBMxN9qo/aIZZeTBylxccultD3vrVeM kPstt+i+5/pqA5arMMvgXMR7CgRxGjD9eAab7riF9qL5O88UrFlVZJKiNjopb/qqFqLH zyHw== 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:cc:subject:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=+nS0POFq8TLjRmp+bOKHVAOVRiI1OVApf2Zr7gzZJPk=; b=mbMbHtOw8NYJz5aJ2sM/SbpHdMN+Fvh8DAVUnzUTUWZFVioXAqAz/iy2Y8/LQ/Hvx+ qMYgPtSXb6kWzolLFcNkpkmbN+VuppMS6QC+FgMYCc86/bbncRqiRDedmc4U3SZ3R8lB 6Zf4fDdR4xF0C56mvLc860R/+0acOL1NH3y31aB8HMfjy40MzGMA+IvTgADR6c+3qAZE wNNTtfPt6CYVKpJWoVmtw+n3BZL3tRf2DnWPw3j7+w4AqENXW/bfc8XFVk8Gnsy2fxA7 YUkrvn5T3CRNQZP0jqWVxX0MvxYEZwZW2qhm3ecr8GEBOqvD8QA8DyofSIZbWy+yy6Jp S46Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hwx8R6aF; 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 i10-20020a170906264a00b007c173f57c88si1692898ejc.811.2023.01.06.13.43.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 13:43:01 -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=hwx8R6aF; 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 0A2C03858C1F for ; Fri, 6 Jan 2023 21:43:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A2C03858C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673041381; 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=hwx8R6aFWBtvy2Z8HpUrlf6u6XFf3uO4Ou/uepHWtDnCUqzVjz4WdBkRAU9OyWPBU eSVr+znqK4AotgDh+Jf20kLKdiHc+XpS30y7B+/s0NGKMHHS6WtM3/eQx/oL9BIcBU P+U9ablZPiaxKSSaoj3xxjaptRUcvhfuqwiO8+5g= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754311040155145405?= X-GMAIL-MSGID: =?utf-8?q?1754311040155145405?= 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)