[PATCH] D27988: [LLD] Combine read-only and writable input sections into single output section

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 20 15:27:16 PST 2016


I don't think this is correct in general.

The spec just says

------------------------------------------------
In the first phase, input sections that match in name, type and
attribute flags should be concatenated into single sections.
----------------------------------------------

Can you change the crt files instead? If we must do this it should
probably be behind an off by default option.

As for the implementation, the change should be inside getOutFlags.

Cheers,
Rafael



Mark Kettenis via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:

> kettenis created this revision.
> kettenis added a reviewer: lld.
> kettenis added a subscriber: llvm-commits.
>
> On OpenBSD crtbegin.o has a read-only .ctors section whereas  crtend.o has a writable .ctors.
> This results in two separate .ctors sections in the output, making the resulting executable crash
> because the sentinel from crtend.o is stored in the second .ctors section which doesn't immediately
> follow the first .ctors section.  This can be easily fixed by masking off the SHF_WRITE flag when
> creating the key that is used to look up the output section.  This will combine the input sections
> into a single output sections that is marked as writable.  This matches the behaviour of  the GNU
> toolchain.
>
>
> https://reviews.llvm.org/D27988
>
> Files:
>   ELF/OutputSections.cpp
>
>
> Index: ELF/OutputSections.cpp
> ===================================================================
> --- ELF/OutputSections.cpp
> +++ ELF/OutputSections.cpp
> @@ -538,7 +538,7 @@
>  static SectionKey<ELFT::Is64Bits> createKey(InputSectionBase<ELFT> *C,
>                                              StringRef OutsecName) {
>    typedef typename ELFT::uint uintX_t;
> -  uintX_t Flags = getOutFlags(C);
> +  uintX_t Flags = getOutFlags(C) & ~SHF_WRITE;
>  
>    // For SHF_MERGE we create different output sections for each alignment.
>    // This makes each output section simple and keeps a single level mapping from
>
>
> Index: ELF/OutputSections.cpp
> ===================================================================
> --- ELF/OutputSections.cpp
> +++ ELF/OutputSections.cpp
> @@ -538,7 +538,7 @@
>  static SectionKey<ELFT::Is64Bits> createKey(InputSectionBase<ELFT> *C,
>                                              StringRef OutsecName) {
>    typedef typename ELFT::uint uintX_t;
> -  uintX_t Flags = getOutFlags(C);
> +  uintX_t Flags = getOutFlags(C) & ~SHF_WRITE;
>  
>    // For SHF_MERGE we create different output sections for each alignment.
>    // This makes each output section simple and keeps a single level mapping from
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list