[PATCH] D37735: [ELF] - Remove one of OutputSectionFactory::addInputSec().

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 13:15:06 PDT 2017


This LGTM with Rui's suggestion of having the helper return a value.

Cheers,
Rafael


Rui Ueyama via Phabricator <reviews at reviews.llvm.org> writes:

> ruiu added inline comments.
>
>
> ================
> Comment at: ELF/OutputSections.cpp:208-209
>  
> -void OutputSectionFactory::addInputSec(InputSectionBase *IS,
> -                                       StringRef OutsecName) {
> -  // Sections with the SHT_GROUP attribute reach here only when the - r option
> -  // is given. Such sections define "section groups", and InputFiles.cpp has
> -  // dedup'ed section groups by their signatures. For the -r, we want to pass
> -  // through all SHT_GROUP sections without merging them because merging them
> -  // creates broken section contents.
> -  if (IS->Type == SHT_GROUP) {
> -    OutputSection *Out = nullptr;
> -    addInputSec(IS, OutsecName, Out);
> -    return;
> -  }
> -
> -  // Imagine .zed : { *(.foo) *(.bar) } script. Both foo and bar may have
> -  // relocation sections .rela.foo and .rela.bar for example. Most tools do
> -  // not allow multiple REL[A] sections for output section. Hence we
> -  // should combine these relocation sections into single output.
> -  // We skip synthetic sections because it can be .rela.dyn/.rela.plt or any
> -  // other REL[A] sections created by linker itself.
> -  if (!isa<SyntheticSection>(IS) &&
> -      (IS->Type == SHT_REL || IS->Type == SHT_RELA)) {
> -    auto *Sec = cast<InputSection>(IS);
> -    OutputSection *Out = Sec->getRelocatedSection()->getOutputSection();
> -    addInputSec(IS, OutsecName, Out->RelocationSection);
> -    return;
> -  }
> -
> -  SectionKey Key = createKey(IS, OutsecName);
> -  OutputSection *&Sec = Map[Key];
> -  addInputSec(IS, OutsecName, Sec);
> -}
> -
> -void OutputSectionFactory::addInputSec(InputSectionBase *IS,
> -                                       StringRef OutsecName,
> -                                       OutputSection *&Sec) {
> -  if (!IS->Live) {
> -    reportDiscarded(IS);
> -    return;
> -  }
> -
> +static void addSection(InputSectionBase *IS, StringRef OutsecName,
> +                       OutputSection *&Sec) {
>    if (Sec && Sec->Live) {
> ----------------
> Instead of mutating a given pointer through a reference, this function should take `OutputSection *` and returns `OutputSection *`.
>
>
> https://reviews.llvm.org/D37735


More information about the llvm-commits mailing list