Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -1191,10 +1191,13 @@ static void findKeepUniqueSections(opt::InputArgList &Args) { for (auto *Arg : Args.filtered(OPT_keep_unique)) { StringRef Name = Arg->getValue(); - if (auto *Sym = dyn_cast_or_null(Symtab->find(Name))) - Sym->Section->KeepUnique = true; - else - warn("could not find symbol " + Name + " to keep unique"); + if (auto *Sym = dyn_cast_or_null(Symtab->find(Name))) { + if (auto *Sec = dyn_cast(Sym->Section)) { + Sec->KeepUnique = true; + continue; + } + } + warn("could not find symbol " + Name + " to keep unique"); } } Index: ELF/InputSection.h =================================================================== --- ELF/InputSection.h +++ ELF/InputSection.h @@ -52,18 +52,14 @@ unsigned SectionKind : 3; - // The next two bit fields are only used by InputSectionBase, but we - // put them here so the struct packs better. - - // The garbage collector sets sections' Live bits. + // The garbage collector sets the input sections' Live bits. // If GC is disabled, all sections are considered live by default. + // Output sections are live if they they have any input sections added to + // them. unsigned Live : 1; unsigned Bss : 1; - // Set for sections that should not be folded by ICF. - unsigned KeepUnique : 1; - // These corresponds to the fields in Elf_Shdr. uint32_t Alignment; uint64_t Flags; @@ -88,7 +84,7 @@ uint64_t Entsize, uint64_t Alignment, uint32_t Type, uint32_t Info, uint32_t Link) : Name(Name), Repl(this), SectionKind(SectionKind), Live(false), - Bss(false), KeepUnique(false), Alignment(Alignment), Flags(Flags), + Bss(false), Alignment(Alignment), Flags(Flags), Entsize(Entsize), Type(Type), Link(Link), Info(Info) {} }; @@ -129,7 +125,10 @@ // .foo takes all .text sections, and .bar becomes empty. To achieve // this, we need to memorize whether a section has been placed or // not for each input section. - bool Assigned = false; + unsigned Assigned : 1; + + // Set for sections that should not be folded by ICF. + unsigned KeepUnique : 1; // Input sections are part of an output section. Special sections // like .eh_frame and merge sections are first combined into a Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -60,7 +60,7 @@ StringRef Name, Kind SectionKind) : SectionBase(SectionKind, Name, Flags, Entsize, Alignment, Type, Info, Link), - File(File), Data(Data) { + File(File), Data(Data), Assigned(false), KeepUnique(false) { // In order to reduce memory allocation, we assume that mergeable // sections are smaller than 4 GiB, which is not an unreasonable // assumption as of 2017.