-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLD] [MinGW] Implement --dependent-load-flag option #113814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-lld Author: Mateusz Mikuła (mati865) ChangesImplement MSVC's There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment) Full diff: https://github.com/llvm/llvm-project/pull/113814.diff 3 Files Affected:
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 553698d4f537fc..b65840e57755e1 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -398,6 +398,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 ff7e21fa808f39..a1a4a581ed8bc1 100644
--- a/lld/MinGW/Options.td
+++ b/lld/MinGW/Options.td
@@ -61,6 +61,7 @@ defm demangle: B<"demangle",
"Do not demangle symbol names">;
def disable_auto_import: F<"disable-auto-import">,
HelpText<"Don't automatically import data symbols from other DLLs without dllimport">;
+defm dependent_load_flag: EEq<"dependent-load-flag", "Override default LibraryLoad flags">;
def disable_runtime_pseudo_reloc: F<"disable-runtime-pseudo-reloc">,
HelpText<"Don't do automatic imports that require runtime fixups">;
def disable_stdcall_fixup: F<"disable-stdcall-fixup">,
diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test
index 2831d155fef128..c2aceebde7432e 100644
--- a/lld/test/MinGW/driver.test
+++ b/lld/test/MinGW/driver.test
@@ -455,3 +455,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
|
76d330c
to
10fbd99
Compare
Cc @mstorsjo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable, thanks! Let's hope that binutils can align on the name and behaviour of the flag, if they also get to implementing this.
And as high level view of what it does - this sets one value in the _load_config_used
struct, if such a symbol happens to be found at link time, right?
10fbd99
to
1a63495
Compare
Yeah, that's how I understand it. Which means it has an effect only when using Control Flow Guard is enabled. |
Hmm, but isn't So with that, |
IIUC static libraries won't even contain that symbol, and in this case it should be provided only by mingw-w64. I think this example backs up my point:
Only two static libraries from my whole installation of CLANG64 env in MSYS2 contain |
For mingw-w64, at least for now But if there is a new reason to require the load config directory, then we need to change how It may also be beneficial to add a check in LLD to emit a warning if |
I don't see how that contradicts what I'm saying :-) As long as Case in point:
(This tested with llvm-mingw, but I presume it would behave the same in msys2.)
Ah, right, I forgot about that detail. I presume that this is what @mati865 was referring to?
Yep, this sounds reasonable to me. IIRC ARM64EC stuff also requires the load config.
That sounds like a very good addition here! |
Due to the late hour, I forgot to write one more thing: it would be useful to distinguish "typical" static libraries from CRT ones.
As if any static libraries were allowed to provide it.
Yeah, I meant to say the typical static libraries should never contain that symbol, and mingw-w64 libs provide it only when CFG is enabled. |
Well I don't see a reason why they can't be allowed to do it? It's surely a nontypical setup, but I guess it could be possible for an advanced app to provide it themselves if they expect to run with toolchains that don't provide it. Anyway, this is all theoretical...
Right, indeed - I had forgot about this detail. So it is available as long as mingw-w64 was built with CFG enabled, even if the user app isn't built with CFG enabled (which was what I referred to); user apps can use Anyway, to sum things up - this patch is fine and I guess there's no unfinished discussion thread that would block merging it - right? @alvinhochun's great suggestion about warning if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As if any static libraries were allowed to provide it.
Well I don't see a reason why they can't be allowed to do it? It's surely a nontypical setup, but I guess it could be possible for an advanced app to provide it themselves if they expect to run with toolchains that don't provide it.
Users can supply their own _load_config_used
symbol. Even when using MSVC it is sometimes (rarely) done to customize certain fields in the load config dir. For mingw-w64 users, if they urgently need to have DependentLoadFlag set they can build their own loadcfg.o
and link it. Though it would be a bad move for an unrelated 3rd-party library to supply it, because it would override the default _load_config_used
from the CRT (if there is one) without the user asking for it.
A user-supplied _load_config_used
may get outdated and miss fields, so it may be better to change the fields afterwards using some PE editing tools instead. But I digress.
Anyway, to sum things up - this patch is fine and I guess there's no unfinished discussion thread that would block merging it - right?
@alvinhochun's great suggestion about warning if
-dependentloadflag:
is used without a load config being available, can be done by either of us as a separate later step.
Yeah, LGTM (with one minor inline comment). Though it doesn't seem like there is an urgent need for it to be in main right now, so I feel maybe it is beneficial to wait until a PR to add the warning is ready, so both changes can be merged together. Wdyt?
lld/MinGW/Options.td
Outdated
@@ -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)">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should exclude the formatting change from the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed an NFC commit to clean this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this change is still here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would go away with a rebase, let’s try to do that.
No strong opinion either way. On the other hand, even if we don't have all the nice convenience in place, it might be nice to get the option merged to align other parties around it (binutils, and users)? |
Opened #117400 for the warning. |
With #117400 in place, I guess we're good to go to merge this now as well? |
Yes, my LGTM with comment still stands. (I see the commit has been marked with some failed checks but they look unrelated to this PR.) |
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: msys2/MINGW-packages#22216 (comment)
1a63495
to
58cbfb0
Compare
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: msys2/MINGW-packages#22216 (comment)