[PATCH] D79934: [RFC] [LLD] [COFF] Support options for enabling/disabling autoimport and pseudo relocs in .drectve sections

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 14 03:42:50 PDT 2020


mstorsjo created this revision.
mstorsjo added reviewers: rnk, ruiu.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is the other bit I split out from D78923 <https://reviews.llvm.org/D78923> as mentioned there. However since I wrote this, I'm less convinced that it's a good idea.

Firstly, it makes the lld private option (used on the lld-link interface - the one on the mingw driver interface is public) essentially public, if projects would be to start embedding it in .drectve sections.

Secondly, placing such an option in an object file is tricky, because it's essentially impossible to override it by linker options, as the linker options are read first and the object file is parsed later, overriding it.

Thirdly, after remembering more of the details about this, it turned out that the full pseudo reloc mechanism should be usable even in restricted UWP mode, as long as VirtualProtect is remapped to VirtualProtectFromApp (which already is done in https://sourceforge.net/p/mingw-w64/mingw-w64/ci/8f078a256769c84a021f5512ba0400f1eb8d0c05/), and as long as all places needing fixup is in data sections. If the executable code is generated with LLVM, it should avoid placing any such references within code sections, but always use .refptr stubs - so then this shouldn't really be an issue.

In any case, posting this for discussion as it was mentioned in D78923 <https://reviews.llvm.org/D78923> - but I'm less convinced about its necessity now. Or what does @jacek think?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79934

Files:
  lld/COFF/Driver.cpp
  lld/test/COFF/autoimport-drectve.s


Index: lld/test/COFF/autoimport-drectve.s
===================================================================
--- /dev/null
+++ lld/test/COFF/autoimport-drectve.s
@@ -0,0 +1,25 @@
+# REQUIRES: x86
+
+# RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.text\nDllMainCRTStartup:\nret\n.data\nvariable:\n.long 42" > %t-lib.s
+# RUN: llvm-mc -triple=x86_64-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
+# RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
+
+# RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t.obj
+# RUN: not lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib 2>&1 | FileCheck %s
+
+## Check that we can disable runtime pseudo relocs via a .drectve in a
+## linked object file:
+##
+# CHECK: error: automatic dllimport of variable in {{.*}}/autoimport-drectve.s.tmp.obj requires pseudo relocations
+
+    .global main
+    .text
+main:
+    movl variable(%rip), %eax
+    ret
+    .data
+ptr:
+    .quad variable
+
+    .section .drectve
+    .ascii "-runtime-pseudo-reloc:no"
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -395,6 +395,18 @@
     case OPT_nodefaultlib:
       config->noDefaultLibs.insert(doFindLib(arg->getValue()).lower());
       break;
+    case OPT_auto_import:
+      config->autoImport = true;
+      break;
+    case OPT_auto_import_no:
+      config->autoImport = false;
+      break;
+    case OPT_runtime_pseudo_reloc:
+      config->pseudoRelocs = true;
+      break;
+    case OPT_runtime_pseudo_reloc_no:
+      config->pseudoRelocs = false;
+      break;
     case OPT_section:
       parseSection(arg->getValue());
       break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79934.263956.patch
Type: text/x-patch
Size: 1761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200514/cb54eb88/attachment.bin>


More information about the llvm-commits mailing list