[PATCH] D40070: [ELF] - Don't emit broken relocations for SHF_MERGE sections when --emit-relocs is used.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 10:05:59 PST 2017


George Rimar via Phabricator <reviews at reviews.llvm.org> writes:

> Index: ELF/Writer.cpp
> ===================================================================
> --- ELF/Writer.cpp
> +++ ELF/Writer.cpp
> @@ -487,8 +487,17 @@
>      if (I == Sec->SectionCommands.end())
>        continue;
>      InputSection *IS = cast<InputSectionDescription>(*I)->Sections[0];
> -    if (isa<SyntheticSection>(IS) || IS->Type == SHT_REL ||
> -        IS->Type == SHT_RELA)
> +
> +    // Relocations are not using REL[A] section symbols.
> +    if (IS->Type == SHT_REL || IS->Type == SHT_RELA)
> +      continue;
> +
> +    // We do not create symbol for synthetic sections because do not have
> +    // relocations that might use it, but SHF_MERGE sections is an exception
> +    // used for -r. After applying merging optimisation we want to rewrite
> +    // relocations and need section symbol for synthetic mergeable sections to
> +    // refer to.
> +    if (isa<SyntheticSection>(IS) && !(IS->Flags & SHF_MERGE))
>        continue;

Not just for -r.

>      auto *Sym = make<Defined>("", /*IsLocal=*/true, /*StOther=*/0, STT_SECTION,
> Index: ELF/InputSection.cpp
> ===================================================================
> --- ELF/InputSection.cpp
> +++ ELF/InputSection.cpp
> @@ -411,7 +411,8 @@
>        }
>  
>        if (Config->IsRela) {
> -        P->r_addend += Sym.getVA() - Section->getOutputSection()->Addr;
> +        P->r_addend =
> +            Sym.getVA(getAddend<ELFT>(Rel)) - Section->getOutputSection()->Addr;
>        } else if (Config->Relocatable) {
>          const uint8_t *BufLoc = Sec->Data.begin() + Rel.r_offset;
>          Sec->Relocations.push_back({R_ABS, Type, Rel.r_offset,

LGTM

Thanks,
Rafael


More information about the llvm-commits mailing list