[PATCH] D150508: [LLD] Do not assume /guard:cf always set together with /guard:ehcont

Phoebe Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 13 03:58:27 PDT 2023


pengfei created this revision.
pengfei added reviewers: rnk, jhenderson, ruiu.
Herald added a project: All.
pengfei requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

MS link accepts *.obj with ehcont bit set only. LLD should match this
behavoir too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150508

Files:
  lld/COFF/InputFiles.h
  lld/COFF/Writer.cpp
  lld/test/COFF/guard-ehcont.s


Index: lld/test/COFF/guard-ehcont.s
===================================================================
--- lld/test/COFF/guard-ehcont.s
+++ lld/test/COFF/guard-ehcont.s
@@ -10,7 +10,7 @@
 # CHECK:   GuardCFCheckFunction: 0x0
 # CHECK:   GuardCFCheckDispatch: 0x0
 # CHECK:   GuardCFFunctionTable: 0x14000{{.*}}
-# CHECK:   GuardCFFunctionCount: 1
+# CHECK:   GuardCFFunctionCount: 4
 # CHECK:   GuardFlags [ (0x400500)
 # CHECK:     CF_FUNCTION_TABLE_PRESENT (0x400)
 # CHECK:     CF_INSTRUMENTED (0x100)
@@ -225,4 +225,4 @@
         .fill 72, 1, 0
         .quad __guard_eh_cont_table
         .quad __guard_eh_cont_count
-        .fill 32, 1, 0
\ No newline at end of file
+        .fill 32, 1, 0
Index: lld/COFF/Writer.cpp
===================================================================
--- lld/COFF/Writer.cpp
+++ lld/COFF/Writer.cpp
@@ -1743,10 +1743,11 @@
       markSymbolsForRVATable(file, file->getGuardIATChunks(), giatsRVASet);
       getSymbolsFromSections(file, file->getGuardIATChunks(), giatsSymbols);
       markSymbolsForRVATable(file, file->getGuardLJmpChunks(), longJmpTargets);
-      markSymbolsForRVATable(file, file->getGuardEHContChunks(), ehContTargets);
     } else {
       markSymbolsWithRelocations(file, addressTakenSyms);
     }
+    if (file->hasGuardEHCont())
+      markSymbolsForRVATable(file, file->getGuardEHContChunks(), ehContTargets);
   }
 
   // Mark the image entry as address-taken.
Index: lld/COFF/InputFiles.h
===================================================================
--- lld/COFF/InputFiles.h
+++ lld/COFF/InputFiles.h
@@ -177,7 +177,10 @@
   bool hasSafeSEH() { return feat00Flags & 0x1; }
 
   // True if this file was compiled with /guard:cf.
-  bool hasGuardCF() { return feat00Flags & 0x4800; }
+  bool hasGuardCF() { return feat00Flags & 0x800; }
+
+  // True if this file was compiled with /guard:ehcont.
+  bool hasGuardEHCont() { return feat00Flags & 0x4000; }
 
   // Pointer to the PDB module descriptor builder. Various debug info records
   // will reference object files by "module index", which is here. Things like


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150508.521897.patch
Type: text/x-patch
Size: 2093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230513/9966086d/attachment.bin>


More information about the llvm-commits mailing list