[lld] r352928 - [COFF] Fix crashes when writing a PDB after adding thunks.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 5 03:15:10 PST 2019


Merged to 8.0 in r353157.

On Fri, Feb 1, 2019 at 11:07 PM Martin Storsjo via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Author: mstorsjo
> Date: Fri Feb  1 14:08:03 2019
> New Revision: 352928
>
> URL: http://llvm.org/viewvc/llvm-project?rev=352928&view=rev
> Log:
> [COFF] Fix crashes when writing a PDB after adding thunks.
>
> When writing a PDB, the OutputSection of all chunks need to be set.
> The thunks are added directly to OutputSection after the normal
> machinery that sets it for all other chunks.
>
> This fixes part of PR40467.
>
> Differential Revision: https://reviews.llvm.org/D57574
>
> Added:
>     lld/trunk/test/COFF/arm-thumb-thunks-pdb.s
> Modified:
>     lld/trunk/COFF/Writer.cpp
>
> Modified: lld/trunk/COFF/Writer.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=352928&r1=352927&r2=352928&view=diff
> ==============================================================================
> --- lld/trunk/COFF/Writer.cpp (original)
> +++ lld/trunk/COFF/Writer.cpp Fri Feb  1 14:08:03 2019
> @@ -373,14 +373,14 @@ getThunk(DenseMap<uint64_t, Defined *> &
>  // After adding thunks, we verify that all relocations are in range (with
>  // no extra margin requirements). If this failed, we restart (throwing away
>  // the previously created thunks) and retry with a wider margin.
> -static bool createThunks(std::vector<Chunk *> &Chunks, int Margin) {
> +static bool createThunks(OutputSection *OS, int Margin) {
>    bool AddressesChanged = false;
>    DenseMap<uint64_t, Defined *> LastThunks;
>    size_t ThunksSize = 0;
>    // Recheck Chunks.size() each iteration, since we can insert more
>    // elements into it.
> -  for (size_t I = 0; I != Chunks.size(); ++I) {
> -    SectionChunk *SC = dyn_cast_or_null<SectionChunk>(Chunks[I]);
> +  for (size_t I = 0; I != OS->Chunks.size(); ++I) {
> +    SectionChunk *SC = dyn_cast_or_null<SectionChunk>(OS->Chunks[I]);
>      if (!SC)
>        continue;
>      size_t ThunkInsertionSpot = I + 1;
> @@ -417,7 +417,8 @@ static bool createThunks(std::vector<Chu
>          Chunk *ThunkChunk = Thunk->getChunk();
>          ThunkChunk->setRVA(
>              ThunkInsertionRVA); // Estimate of where it will be located.
> -        Chunks.insert(Chunks.begin() + ThunkInsertionSpot, ThunkChunk);
> +        ThunkChunk->setOutputSection(OS);
> +        OS->Chunks.insert(OS->Chunks.begin() + ThunkInsertionSpot, ThunkChunk);
>          ThunkInsertionSpot++;
>          ThunksSize += ThunkChunk->getSize();
>          ThunkInsertionRVA += ThunkChunk->getSize();
> @@ -506,7 +507,7 @@ void Writer::finalizeAddresses() {
>      // to avoid things going out of range due to the added thunks.
>      bool AddressesChanged = false;
>      for (OutputSection *Sec : OutputSections)
> -      AddressesChanged |= createThunks(Sec->Chunks, Margin);
> +      AddressesChanged |= createThunks(Sec, Margin);
>      // If the verification above thought we needed thunks, we should have
>      // added some.
>      assert(AddressesChanged);
>
> Added: lld/trunk/test/COFF/arm-thumb-thunks-pdb.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/arm-thumb-thunks-pdb.s?rev=352928&view=auto
> ==============================================================================
> --- lld/trunk/test/COFF/arm-thumb-thunks-pdb.s (added)
> +++ lld/trunk/test/COFF/arm-thumb-thunks-pdb.s Fri Feb  1 14:08:03 2019
> @@ -0,0 +1,18 @@
> +// REQUIRES: arm
> +// RUN: llvm-mc -filetype=obj -triple=thumbv7-windows %s -o %t.obj
> +// RUN: lld-link -entry:main -subsystem:console %t.obj -out:%t.exe -debug -pdb:%t.pdb -verbose 2>&1 | FileCheck %s --check-prefix=VERBOSE
> +
> +// VERBOSE: Added 1 thunks with margin {{.*}} in {{.*}} passes
> +
> +    .syntax unified
> +    .globl main
> +    .globl func1
> +    .text
> +main:
> +    bne func1
> +    bx lr
> +    .section .text$a, "xr"
> +    .space 0x100000
> +    .section .text$b, "xr"
> +func1:
> +    bx lr
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list