[PATCH] D51288: [MinGW] [X86] Add stubs for references to data variables that might end up imported from a dll

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 27 01:56:18 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: rnk, pcc.
Herald added a reviewer: javed.absar.
Herald added a subscriber: kristof.beyls.

Variables declared with the dllimport attribute are accessed via a stub variable named __imp_<var>. In MinGW configurations,  variables that aren't declared with a dllimport attribute might still end up imported from another DLL with runtime pseudo relocs.

For x86_64, this avoids the risk that the target is out of range for a 32 bit PC relative reference, in case the target DLL is loaded further than 4 GB from the reference. It also avoids having to make the text section writable at runtime when doing the runtime fixups, which makes it worthwhile to do for i386 as well.

Add stub variables for all dso local data references where a definition of the variable isn't visible within the module, since the DLL data autoimporting might make them imported even though they are marked as dso local within LLVM.

Don't do this for variables that actually are defined within the same module, since we then know for sure that it actually is dso local.

Don't do this for references to functions, since there's no need for runtime pseudo relocations for autoimporting them; if a function from a different DLL is called without the appropriate dllimport attribute, the call just gets routed via a thunk instead.

GCC does something similar since 4.9 (when compiling with -mcmodel=medium or large; from that version, medium is the default code model for x86_64 mingw), but only for x86_64.

This patch both adds the generic support for COFF pointer stubs, and implements it for X86. Later patches implements the same for ARM and AArch64.


Repository:
  rL LLVM

https://reviews.llvm.org/D51288

Files:
  include/llvm/CodeGen/MachineModuleInfoImpls.h
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  lib/CodeGen/MachineModuleInfoImpls.cpp
  lib/Target/X86/MCTargetDesc/X86BaseInfo.h
  lib/Target/X86/X86AsmPrinter.cpp
  lib/Target/X86/X86InstrInfo.cpp
  lib/Target/X86/X86InstrInfo.h
  lib/Target/X86/X86MCInstLower.cpp
  lib/Target/X86/X86Subtarget.cpp
  test/CodeGen/X86/br-fold.ll
  test/CodeGen/X86/mingw-refptr.ll
  test/CodeGen/X86/stack-protector.ll
  test/CodeGen/X86/win32-ssp.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51288.162637.patch
Type: text/x-patch
Size: 16676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180827/f90c2896/attachment.bin>


More information about the llvm-commits mailing list