public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* -Ur option documentation
@ 2023-05-05 20:58 Florian Weimer
  2023-05-05 21:41 ` Andreas Schwab
  0 siblings, 1 reply; 11+ messages in thread
From: Florian Weimer @ 2023-05-05 20:58 UTC (permalink / raw)
  To: binutils

The manual says this:

'-Ur'
     For anything other than C++ programs, this option is equivalent to
     '-r': it generates relocatable output--i.e., an output file that
     can in turn serve as input to 'ld'.  When linking C++ programs,
     '-Ur' _does_ resolve references to constructors, unlike '-r'.  It
     does not work to use '-Ur' on files that were themselves linked
     with '-Ur'; once the constructor table has been built, it cannot be
     added to.  Use '-Ur' only for the last partial link, and '-r' for
     the others.

For ELF, this refers to the legacy init function, right?  So it's not
really about C++ in that case.  And the restriction is gone if the
target uses ELF SHT_INIT_ARRAY sections.

Thanks,
Florian


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

* Re: -Ur option documentation
  2023-05-05 20:58 -Ur option documentation Florian Weimer
@ 2023-05-05 21:41 ` Andreas Schwab
  2023-05-08 10:47   ` Florian Weimer
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Schwab @ 2023-05-05 21:41 UTC (permalink / raw)
  To: Florian Weimer via Binutils; +Cc: Florian Weimer

On Mai 05 2023, Florian Weimer via Binutils wrote:

> The manual says this:
>
> '-Ur'
>      For anything other than C++ programs, this option is equivalent to
>      '-r': it generates relocatable output--i.e., an output file that
>      can in turn serve as input to 'ld'.  When linking C++ programs,
>      '-Ur' _does_ resolve references to constructors, unlike '-r'.  It
>      does not work to use '-Ur' on files that were themselves linked
>      with '-Ur'; once the constructor table has been built, it cannot be
>      added to.  Use '-Ur' only for the last partial link, and '-r' for
>      the others.
>
> For ELF, this refers to the legacy init function, right?

No, it refers to the a.out N_SETx symbols.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

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

* Re: -Ur option documentation
  2023-05-05 21:41 ` Andreas Schwab
@ 2023-05-08 10:47   ` Florian Weimer
  2023-05-08 11:48     ` Simon Richter
  2023-05-08 19:08     ` Fangrui Song
  0 siblings, 2 replies; 11+ messages in thread
From: Florian Weimer @ 2023-05-08 10:47 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Florian Weimer via Binutils

* Andreas Schwab:

> On Mai 05 2023, Florian Weimer via Binutils wrote:
>
>> The manual says this:
>>
>> '-Ur'
>>      For anything other than C++ programs, this option is equivalent to
>>      '-r': it generates relocatable output--i.e., an output file that
>>      can in turn serve as input to 'ld'.  When linking C++ programs,
>>      '-Ur' _does_ resolve references to constructors, unlike '-r'.  It
>>      does not work to use '-Ur' on files that were themselves linked
>>      with '-Ur'; once the constructor table has been built, it cannot be
>>      added to.  Use '-Ur' only for the last partial link, and '-r' for
>>      the others.
>>
>> For ELF, this refers to the legacy init function, right?
>
> No, it refers to the a.out N_SETx symbols.

So this doesn't matter to ELF at all?  Would it be possible to update
the documentation accordingly?

Thanks,
Florian


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

* Re: -Ur option documentation
  2023-05-08 10:47   ` Florian Weimer
@ 2023-05-08 11:48     ` Simon Richter
  2023-05-08 19:08     ` Fangrui Song
  1 sibling, 0 replies; 11+ messages in thread
From: Simon Richter @ 2023-05-08 11:48 UTC (permalink / raw)
  To: binutils

Hi,

On 5/8/23 19:47, Florian Weimer via Binutils wrote:

>>> '-Ur'

>>> For ELF, this refers to the legacy init function, right?
>> No, it refers to the a.out N_SETx symbols.

> So this doesn't matter to ELF at all?  Would it be possible to update
> the documentation accordingly?

I remember that we used -Ur excessively when linking programs and 
libraries for uClinux.

With -Ur, a different linker script is used that looks a lot like the 
script used for a final link, i.e. it builds init and fini arrays and 
ctor and dtor blocks, creates the usual generated symbols (_stext, 
_etext, _sdata, _edata, _sbss, _ebss, ...) and merges everything into a 
single section.

