public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* _rtld_global, _rtld_global_ro (and local aliases) as an optimization
@ 2023-06-06 12:14 Florian Weimer
  2023-06-06 19:30 ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 9+ messages in thread
From: Florian Weimer @ 2023-06-06 12:14 UTC (permalink / raw)
  To: libc-alpha

We currently use _rtld_global, _rtld_global_ro to pass information from
ld.so to the other shared objects.  For this purpose, it is convenient
to have everything in two structs because we do not need to add
additional exports.

There is another effect, though.  Due to the local hidden aliases
_rtld_local, _rtld_local_ro in ld.so (similar to
rtld_hidden_proto/rtld_hidden_def, but implemented differently), the
instruction sequence for field access is potentially shorter than it
would be if all these fields were separate global variables (still with
hidden visibility).  On many RISC targets, constructing the address of a
hidden global variable or a struct member needs two instructions.
However, obtaining the address of a different struct member is just one
instruction if you already have the address of another member.

Is this optimization still important?  It's often preferable not to add
new fields to _rtld_global/_rtld_global_ro for data that is internal to
ld.so, to avoid changing the internal GLIBC_PRIVATE ABI.  This helps
with backporting because it enables zero-downtime upgrades.

Thanks,
Florian


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

* Re: _rtld_global, _rtld_global_ro (and local aliases) as an optimization
  2023-06-06 12:14 _rtld_global, _rtld_global_ro (and local aliases) as an optimization Florian Weimer
@ 2023-06-06 19:30 ` Adhemerval Zanella Netto
  2023-06-07  8:57   ` Florian Weimer
  0 siblings, 1 reply; 9+ messages in thread
From: Adhemerval Zanella Netto @ 2023-06-06 19:30 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha



On 06/06/23 09:14, Florian Weimer via Libc-alpha wrote:
> We currently use _rtld_global, _rtld_global_ro to pass information from
> ld.so to the other shared objects.  For this purpose, it is convenient
> to have everything in two structs because we do not need to add
> additional exports.
> 
> There is another effect, though.  Due to the local hidden aliases
> _rtld_local, _rtld_local_ro in ld.so (similar to
> rtld_hidden_proto/rtld_hidden_def, but implemented differently), the
> instruction sequence for field access is potentially shorter than it
> would be if all these fields were separate global variables (still with
> hidden visibility).  On many RISC targets, constructing the address of a
> hidden global variable or a struct member needs two instructions.
> However, obtaining the address of a different struct member is just one
> instruction if you already have the address of another member.
> 
> Is this optimization still important?  It's often preferable not to add
> new fields to _rtld_global/_rtld_global_ro for data that is internal to
> ld.so, to avoid changing the internal GLIBC_PRIVATE ABI.  This helps
> with backporting because it enables zero-downtime upgrades.

It is not really clear which optimization are you referring here, do mean
using __rtld_local_attribute__ with section (".sdata") when the architecture 
supports it (like mostly RISC targets)? Or having _rtld_global_ro being an
alias to _rtld_local_ro within the loader?

Also, what kind of changing are you proposing? 

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

* Re: _rtld_global, _rtld_global_ro (and local aliases) as an optimization
  2023-06-06 19:30 ` Adhemerval Zanella Netto
@ 2023-06-07  8:57   ` Florian Weimer
  2023-06-07  9:14     ` Andreas Schwab
  0 siblings, 1 reply; 9+ messages in thread
From: Florian Weimer @ 2023-06-07  8:57 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: libc-alpha

* Adhemerval Zanella Netto:

> On 06/06/23 09:14, Florian Weimer via Libc-alpha wrote:
>> We currently use _rtld_global, _rtld_global_ro to pass information from
>> ld.so to the other shared objects.  For this purpose, it is convenient
>> to have everything in two structs because we do not need to add
>> additional exports.
>> 
>> There is another effect, though.  Due to the local hidden aliases
>> _rtld_local, _rtld_local_ro in ld.so (similar to
>> rtld_hidden_proto/rtld_hidden_def, but implemented differently), the
>> instruction sequence for field access is potentially shorter than it
>> would be if all these fields were separate global variables (still with
>> hidden visibility).  On many RISC targets, constructing the address of a
>> hidden global variable or a struct member needs two instructions.
>> However, obtaining the address of a different struct member is just one
>> instruction if you already have the address of another member.
>> 
>> Is this optimization still important?  It's often preferable not to add
>> new fields to _rtld_global/_rtld_global_ro for data that is internal to
>> ld.so, to avoid changing the internal GLIBC_PRIVATE ABI.  This helps
>> with backporting because it enables zero-downtime upgrades.
>
> It is not really clear which optimization are you referring here, do mean
> using __rtld_local_attribute__ with section (".sdata") when the architecture 
> supports it (like mostly RISC targets)? Or having _rtld_global_ro being an
> alias to _rtld_local_ro within the loader?

Maintaining global variables as _rtld_global/_rtld_global_ro fields even
if they are not needed outside ld.so.

> Also, what kind of changing are you proposing? 

As a concrete example, we could turn GLRO(dl_dso_sort_algo) into

static int dso_sort_algo;

in elf/dl-sort-maps.c because it's not used outside the file.

Thanks,
Florian


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

* Re: _rtld_global, _rtld_global_ro (and local aliases) as an optimization
  2023-06-07  8:57   ` Florian Weimer
