[lld] [LLD][COFF] Support /DEPENDENTLOADFLAGS[:flags] (PR #71537)

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 08:16:50 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;
----------------
aganea wrote:

Quite interestingly `dependentLoadFlags` is a WORD in the loadconfig, but it’s a DWORD in `LoadLibraryEx`. Nothing to do here, this is just a remark.

https://github.com/llvm/llvm-project/pull/71537


More information about the llvm-commits mailing list