[PATCH v3 2/2] Default to --with-default-link=no (bug 25812)

Florian Weimer fweimer@redhat.com
Fri Apr 29 14:55:37 GMT 2022


* Fangrui Song:

> On 2022-04-29, Florian Weimer wrote:
>>* Fangrui Song:
>>
>>>>How does lld place sections without a linker script?  Purely based on
>>>>names?
>>>
>>> It entirely uses code to describe the built-in rules like gold, while
>>> GNU ld uses an internal linker script plus built-in code.
>>> (some rules cannot be described by the linker script language and needs
>>> code anyway).
>>
>>How can we make sure that certain sections are covered by RELRO, and
>>still get start/stop symbols for them?
>
> About __start_/__stop_:
> __start_/__stop_ symbols are special. They don't need to be mentioned in a
> linker script to take effects for lld and modern GNU ld. I haven't checked
> whether there is an ancient GNU ld which requires symbol assignments when the
> output section description is specified.

According to the BFD ld documentation, __start_/__stop_ symbols are only
generated if the resulting name is a C identifier and the name is the
same.  That means that if we name the section .data.rel.ro.vtables or
something like that (to benefit from .data.rel.ro.* placement), we won't
get the start/stop symbols.  If we use a C identifier name for the
section, it won't be covered by RELRO.

> About RELRO:
> It seems that there is no section name convention to make a section
> RELRO.  Having a SECTIONS command with DATA_SEGMENT_ALIGN /
> DATA_SEGMENT_RELRO_END can specify all RELRO sections. I do not know a
> simpler approach than postprocessing ld.bfd --verbose output.
>
> To make GNU ld work, the following linker script is sufficient:
>
>   SECTIONS {
>            __libc_subfreeres : { *(__libc_subfreeres) }
>            __libc_atexit : { *(__libc_atexit) }
>            __libc_IO_vtables : { *(__libc_IO_vtables) }
>   } INSERT BEFORE .data.rel.ro;

That might work.  But if we cut down the number of vtables, I think we
can eliminate those special RELRO sections altogether.

We have been slowly migrating off __libc_subfreeres and the like because
having shutdown order depend on link is very non-obvious and
problematic.  For example, for optimimum results, we want to shut down
malloc last on a thread.

Thanks,
Florian



More information about the Libc-alpha mailing list