public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: Fangrui Song <i@maskray.me>
Cc: Umesh Kalappa <umesh.kalappa0@gmail.com>,
	Binutils <binutils@sourceware.org>
Subject: Re: Linker diagnostics for the incorrect options .
Date: Wed, 23 Sep 2020 10:31:03 +0100	[thread overview]
Message-ID: <af5dda68-3ecc-e794-f29b-295aa523bc69@redhat.com> (raw)
In-Reply-To: <MWHPR12MB14567F315D72755B1CC41210CB3B0@MWHPR12MB1456.namprd12.prod.outlook.com>

[-- Attachment #1: Type: text/plain, Size: 818 bytes --]

Hi Fangrui,

> This is a conflict between the grouped short options syntax and single
> dash prefixed long options.
> 
> % touch an ommand ':)'
> % ld.bfd -you -can -ofcourse -use -this -Long -command -Line ':)'
> :)

he!

> For newer long options, we should encourage EXACTLY_TWO_DASHES

Definitely.

> (ld/lexsup.c). I have not seen grouped short options in a very large
> code base and FreeBSD.
> Maybe we can deprecate grouped short options syntax for ld.

I like this idea.  How about the attached patch ?  With it applied I
get output like this:

  % ld -vn -non-static -e 0 -v -e2 hello.o
  GNU ld (GNU Binutils) 2.35.50.20200923
  ld: Warning: grouped short command line options are deprecated: -vn
  ld: Error: unable to disambiguate: -non-static (did you mean --non-static ?)

  % echo $?
  1

Cheers
  Nick

[-- Attachment #2: ld-deprecate-grouped-options.patch --]
[-- Type: text/x-patch, Size: 1131 bytes --]

diff --git a/ld/lexsup.c b/ld/lexsup.c
index b8f066745f..f906508037 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -735,6 +735,21 @@ parse_args (unsigned argc, char **argv)
 	  optind = last_optind;
 	  optc = getopt_long (argc, argv, "-", really_longopts, &longind);
 	}
+      /* Attempt to detect grouped short options,  eg: "-non-start".
+	 Accepting such options is error prone as it is not clear if the user
+	 intended "-n -o n-start" or "--non-start".  */
+      else if (longind == 0  /* This is a short option.  */
+	       && optc > 32  /* It is a valid option.  */
+	       && optind != last_optind /* It is not a repeat of the previous option.  */
+	       && optc != argv[last_optind][1] /* The character is not the second character of argv[last_optind].  */
+	       )
+	{
+	  if (optarg)
+	    einfo (_("%F%P: Error: unable to disambiguate: %s (did you mean -%s ?)\n"),
+		   argv[last_optind], argv[last_optind]);
+	  else
+	    einfo (_("%P: Warning: grouped short command line options are deprecated: %s\n"), argv[last_optind]);
+	}
 
       if (ldemul_handle_option (optc))
 	continue;

  parent reply	other threads:[~2020-09-23  9:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-19  5:29 Umesh Kalappa
2020-09-22 12:31 ` Nick Clifton
2020-09-22 18:40   ` Fangrui Song
     [not found]   ` <MWHPR12MB14567F315D72755B1CC41210CB3B0@MWHPR12MB1456.namprd12.prod.outlook.com>
2020-09-23  9:31     ` Nick Clifton [this message]
2020-10-02  0:19       ` Fangrui Song
     [not found]       ` <MWHPR12MB145628F1D93CC392F9F8F1DECB310@MWHPR12MB1456.namprd12.prod.outlook.com>
2020-10-05 12:55         ` Nick Clifton
2020-12-11 10:25       ` Matthias Klose

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=af5dda68-3ecc-e794-f29b-295aa523bc69@redhat.com \
    --to=nickc@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=i@maskray.me \
    --cc=umesh.kalappa0@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).