Propagating addresses from linker to the runtie
Florian Weimer
fweimer@redhat.com
Fri Oct 18 12:56:00 GMT 2019
* Segher Boessenkool:
> On Fri, Oct 18, 2019 at 12:47:49PM +0200, Florian Weimer wrote:
>> > #define symbol_set_declare(set) \
>> > extern char const __start_##set[] __symbol_set_attribute; \
>> > extern char const __stop_##set[] __symbol_set_attribute;
>> >
>> > Due to symbol_set_declare, those symbols expand to two unrelated
>> > symbols. Using unrelated symbols for pointer arithmetic again violates the
>> > standard.
>>
>> Ah. So we need more uintptr_t casts here.
>
> Using reserved names (like those starting with two underscores) is UB
> already. And those particular names actually clash with names GNU LD
> already creates!
Well, those names are created by BFD ld for us as well.
But that doesn't mean that GNU C will do anything sensible with them.
You do not need C language extensions for that. Some of them an
non-controversial, others less so.
>> > Thus, the issue that Martin mentioned applies here, too.
>> >
>> > To get this conforming, the linker would need to export a symbol to the start
>> > of the section and the length of the section, IMHO.
>>
>> Right, but we do not have that today. 8-(
>
> We have had it since over 25 years:
>
> Thu Aug 18 15:37:45 1994 Ian Lance Taylor (ian@sanguine.cygnus.com)
>
> Make the ELF linker handle orphaned sections reasonably. Also,
> define __start_SECNAME and __stop_SECNAME around sections whose
> names can be represented in C, for the benefit of symbol sets in
> glibc.
>
> You just need to have linker scripts that do not sabotage this :-)
But it doesn't work on s390x if the section has a size that is not a
multiple of 2 because all global symbols must have alignment 2 or more
on that architecture (of course __alignof (symbol) may still say 1
because *that* has to reflect C semantics).
Thanks,
Florian
More information about the Gcc-help
mailing list