On Mon, Aug 7, 2017 at 7:18 AM, Michael Matz <
ma...@suse.de> wrote:
> Hi,
>
> On Mon, 7 Aug 2017, H.J. Lu wrote:
>
>> > Before removing the last segment register from general use (and hence
>> > break some existing apps) I'd want to see a much better rationale then
>> > "yeah, something with address spaces".
>> >
>> >> > doesn't really help there, I think, because the __gp seems to be global.
>> >>
>> >> __gp is a hidden global symbol and unique to each ELF module.
>> >
>> > E.g. if __gp is hidden and unique per ELF module (and hence not global at
>> > all!) why would .got not be enough?
>> >
>>
>> [hjl@gnu-tools-1 tmp]$ cat x.c
>> int __seg_gs i;
>> int foo (void) { return i; }
> ...
>> movl %gs:i(%rip), %eax
> ...
>> GOT isn't used and GOT may be desirable in some cases.
>
> I don't see how this clears anything up or gives a rationale. If __gp is
> hidden local per ELF module (and hence _different_ per ELF module), then
> per your initial description:
>
> "Linker sets __gp to the middle of the section which contains
> definitions of symbols with GPOFF relocations and the maximum offset is
> [-2G, 2G). Run-time must initialize the segment register, %seg, with the
> address of global pointer, __gp."
>
> the above reference to 'i' (using the new proposed reloc, being an offset
> from %gs:0, which is specific to the ELF module containing that
> instruction) is implicitely hidden and local to the ELF module as well.
> At which point this all seems a bit silly as you could just as well also
> use a proper hidden symbol in local .bss/.data, addressed via PC-relative,
> or via GOT offset.
>
> Another problem with the above is that to have __gp (and therefore gs:0)
> be local and different per ELF module you'd have to actively change and
> restore it whenever you cross ELF module borders.
>
> If, OTOH you just mispecified the above and intended to leave __gp be
> indeed global and the same for all ELF modules, then you need the same
> mechanisms that currently deal with TLS storage also for this "global"
> segment (namely you need to construct one from all constituent ELF
> modules, and need to provision for the offsets into that constructed block
> to not be link time constants but only load time constants (when ignoring
> dlopen!) and so need some space to store these offsets in memory so that
> the loader can modify them).
>
> So, again, I'm still confused about your rationale and how you intend for
> all this to work together.
>
My proposal is the counter part of __seg_fs/__seg_gs in compiler. It
has its limitation and isn't a replacement of TLS. The same questions
can be asked for _seg_fs/__seg_gs.
--
H.J.