[lld] [LLD] [MinGW] Implement --dependent-load-flag option (PR #113814)

Mateusz MikuĊ‚a via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 10:40:45 PST 2024


https://github.com/mati865 updated https://github.com/llvm/llvm-project/pull/113814

>From 1a63495b768554f7a202d7182d3c8111061e56bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= <mati865 at gmail.com>
Date: Sun, 27 Oct 2024 14:47:04 +0100
Subject: [PATCH] [LLD] [MinGW] Implement --dependent-load-flag option

Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and
forward it to COFF.
I'm not sure about the name as ld.bfd doesn't support it (yet?).

There is no solid need for it yet, but it's being considered: https://github.com/msys2/MINGW-packages/pull/22216#issuecomment-2428417546
---
 lld/MinGW/Driver.cpp       | 3 +++
 lld/MinGW/Options.td       | 3 ++-
 lld/test/MinGW/driver.test | 3 +++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 72d612ceed2259..b4371b5b2240d2 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -407,6 +407,9 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
                    OPT_no_allow_multiple_definition, false))
     add("-force:multiple");
 
+  if (auto *a = args.getLastArg(OPT_dependent_load_flag))
+    add("-dependentloadflag:" + StringRef(a->getValue()));
+
   if (auto *a = args.getLastArg(OPT_icf)) {
     StringRef s = a->getValue();
     if (s == "all")
diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td
index abe5e5c82ca3ff..01b01972112a1a 100644
--- a/lld/MinGW/Options.td
+++ b/lld/MinGW/Options.td
@@ -202,6 +202,7 @@ def _HASH_HASH_HASH : Flag<["-"], "###">,
     HelpText<"Print (but do not run) the commands to run for this compilation">;
 def appcontainer: F<"appcontainer">, HelpText<"Set the appcontainer flag in the executable">;
 defm delayload: Eq<"delayload", "DLL to load only on demand">;
+defm dependent_load_flag: EEq<"dependent-load-flag", "Override default LibraryLoad flags">;
 defm mllvm: EqNoHelp<"mllvm">;
 defm pdb: Eq<"pdb", "Output PDB debug info file, chosen implicitly if the argument is empty">;
 defm Xlink : Eq<"Xlink", "Pass <arg> to the COFF linker">, MetaVarName<"<arg>">;
@@ -212,7 +213,7 @@ defm guard_longjmp : B<"guard-longjmp",
   "Do not enable Control Flow Guard long jump hardening">;
 defm error_limit:
   EqLong<"error-limit", "Maximum number of errors to emit before stopping (0 = no limit)">;
-def build_id: J<"build-id=">, HelpText<"Generate build ID note (pass none to disable)">, 
+def build_id: J<"build-id=">, HelpText<"Generate build ID note (pass none to disable)">,
   MetaVarName<"<arg>">;
 def : F<"build-id">, Alias<build_id>, HelpText<"Alias for --build-id=">;
 def functionpadmin: J<"functionpadmin=">, HelpText<"Prepares an image for hotpatching">,
diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test
index ed6bc880f8f2d9..907d2d87dda5cd 100644
--- a/lld/test/MinGW/driver.test
+++ b/lld/test/MinGW/driver.test
@@ -462,3 +462,6 @@ RUN: ld.lld -### foo.o -m i386pep --rpath foo 2>&1 | FileCheck -check-prefix=WAR
 RUN: ld.lld -### foo.o -m i386pep -rpath=foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
 RUN: ld.lld -### foo.o -m i386pep --rpath=foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
 WARN_RPATH: warning: parameter -{{-?}}rpath has no effect on PE/COFF targets
+
+RUN: ld.lld -### foo.o -m i386pe --dependent-load-flag=0x800 2>&1 | FileCheck -check-prefix=DEPENDENT_LOAD_FLAG %s
+DEPENDENT_LOAD_FLAG: -dependentloadflag:0x800



More information about the llvm-commits mailing list