[PATCH] D40364: [ELF] Skip over empty sections when checking for contiguous relro

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 22 14:41:46 PST 2017


Peter Smith via Phabricator <reviews at reviews.llvm.org> writes:

> +// RUN: echo "SECTIONS { \
> +// RUN: .ctors : { *(.ctors) } \
> +// RUN: .large1 : { *(.large1) } \
> +// RUN: .dynamic : { *(.dynamic) } \
> +// RUN: .zero_size : { *(.zero_size) } \
> +// RUN: .jcr : { *(.jcr) } \
> +// RUN: .got.plt : { *(.got.plt) } \
> +// RUN: .large2 : { *(.large2) } \
> +// RUN: .data.rel.ro : { *(.data.rel.ro.*) ; . =  ALIGN(1); } \

Why only the last one needs ". = ALIGN(1);"?

> Index: ELF/Writer.cpp
> ===================================================================
> --- ELF/Writer.cpp
> +++ ELF/Writer.cpp
> @@ -1452,6 +1452,22 @@
>    return Flags;
>  }
>  
> +// Prior to finalizeContents() an OutputSection containing SyntheticSections
> +// may have 0 Size, but contain SyntheticSections that haven't had their size
> +// calculated yet. We must use SyntheticSection->empty() for these sections.
> +static bool isOutputSectionZeroSize(const OutputSection* Sec) {
> +  if (Sec->Size > 0)
> +    return false;
> +  for (BaseCommand *BC : Sec->SectionCommands) {
> +    if (auto *ISD = dyn_cast<InputSectionDescription>(BC))
> +      for (InputSection *IS : ISD->Sections)
> +        if (SyntheticSection *SS = dyn_cast<SyntheticSection>(IS))
> +          if (!SS->empty())
> +            return false;
> +    }
> +  return true;
> +}

This is unfortunate, but it is probably better to get the fix in with a
localized patch and try to improve it afterwards.

LGTM.

Cheers,
Rafael


More information about the llvm-commits mailing list