The linker then resolves internal relocations, and normally only 
relocations against the start address of the output section remain, 
which are output into the resulting relocatable object, which can be 
easily converted to a binary plus a table of offsets where the absolute 
address must be added.

Nasty hack, but it works.

    Simon

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

* Re: -Ur option documentation
  2023-05-08 10:47   ` Florian Weimer
  2023-05-08 11:48     ` Simon Richter
@ 2023-05-08 19:08     ` Fangrui Song
  2023-05-08 19:13       ` Florian Weimer
  1 sibling, 1 reply; 11+ messages in thread
From: Fangrui Song @ 2023-05-08 19:08 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Andreas Schwab, Florian Weimer via Binutils

On Mon, May 8, 2023 at 3:47 AM Florian Weimer via Binutils
<binutils@sourceware.org> wrote:
>
> * Andreas Schwab:
>
> > On Mai 05 2023, Florian Weimer via Binutils wrote:
> >
> >> The manual says this:
> >>
> >> '-Ur'
> >>      For anything other than C++ programs, this option is equivalent to
> >>      '-r': it generates relocatable output--i.e., an output file that
> >>      can in turn serve as input to 'ld'.  When linking C++ programs,
> >>      '-Ur' _does_ resolve references to constructors, unlike '-r'.  It
> >>      does not work to use '-Ur' on files that were themselves linked
> >>      with '-Ur'; once the constructor table has been built, it cannot be
> >>      added to.  Use '-Ur' only for the last partial link, and '-r' for
> >>      the others.
> >>
> >> For ELF, this refers to the legacy init function, right?
> >
> > No, it refers to the a.out N_SETx symbols.
>
> So this doesn't matter to ELF at all?  Would it be possible to update
> the documentation accordingly?
>
> Thanks,
> Florian
>

Anecdotally, -Ur may be so obscure that nearly no project uses. ld.lld
doesn't implement this option and I haven't heard of any distribution
using ld.lld having broken packages due to -Ur...

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

* Re: -Ur option documentation
  2023-05-08 19:08     ` Fangrui Song
@ 2023-05-08 19:13       ` Florian Weimer
  2023-05-10 10:59         ` Nick Clifton
  0 siblings, 1 reply; 11+ messages in thread
From: Florian Weimer @ 2023-05-08 19:13 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Andreas Schwab, Florian Weimer via Binutils

* Fangrui Song:

> Anecdotally, -Ur may be so obscure that nearly no project uses. ld.lld
> doesn't implement this option and I haven't heard of any distribution
> using ld.lld having broken packages due to -Ur...

Certainly a possibility.  (I only saw it by accident in the manual, I
don't have a use case for it.)

Thanks,
Florian


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

* Re: -Ur option documentation
  2023-05-08 19:13       ` Florian Weimer
@ 2023-05-10 10:59         ` Nick Clifton
  2023-05-10 12:00           ` Florian Weimer
  0 siblings, 1 reply; 11+ messages in thread
From: Nick Clifton @ 2023-05-10 10:59 UTC (permalink / raw)
  To: Florian Weimer, Fangrui Song; +Cc: Andreas Schwab, Florian Weimer via Binutils

Hi Guys,

OK, how about this rewording of the option's description:

   For programs that do not use constructors or destructors,
   or ELF based systems that use the newer SHT_INIT_ARRY
   section type this option is equivalent to -r: it generates
   relocatable output -- i.e., an output file that can in turn
   serve as input to ld.  For qualifying binaries however the
   -Ur option is different in that it *does* resolve
   references to constructors, unlike -r.

   It does not work to use -Ur on files that were themselves
   linked with -Ur; once the constructor table has been built,
   it cannot be added to.  Use -Ur only for the last partial
   link, and -r for the others.

Cheers
   Nick


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

