[PATCH] D30080: MC/COFF: Do not emit forward associative section referenceds.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 17 10:06:00 PST 2017


> +// Write the section header.
> +void WinCOFFObjectWriter::writeSectionHeaders() {
> +  // Section numbers must be monotonically increasing in the section
> +  // header, but our Sections array is not sorted by section number,
> +  // so make a copy of Sections and sort it.
> +  std::vector<COFFSection *> Arr;
> +  for (auto &Section : Sections)
> +    Arr.push_back(Section.get());

Can you say just  std::vector<COFFSection *> Arr = Sections; ?


>  void WinCOFFObjectWriter::assignSectionNumbers() {
>    size_t I = 1;
> -  for (const auto &Section : Sections) {
> -    Section->Number = I;
> -    Section->Symbol->Data.SectionNumber = I;
> -    Section->Symbol->Aux[0].Aux.SectionDefinition.Number = I;
> +  auto Assign = [&](COFFSection &Section) {
> +    Section.Number = I;
> +    Section.Symbol->Data.SectionNumber = I;
> +    Section.Symbol->Aux[0].Aux.SectionDefinition.Number = I;
>      ++I;
> -  }
> +  };
> +
> +  // Although it is not explicitly requested by the Microsoft COFF spec,
> +  // we should avoid emitting forward associative section references,
> +  // because MSVC link.exe as of 2017 cannot handle that.
> +  for (const std::unique_ptr<COFFSection> &Section : Sections)
> +    if (!isAssociative(*Section))
> +      Assign(*Section);
> +  for (const std::unique_ptr<COFFSection> &Section : Sections)
> +    if (isAssociative(*Section))
> +      Assign(*Section);
>  }

An associative section cannot refer to another?

Cheers,
Rafeal


More information about the llvm-commits mailing list