Index: ELF/OutputSections.h =================================================================== --- ELF/OutputSections.h +++ ELF/OutputSections.h @@ -102,6 +102,7 @@ if (Alignment > Header.sh_addralign) Header.sh_addralign = Alignment; } + void updateFlags(InputSectionBase *C); // If true, this section will be page aligned on disk. // Typically the first section of each PT_LOAD segment has this flag. Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -56,6 +56,12 @@ } template +void OutputSectionBase::updateFlags(InputSectionBase *C) { + this->Header.sh_flags |= + C->getSectionHdr()->sh_flags & (SHF_EXECINSTR | SHF_WRITE); +} + +template GotPltSection::GotPltSection() : OutputSectionBase(".got.plt", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE) { this->Header.sh_addralign = Target->GotPltEntrySize; @@ -894,6 +900,7 @@ Sections.push_back(S); S->OutSec = this; this->updateAlignment(S->Alignment); + this->updateFlags(C); } // If an input string is in the form of "foo.N" where N is a number, @@ -1252,6 +1259,7 @@ auto *Sec = cast>(C); Sec->OutSec = this; this->updateAlignment(Sec->Alignment); + this->updateFlags(C); this->Header.sh_entsize = Sec->getSectionHdr()->sh_entsize; Sections.push_back(Sec); @@ -1868,7 +1876,8 @@ OutputSectionFactory::createKey(InputSectionBase *C, StringRef OutsecName) { const Elf_Shdr *H = C->getSectionHdr(); - uintX_t Flags = H->sh_flags & ~SHF_GROUP & ~SHF_COMPRESSED; + uintX_t Flags = + H->sh_flags & ~(SHF_GROUP | SHF_COMPRESSED | SHF_EXECINSTR | 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: test/ELF/linkerscript/repsection-va.s =================================================================== --- test/ELF/linkerscript/repsection-va.s +++ test/ELF/linkerscript/repsection-va.s @@ -7,9 +7,8 @@ # CHECK: Sections: # CHECK-NEXT: Idx Name Size Address Type # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .foo 00000004 0000000000000158 DATA -# CHECK-NEXT: 2 .foo 00000004 000000000000015c DATA -# CHECK-NEXT: 3 .text 00000001 0000000000000160 TEXT DATA +# CHECK-NEXT: 1 .foo 00000008 0000000000000158 DATA +# CHECK-NEXT: 2 .text 00000001 0000000000000160 TEXT DATA .global _start _start: