[lld] [LLD][COFF] Support /DEPENDENTLOADFLAGS[:flags] (PR #71537)
Aleksei Nurmukhametov via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 7 09:19:12 PST 2023
================
@@ -2256,6 +2262,32 @@ void Writer::fixTlsAlignment() {
}
}
+void Writer::changeLoadConfig() {
+ Symbol *sym = ctx.symtab.findUnderscore("_load_config_used");
+ auto *b = cast_if_present<DefinedRegular>(sym);
+ if (!b) {
+ if (ctx.config.guardCF != GuardCFLevel::Off)
+ warn("Control Flow Guard is enabled but '_load_config_used' is missing");
+ return;
+ }
+
+ OutputSection *sec = ctx.getOutputSection(b->getChunk());
+ uint8_t *buf = buffer->getBufferStart();
+ uint8_t *secBuf = buf + sec->getFileOff();
+ uint8_t *symBuf = secBuf + (b->getRVA() - sec->getRVA());
+ if (ctx.config.is64())
+ changeLoadConfigGuardData(
+ reinterpret_cast<coff_load_configuration64 *>(symBuf));
+ else
+ changeLoadConfigGuardData(
+ reinterpret_cast<coff_load_configuration32 *>(symBuf));
+}
+
+template <typename T> void Writer::changeLoadConfigGuardData(T *loadConfig) {
+ if (ctx.config.dependentLoadFlags)
+ loadConfig->DependentLoadFlags = ctx.config.dependentLoadFlags;
----------------
nurmukhametov wrote:
Yes, although it looks like that the higher part of DWORD is not used at the moment ([link](https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters)).
https://github.com/llvm/llvm-project/pull/71537
More information about the llvm-commits
mailing list