public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Linker diagnostics for the incorrect options .
@ 2020-08-19  5:29 Umesh Kalappa
  2020-09-22 12:31 ` Nick Clifton
  0 siblings, 1 reply; 7+ messages in thread
From: Umesh Kalappa @ 2020-08-19  5:29 UTC (permalink / raw)
  To: Binutils

Hi All ,

Linker error handling for non  options or incorrect options should be
robust for instance like
$gcc -c test.c
$ld -non-static test.o

The linker  interpretation for  "-n" as a standard option for  nmagic ,then
"o" as output filename  by name "n-static" which is the dynamic executable .

So linker should be robust here with proper diagnostic and we  would like
to fix the same,before that we would like to hear from the experts here.

  Thank you in advance .
~Umesh




<#m_-1933998605313114137_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Linker diagnostics for the incorrect options .
  2020-08-19  5:29 Linker diagnostics for the incorrect options Umesh Kalappa
@ 2020-09-22 12:31 ` Nick Clifton
  2020-09-22 18:40   ` Fangrui Song
       [not found]   ` <MWHPR12MB14567F315D72755B1CC41210CB3B0@MWHPR12MB1456.namprd12.prod.outlook.com>
  0 siblings, 2 replies; 7+ messages in thread
From: Nick Clifton @ 2020-09-22 12:31 UTC (permalink / raw)
  To: Umesh Kalappa, Binutils

Hi Umesh,

> Linker error handling for non  options or incorrect options should be
> robust for instance like
> $gcc -c test.c
> $ld -non-static test.o
> 
> The linker  interpretation for  "-n" as a standard option for  nmagic ,then
> "o" as output filename  by name "n-static" which is the dynamic executable .

This is really a feature of the getopt functions provided by the libiberty
library.  Note that the correct behaviour does happen if you use two dashes
instead of one:

  % ld --non-static test.o
  ld: unrecognized option '--non-static'
  ld: use the --help option for usage information

Essentially this is a user education issue.  Long options should be proceeded 
by double dashes.  Single dashes may work, sometimes, but weird effects can
also occur.

Cheers
  Nick


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Linker diagnostics for the incorrect options .
  2020-09-22 12:31 ` Nick Clifton
@ 2020-09-22 18:40   ` Fangrui Song
       [not found]   ` <MWHPR12MB14567F315D72755B1CC41210CB3B0@MWHPR12MB1456.namprd12.prod.outlook.com>
  1 sibling, 0 replies; 7+ messages in thread
From: Fangrui Song @ 2020-09-22 18:40 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Umesh Kalappa, Binutils

On Tue, Sep 22, 2020 at 5:31 AM Nick Clifton via Binutils
<binutils@sourceware.org> wrote:
>
> Hi Umesh,
>
> > Linker error handling for non  options or incorrect options should be
> > robust for instance like
> > $gcc -c test.c
> > $ld -non-static test.o
> >
> > The linker  interpretation for  "-n" as a standard option for  nmagic ,then
> > "o" as output filename  by name "n-static" which is the dynamic executable .
>
> This is really a feature of the getopt functions provided by the libiberty
> library.  Note that the correct behaviour does happen if you use two dashes
> instead of one:
>
>   % ld --non-static test.o
>   ld: unrecognized option '--non-static'
>   ld: use the --help option for usage information
>
> Essentially this is a user education issue.  Long options should be proceeded
> by double dashes.  Single dashes may work, sometimes, but weird effects can
> also occur.
>
> Cheers
>   Nick
>

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 ':)'
:)

For newer long options, we should encourage EXACTLY_TWO_DASHES
(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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Linker diagnostics for the incorrect options .
       [not found]   ` <MWHPR12MB14567F315D72755B1CC41210CB3B0@MWHPR12MB1456.namprd12.prod.outlook.com>
@ 2020-09-23  9:31     ` Nick Clifton
  2020-10-02  0:19       ` Fangrui Song
                         ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Nick Clifton @ 2020-09-23  9:31 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Umesh Kalappa, Binutils

[-- 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;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Linker diagnostics for the incorrect options .
  2020-09-23  9:31     ` Nick Clifton
@ 2020-10-02  0:19       ` Fangrui Song
       [not found]       ` <MWHPR12MB145628F1D93CC392F9F8F1DECB310@MWHPR12MB1456.namprd12.prod.outlook.com>
  2020-12-11 10:25       ` Matthias Klose
  2 siblings, 0 replies; 7+ messages in thread
From: Fangrui Song @ 2020-10-02  0:19 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Umesh Kalappa, Binutils

On Wed, Sep 23, 2020 at 2:31 AM Nick Clifton <nickc@redhat.com> wrote:
>
> 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

Thanks! Perhaps    ` && optind != last_optind /* It is not a repeat of
the previous option.  */` can be deleted... Nobody repeats a short
option for ld,
unless they want to have fun with:

% Debug/ld/ld-new -vvvvvv
GNU ld (GNU Binutils) 2.35.50.20201002
GNU ld (GNU Binutils) 2.35.50.20201002
GNU ld (GNU Binutils) 2.35.50.20201002
GNU ld (GNU Binutils) 2.35.50.20201002
GNU ld (GNU Binutils) 2.35.50.20201002
GNU ld (GNU Binutils) 2.35.50.20201002

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Linker diagnostics for the incorrect options .
       [not found]       ` <MWHPR12MB145628F1D93CC392F9F8F1DECB310@MWHPR12MB1456.namprd12.prod.outlook.com>
@ 2020-10-05 12:55         ` Nick Clifton
  0 siblings, 0 replies; 7+ messages in thread
From: Nick Clifton @ 2020-10-05 12:55 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Umesh Kalappa, Binutils

Hi Fangrui,

> Thanks! Perhaps    ` && optind != last_optind /* It is not a repeat of
> the previous option.  */` can be deleted... Nobody repeats a short
> option for ld,
> unless they want to have fun with:
> 
> % Debug/ld/ld-new -vvvvvv
> GNU ld (GNU Binutils) 2.35.50.20201002
> GNU ld (GNU Binutils) 2.35.50.20201002
> GNU ld (GNU Binutils) 2.35.50.20201002
> GNU ld (GNU Binutils) 2.35.50.20201002

Awww, you mean real users won't want to do that ? :-)

Advice accepted.  I have applied the patch with that line removed.

Cheers
  Nick



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Linker diagnostics for the incorrect options .
  2020-09-23  9:31     ` Nick Clifton
  2020-10-02  0:19       ` Fangrui Song
       [not found]       ` <MWHPR12MB145628F1D93CC392F9F8F1DECB310@MWHPR12MB1456.namprd12.prod.outlook.com>
@ 2020-12-11 10:25       ` Matthias Klose
  2 siblings, 0 replies; 7+ messages in thread
From: Matthias Klose @ 2020-12-11 10:25 UTC (permalink / raw)
  To: Nick Clifton, Fangrui Song; +Cc: Binutils

On 9/23/20 11:31 AM, Nick Clifton via Binutils wrote:
> 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

this causes PR ld/27050:

$ ld.bfd -no-pie
ld.bfd: Error: unable to disambiguate: -no-pie (did you mean --no-pie ?)


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-12-11 10:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19  5:29 Linker diagnostics for the incorrect options 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
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

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).