* Re: -Ur option documentation
  2023-05-10 10:59         ` Nick Clifton
@ 2023-05-10 12:00           ` Florian Weimer
  2023-05-10 14:09             ` Nick Clifton
  0 siblings, 1 reply; 11+ messages in thread
From: Florian Weimer @ 2023-05-10 12:00 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Fangrui Song, Andreas Schwab, Florian Weimer via Binutils

* Nick Clifton:

> Hi Guys,
>
> OK, how about this rewording of the option's description:
>
>   For programs that do not use constructors or destructors,
>   or ELF based systems that use the newer SHT_INIT_ARRY
>   section type this option is equivalent to -r: it generates
>   relocatable output -- i.e., an output file that can in turn
>   serve as input to ld.  For qualifying binaries however the
>   -Ur option is different in that it *does* resolve
>   references to constructors, unlike -r.
>
>   It does not work to use -Ur on files that were themselves
>   linked with -Ur; once the constructor table has been built,
>   it cannot be added to.  Use -Ur only for the last partial
>   link, and -r for the others.

Andreas said that DT_INIT should still work with -Ur, so maybe you don't
need the SHT_INIT_ARRY clarification?

Thanks,
Florian


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

* Re: -Ur option documentation
  2023-05-10 12:00           ` Florian Weimer
@ 2023-05-10 14:09             ` Nick Clifton
  2023-05-25  8:08               ` Florian Weimer
  0 siblings, 1 reply; 11+ messages in thread
From: Nick Clifton @ 2023-05-10 14:09 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Fangrui Song, Andreas Schwab, Florian Weimer via Binutils

Hi Florian,

> Andreas said that DT_INIT should still work with -Ur, so maybe you don't
> need the SHT_INIT_ARRY clarification?

So:

     For programs that do not use constructors or destructors,
     or for ELF based systems this option is equivalent to -r:
     it generates relocatable output -- i.e., an output file
     that can in turn serve as input to ld.  For other binaries
     however the -Ur option is similar to -r but it also resolves
     references to constructors and destructors.

     It does not work to use -Ur on files that were themselves
     linked with -Ur; once the constructor table has been built,
     it cannot be added to.  Use -Ur only for the last partial
     link, and -r for the others.

Cheers
   Nick


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

* Re: -Ur option documentation
  2023-05-10 14:09             ` Nick Clifton
@ 2023-05-25  8:08               ` Florian Weimer
  2023-05-30 15:13                 ` Nick Clifton
  0 siblings, 1 reply; 11+ messages in thread
From: Florian Weimer @ 2023-05-25  8:08 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Fangrui Song, Andreas Schwab, Florian Weimer via Binutils

* Nick Clifton:

> Hi Florian,
>
>> Andreas said that DT_INIT should still work with -Ur, so maybe you don't
>> need the SHT_INIT_ARRY clarification?
>
> So:
>
>     For programs that do not use constructors or destructors,
>     or for ELF based systems this option is equivalent to -r:
>     it generates relocatable output -- i.e., an output file
>     that can in turn serve as input to ld.  For other binaries
>     however the -Ur option is similar to -r but it also resolves
>     references to constructors and destructors.
>
>     It does not work to use -Ur on files that were themselves
>     linked with -Ur; once the constructor table has been built,
>     it cannot be added to.  Use -Ur only for the last partial
>     link, and -r for the others.

Maybe “For those systems where -r and -Ur behave differently, it does
not work to use -Ur …”?

Thanks,
Florian


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

* Re: -Ur option documentation
  2023-05-25  8:08               ` Florian Weimer
@ 2023-05-30 15:13                 ` Nick Clifton
  0 siblings, 0 replies; 11+ messages in thread
From: Nick Clifton @ 2023-05-30 15:13 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Fangrui Song, Andreas Schwab, Florian Weimer via Binutils

Hi Florian,

>>      It does not work to use -Ur on files that were themselves
>>      linked with -Ur; once the constructor table has been built,
>>      it cannot be added to.  Use -Ur only for the last partial
>>      link, and -r for the others.
> 
> Maybe “For those systems where -r and -Ur behave differently, it does
> not work to use -Ur …”?

That is reasonable.  I have pushed a patch to reword that paragraph
as you have suggested.

Cheers
   Nick



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

end of thread, other threads:[~2023-05-30 15:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05 20:58 -Ur option documentation Florian Weimer
2023-05-05 21:41 ` Andreas Schwab
2023-05-08 10:47   ` Florian Weimer
2023-05-08 11:48     ` Simon Richter
2023-05-08 19:08     ` Fangrui Song
2023-05-08 19:13       ` Florian Weimer
2023-05-10 10:59         ` Nick Clifton
2023-05-10 12:00           ` Florian Weimer
2023-05-10 14:09             ` Nick Clifton
2023-05-25  8:08               ` Florian Weimer
2023-05-30 15:13                 ` Nick Clifton

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