From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-x42e.google.com with SMTP id bn26so4082883wrb.0 for ; Sat, 07 Jan 2023 09:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to; bh=VOKAVgB+QbXrwa+9t1nn+W7WCa6UynAgtagwYxj5Tv0=; b=DIkjWTYEIiVstceVF+nCDL3bjz2L/a3qysDb8iodeWbJY9WtSZZ5/p5c5kzXKLYyFC KiaoagyVCmSZCYr7qoLVh1gEw3sIuVBpHgYKzmbi3MMq5pb1OMWukqUIHaj0DFetGkvl bjPYXR48lQbVJu7XrvkOzqbTZonjxBzWvtG+hXazc+lrBPbFNFkH2bV7EeG11tOKuDJM beQAi2vaNJv+wL6XNrhmlQmsK/U7zsbX6k5moWbTw+aalUQ1T6ZmY2pCDF3S9zTFfXwm EeoEa0Bsjr/F7ub/6sHJSW31/Cb2l6DJhl4pxITkPF+/9M6t6RunJU+wjamOulw3qdSq 8EjQ== 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-Google-Smtp-Source: AMrXdXvaXqJQkv+yschn7s9vgqt+bXGVXeE/LnUtR+jMg7N6b3KY/pnQ1oQynMHCMz0qn8AnW2gK5g== 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 From: Gaius Mulley 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 Content-Type: text/plain 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 List-Id: 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)