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

Mark Kettenis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 20 07:27:39 PST 2016


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27988.82093.patch
Type: text/x-patch
Size: 596 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161220/0420325f/attachment.bin>


More information about the llvm-commits mailing list