[PATCH] D60081: [COFF] Fix delay import directory iterator

Joseph Tremoulet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 2 08:08:21 PDT 2019


JosephTremoulet added a comment.

In D60081#1450958 <https://reviews.llvm.org/D60081#1450958>, @ruiu wrote:

> Can you tell me how to reproduce the issue? Maybe that's a good start to think about how to write a test.


Sure, sorry.

1: Create a PE file with delay-load references to two DLLs:

  >type Alpha.c
  __declspec(dllexport) void one() {}
  __declspec(dllexport) void two() {}
  
  >type Beta.c
  __declspec(dllexport) void left() { }
  __declspec(dllexport) void right() { }
  
  >type Root.c
  __declspec(dllimport) void one();
  __declspec(dllimport) void two();
  __declspec(dllimport) void left();
  __declspec(dllimport) void right();
  
  int main(int argc, char** argv) {
    one();
    two();
    left();
    right();
    return 0;
  }
  
  >cl /LD Alpha.c & cl /LD Beta.c & cl Root.c Alpha.lib Beta.lib delayimp.lib /link /delayload:Alpha.dll /delayload:Beta.dll



2. Invoke `llvm-readobj --coff-imports` on the exe produced in step 1.



Expected Results:
-----------------

The "Delay Import" parts of the dump have different `ModuleHandle`s, `ImportAddressTable`s, `ImportNameTable`s, and `BoundDelayImportTable`s for the two DLL references

  DelayImport {
    Name: Alpha.dll
    Attributes: 0x1
    ModuleHandle: 0x17A30
    ImportAddressTable: 0x17A00
    ImportNameTable: 0x163B0
    BoundDelayImportTable: 0x16400
    UnloadDelayImportTable: 0x0
    Import {
      Symbol: two (1)
      Address: 0x1400010B1
    }
    Import {
      Symbol: one (0)
      Address: 0x14000102C
    }
  }
  DelayImport {
    Name: Beta.dll
    Attributes: 0x1
    ModuleHandle: 0x17A38
    ImportAddressTable: 0x17A18
    ImportNameTable: 0x163C8
    BoundDelayImportTable: 0x16418
    UnloadDelayImportTable: 0x0
    Import {
      Symbol: right (1)
      Address: 0x140001142
    }
    Import {
      Symbol: left (0)
      Address: 0x1400010BD
    }
  }



Observed Results:
-----------------

The "Delay Import" parts of the dump show the same `ModuleHandle`s, `ImportAddressTable`s, `ImportNameTable`s, and `BoundDelayImportTable`s for the two DLL references (repeating the values that are correct for the first one)

  DelayImport {
    Name: Alpha.dll
    Attributes: 0x1
    ModuleHandle: 0x17A30
    ImportAddressTable: 0x17A00
    ImportNameTable: 0x163B0
    BoundDelayImportTable: 0x16400
    UnloadDelayImportTable: 0x0
    Import {
      Symbol: two (1)
      Address: 0x1400010B1
    }
    Import {
      Symbol: one (0)
      Address: 0x14000102C
    }
  }
  DelayImport {
    Name: Beta.dll
    Attributes: 0x1
    ModuleHandle: 0x17A30
    ImportAddressTable: 0x17A00
    ImportNameTable: 0x163B0
    BoundDelayImportTable: 0x16400
    UnloadDelayImportTable: 0x0
    Import {
      Symbol: right (1)
      Address: 0x140001142
    }
    Import {
      Symbol: left (0)
      Address: 0x1400010BD
    }
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60081/new/

https://reviews.llvm.org/D60081





More information about the llvm-commits mailing list