<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Feb 17, 2017 at 10:06 AM, Rafael Avila de Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> +// Write the section header.<br>
> +void WinCOFFObjectWriter::<wbr>writeSectionHeaders() {<br>
> +  // Section numbers must be monotonically increasing in the section<br>
> +  // header, but our Sections array is not sorted by section number,<br>
> +  // so make a copy of Sections and sort it.<br>
> +  std::vector<COFFSection *> Arr;<br>
> +  for (auto &Section : Sections)<br>
> +    Arr.push_back(Section.get());<br>
<br>
Can you say just  std::vector<COFFSection *> Arr = Sections; ?<br></blockquote><div><br></div><div>Sections is a std::vector<std::unique_ptr<COFFSection>>, so you can't.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
>  void WinCOFFObjectWriter::<wbr>assignSectionNumbers() {<br>
>    size_t I = 1;<br>
> -  for (const auto &Section : Sections) {<br>
> -    Section->Number = I;<br>
> -    Section->Symbol->Data.<wbr>SectionNumber = I;<br>
> -    Section->Symbol->Aux[0].Aux.<wbr>SectionDefinition.Number = I;<br>
> +  auto Assign = [&](COFFSection &Section) {<br>
> +    Section.Number = I;<br>
> +    Section.Symbol->Data.<wbr>SectionNumber = I;<br>
> +    Section.Symbol->Aux[0].Aux.<wbr>SectionDefinition.Number = I;<br>
>      ++I;<br>
> -  }<br>
> +  };<br>
> +<br>
> +  // Although it is not explicitly requested by the Microsoft COFF spec,<br>
> +  // we should avoid emitting forward associative section references,<br>
> +  // because MSVC link.exe as of 2017 cannot handle that.<br>
> +  for (const std::unique_ptr<COFFSection> &Section : Sections)<br>
> +    if (!isAssociative(*Section))<br>
> +      Assign(*Section);<br>
> +  for (const std::unique_ptr<COFFSection> &Section : Sections)<br>
> +    if (isAssociative(*Section))<br>
> +      Assign(*Section);<br>
>  }<br>
<br>
An associative section cannot refer to another?<br></blockquote><div><br></div><div>They can't. </div></div></div></div>