[lld] r270346 - Simplify SplitInputSection::getRangeAndSize.

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Tue May 24 03:10:44 PDT 2016


Hi,

On Sun, May 22, 2016 at 3:41 AM, Rui Ueyama via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: ruiu
> Date: Sat May 21 19:41:38 2016
> New Revision: 270346
>
> URL: http://llvm.org/viewvc/llvm-project?rev=270346&view=rev
> Log:
> Simplify SplitInputSection::getRangeAndSize.
>
> This patch adds Size member to SectionPiece so that getRangeAndSize
> can just return a SectionPiece instead of a std::pair<SectionPiece *, uint_t>.
> Also renamed the function.

[...]

> --- lld/trunk/ELF/OutputSections.cpp (original)
> +++ lld/trunk/ELF/OutputSections.cpp Sat May 21 19:41:38 2016
> @@ -1142,9 +1142,6 @@ void EHOutputSection<ELFT>::addSectionAu
>
>    DenseMap<uintX_t, uintX_t> OffsetToIndex;
>    while (!D.empty()) {
> -    unsigned Index = Sec->Pieces.size();
> -    Sec->Pieces.emplace_back(Offset);
> -
>      uintX_t Length = readEntryLength<ELFT>(D);
>      // If CIE/FDE data length is zero then Length is 4, this
>      // shall be considered a terminator and processing shall end.
> @@ -1152,6 +1149,9 @@ void EHOutputSection<ELFT>::addSectionAu
>        break;
>      StringRef Entry((const char *)D.data(), Length);
>
> +    unsigned Index = Sec->Pieces.size();
> +    Sec->Pieces.emplace_back(Offset, Length);
> +
>      uint32_t ID = read32<E>(D.data() + 4);
>      if (ID == 0) {
>        // CIE

Before this commit if .eh_frame section contains only 4-byte
terminator, we added single entry into the Pieces. Now in that case
the Pieces is empty. But it is possible to have a symbol points to
this .eh_frame section. In that case Section->getOffset(Body) call for
such symbol is crashed in the EhInputSection<ELFT>::getOffset()
because SplitInputSection<ELFT>::getSectionPiece() returns trash.

On my machine it prevents to link "Hello World":
[[
% ld.lld --hash-style=both --build-id --eh-frame-hdr -m elf_x86_64
-dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/4.7/crtbegin.o
-L/usr/lib/gcc/x86_64-linux-gnu/4.7
-L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu
-L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../..
-L/home/simon/work/llvm/bld/bin/../lib -L/lib -L/usr/lib main.o -lgcc
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.7/crtend.o
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crtn.o

% objdump -st /usr/lib/gcc/x86_64-linux-gnu/4.7/crtend.o
...

0000000000000000 l    d  .eh_frame      0000000000000000 .eh_frame
0000000000000000 l     O .eh_frame      0000000000000000 __FRAME_END__

...

Contents of section .eh_frame:
 0000 00000000                             ....
]]

-- 
Simon Atanasyan


More information about the llvm-commits mailing list