@ 2023-06-07  9:14     ` Andreas Schwab
  2023-06-07  9:37       ` Florian Weimer
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2023-06-07  9:14 UTC (permalink / raw)
  To: Florian Weimer via Libc-alpha; +Cc: Adhemerval Zanella Netto, Florian Weimer

On Jun 07 2023, Florian Weimer via Libc-alpha wrote:

> As a concrete example, we could turn GLRO(dl_dso_sort_algo) into
>
> static int dso_sort_algo;
>
> in elf/dl-sort-maps.c because it's not used outside the file.

I think it was just a mistake to put it there initially.  None of the
definitions related to the DSO sort algo (except _dl_sort_maps_init)
need to be visible outside that file.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: _rtld_global, _rtld_global_ro (and local aliases) as an optimization
  2023-06-07  9:14     ` Andreas Schwab
@ 2023-06-07  9:37       ` Florian Weimer
  2023-06-07 12:08         ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 9+ messages in thread
From: Florian Weimer @ 2023-06-07  9:37 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Florian Weimer via Libc-alpha, Adhemerval Zanella Netto

* Andreas Schwab:

> On Jun 07 2023, Florian Weimer via Libc-alpha wrote:
>
>> As a concrete example, we could turn GLRO(dl_dso_sort_algo) into
>>
>> static int dso_sort_algo;
>>
>> in elf/dl-sort-maps.c because it's not used outside the file.
>
> I think it was just a mistake to put it there initially.  None of the
> definitions related to the DSO sort algo (except _dl_sort_maps_init)
> need to be visible outside that file.

We have more cases that are somewhat similar, where we could use an
extern attribute_hidden variable instead of a struct member.  What about
those?

Thanks,
Florian


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

* Re: _rtld_global, _rtld_global_ro (and local aliases) as an optimization
  2023-06-07  9:37       ` Florian Weimer
@ 2023-06-07 12:08         ` Adhemerval Zanella Netto
  2023-06-07 12:21           ` Florian Weimer
  0 siblings, 1 reply; 9+ messages in thread
From: Adhemerval Zanella Netto @ 2023-06-07 12:08 UTC (permalink / raw)
  To: Florian Weimer, Andreas Schwab; +Cc: Florian Weimer via Libc-alpha



On 07/06/23 06:37, Florian Weimer wrote:
> * Andreas Schwab:
> 
>> On Jun 07 2023, Florian Weimer via Libc-alpha wrote:
>>
>>> As a concrete example, we could turn GLRO(dl_dso_sort_algo) into
>>>
>>> static int dso_sort_algo;
>>>
>>> in elf/dl-sort-maps.c because it's not used outside the file.
>>
>> I think it was just a mistake to put it there initially.  None of the
>> definitions related to the DSO sort algo (except _dl_sort_maps_init)
>> need to be visible outside that file.
> 
> We have more cases that are somewhat similar, where we could use an
> extern attribute_hidden variable instead of a struct member.  What about
> those?

I think it makes sense to cleanup the _rtld_global/_rtld_global_ro variables,
as Andreas has put there are multiple examples that we shouldn't had to
update it.

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

* Re: _rtld_global, _rtld_global_ro (and local aliases) as an optimization
  2023-06-07 12:08         ` Adhemerval Zanella Netto
