<div dir="ltr">So it is a special case that .eh_frame contains only the terminator (empty) record and there is a relocation pointing to offset 0 of .eh_frame, correct?</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 24, 2016 at 3:10 AM, Simon Atanasyan <span dir="ltr"><<a href="mailto:simon@atanasyan.com" target="_blank">simon@atanasyan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<span class=""><br>
On Sun, May 22, 2016 at 3:41 AM, Rui Ueyama via llvm-commits<br>
<<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Author: ruiu<br>
> Date: Sat May 21 19:41:38 2016<br>
> New Revision: 270346<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=270346&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=270346&view=rev</a><br>
> Log:<br>
> Simplify SplitInputSection::getRangeAndSize.<br>
><br>
> This patch adds Size member to SectionPiece so that getRangeAndSize<br>
> can just return a SectionPiece instead of a std::pair<SectionPiece *, uint_t>.<br>
> Also renamed the function.<br>
<br>
</span>[...]<br>
<span class=""><br>
> --- lld/trunk/ELF/OutputSections.cpp (original)<br>
> +++ lld/trunk/ELF/OutputSections.cpp Sat May 21 19:41:38 2016<br>
> @@ -1142,9 +1142,6 @@ void EHOutputSection<ELFT>::addSectionAu<br>
><br>
>    DenseMap<uintX_t, uintX_t> OffsetToIndex;<br>
>    while (!D.empty()) {<br>
> -    unsigned Index = Sec->Pieces.size();<br>
> -    Sec->Pieces.emplace_back(Offset);<br>
> -<br>
>      uintX_t Length = readEntryLength<ELFT>(D);<br>
>      // If CIE/FDE data length is zero then Length is 4, this<br>
>      // shall be considered a terminator and processing shall end.<br>
> @@ -1152,6 +1149,9 @@ void EHOutputSection<ELFT>::addSectionAu<br>
>        break;<br>
>      StringRef Entry((const char *)D.data(), Length);<br>
><br>
> +    unsigned Index = Sec->Pieces.size();<br>
> +    Sec->Pieces.emplace_back(Offset, Length);<br>
> +<br>
>      uint32_t ID = read32<E>(D.data() + 4);<br>
>      if (ID == 0) {<br>
>        // CIE<br>
<br>
</span>Before this commit if .eh_frame section contains only 4-byte<br>
terminator, we added single entry into the Pieces. Now in that case<br>
the Pieces is empty. But it is possible to have a symbol points to<br>
this .eh_frame section. In that case Section->getOffset(Body) call for<br>
such symbol is crashed in the EhInputSection<ELFT>::getOffset()<br>
because SplitInputSection<ELFT>::getSectionPiece() returns trash.<br>
<br>
On my machine it prevents to link "Hello World":<br>
[[<br>
% ld.lld --hash-style=both --build-id --eh-frame-hdr -m elf_x86_64<br>
-dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out<br>
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o<br>
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o<br>
/usr/lib/gcc/x86_64-linux-gnu/4.7/crtbegin.o<br>
-L/usr/lib/gcc/x86_64-linux-gnu/4.7<br>
-L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu<br>
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu<br>
-L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../..<br>
-L/home/simon/work/llvm/bld/bin/../lib -L/lib -L/usr/lib main.o -lgcc<br>
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s<br>
--no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.7/crtend.o<br>
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crtn.o<br>
<br>
% objdump -st /usr/lib/gcc/x86_64-linux-gnu/4.7/crtend.o<br>
...<br>
<br>
0000000000000000 l    d  .eh_frame      0000000000000000 .eh_frame<br>
0000000000000000 l     O .eh_frame      0000000000000000 __FRAME_END__<br>
<br>
...<br>
<br>
Contents of section .eh_frame:<br>
 0000 00000000                             ....<br>
]]<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Simon Atanasyan<br>
</font></span></blockquote></div><br></div>