@ 2023-06-07 12:21           ` Florian Weimer
  2023-06-07 12:40             ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 9+ messages in thread
From: Florian Weimer @ 2023-06-07 12:21 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: Andreas Schwab, Florian Weimer via Libc-alpha

* Adhemerval Zanella Netto:

> On 07/06/23 06:37, Florian Weimer wrote:
>> * Andreas Schwab:
>> 
>>> On Jun 07 2023, Florian Weimer via Libc-alpha wrote:
>>>
>>>> As a concrete example, we could turn GLRO(dl_dso_sort_algo) into
>>>>
>>>> static int dso_sort_algo;
>>>>
>>>> in elf/dl-sort-maps.c because it's not used outside the file.
>>>
>>> I think it was just a mistake to put it there initially.  None of the
>>> definitions related to the DSO sort algo (except _dl_sort_maps_init)
>>> need to be visible outside that file.
>> 
>> We have more cases that are somewhat similar, where we could use an
>> extern attribute_hidden variable instead of a struct member.  What about
>> those?
>
> I think it makes sense to cleanup the _rtld_global/_rtld_global_ro variables,
> as Andreas has put there are multiple examples that we shouldn't had to
> update it.

So the consensus is that we should use this only for cross-DSO
information sharing, and not for optimizing address computation of
global data variables?

Thanks,
Florian


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

* Re: _rtld_global, _rtld_global_ro (and local aliases) as an optimization
  2023-06-07 12:21           ` Florian Weimer
@ 2023-06-07 12:40             ` Adhemerval Zanella Netto
  2023-06-07 12:56               ` Florian Weimer
  0 siblings, 1 reply; 9+ messages in thread
From: Adhemerval Zanella Netto @ 2023-06-07 12:40 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Andreas Schwab, Florian Weimer via Libc-alpha



On 07/06/23 09:21, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
> 
>> On 07/06/23 06:37, Florian Weimer wrote:
>>> * Andreas Schwab:
>>>
>>>> On Jun 07 2023, Florian Weimer via Libc-alpha wrote:
>>>>
>>>>> As a concrete example, we could turn GLRO(dl_dso_sort_algo) into
>>>>>
>>>>> static int dso_sort_algo;
>>>>>
>>>>> in elf/dl-sort-maps.c because it's not used outside the file.
>>>>
>>>> I think it was just a mistake to put it there initially.  None of the
>>>> definitions related to the DSO sort algo (except _dl_sort_maps_init)
>>>> need to be visible outside that file.
>>>
>>> We have more cases that are somewhat similar, where we could use an
>>> extern attribute_hidden variable instead of a struct member.  What about
>>> those?
>>
>> I think it makes sense to cleanup the _rtld_global/_rtld_global_ro variables,
>> as Andreas has put there are multiple examples that we shouldn't had to
>> update it.
> 
> So the consensus is that we should use this only for cross-DSO
> information sharing, and not for optimizing address computation of
> global data variables?

Which cases are uses solely for optimizing address computation? For, instance
the _dl_pagesize along with _dl_auxv. On Linux, we don't really _dl_pagesize,
but it is simpler and faster than iterate over _dl_auxv.

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

* Re: _rtld_global, _rtld_global_ro (and local aliases) as an optimization
  2023-06-07 12:40             ` Adhemerval Zanella Netto
@ 2023-06-07 12:56               ` Florian Weimer
  0 siblings, 0 replies; 9+ messages in thread
From: Florian Weimer @ 2023-06-07 12:56 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: Andreas Schwab, Florian Weimer via Libc-alpha

* Adhemerval Zanella Netto:

>> So the consensus is that we should use this only for cross-DSO
>> information sharing, and not for optimizing address computation of
>> global data variables?
>
> Which cases are uses solely for optimizing address computation? For, instance
> the _dl_pagesize along with _dl_auxv. On Linux, we don't really _dl_pagesize,
> but it is simpler and faster than iterate over _dl_auxv.

I believe GL (dl_rtld_map) is only used within ld.so.

Thanks,
Florian


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

end of thread, other threads:[~2023-06-07 12:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06 12:14 _rtld_global, _rtld_global_ro (and local aliases) as an optimization Florian Weimer
2023-06-06 19:30 ` Adhemerval Zanella Netto
2023-06-07  8:57   ` Florian Weimer
2023-06-07  9:14     ` Andreas Schwab
2023-06-07  9:37       ` Florian Weimer
2023-06-07 12:08         ` Adhemerval Zanella Netto
2023-06-07 12:21           ` Florian Weimer
2023-06-07 12:40             ` Adhemerval Zanella Netto
2023-06-07 12:56               ` Florian Weimer

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