diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -24,6 +24,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/BinaryFormat/COFF.h" #include "llvm/Support/BinaryStreamReader.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Endian.h" @@ -1702,12 +1703,12 @@ // Set __guard_flags, which will be used in the load config to indicate that // /guard:cf was enabled. - uint32_t guardFlags = uint32_t(coff_guard_flags::CFInstrumented) | - uint32_t(coff_guard_flags::HasFidTable); + uint32_t guardFlags = uint32_t(GuardFlags::CF_INSTRUMENTED) | + uint32_t(GuardFlags::CF_FUNCTION_TABLE_PRESENT); if (config->guardCF & GuardCFLevel::LongJmp) - guardFlags |= uint32_t(coff_guard_flags::HasLongJmpTable); + guardFlags |= uint32_t(GuardFlags::CF_LONGJUMP_TABLE_PRESENT); if (config->guardCF & GuardCFLevel::EHCont) - guardFlags |= uint32_t(coff_guard_flags::HasEHContTable); + guardFlags |= uint32_t(GuardFlags::EH_CONTINUATION_TABLE_PRESENT); Symbol *flagSym = ctx.symtab.findUnderscore("__guard_flags"); cast(flagSym)->setVA(guardFlags); } diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h --- a/llvm/include/llvm/Object/COFF.h +++ b/llvm/include/llvm/Object/COFF.h @@ -597,17 +597,6 @@ using coff_tls_directory32 = coff_tls_directory; using coff_tls_directory64 = coff_tls_directory; -/// Bits in control flow guard flags as we understand them. -enum class coff_guard_flags : uint32_t { - CFInstrumented = 0x00000100, - HasFidTable = 0x00000400, - ProtectDelayLoadIAT = 0x00001000, - DelayLoadIATSection = 0x00002000, // Delay load in separate section - HasLongJmpTable = 0x00010000, - HasEHContTable = 0x00400000, - FidTableHasFlags = 0x10000000, // Indicates that fid tables are 5 bytes -}; - enum class frame_type : uint16_t { Fpo = 0, Trap = 1, Tss = 2, NonFpo = 3 }; struct coff_load_config_code_integrity { diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp --- a/llvm/tools/llvm-readobj/COFFDumper.cpp +++ b/llvm/tools/llvm-readobj/COFFDumper.cpp @@ -852,11 +852,18 @@ if (Tables.GuardFidTableVA) { ListScope LS(W, "GuardFidTable"); - if (Tables.GuardFlags & uint32_t(coff_guard_flags::FidTableHasFlags)) - printRVATable(Tables.GuardFidTableVA, Tables.GuardFidTableCount, 5, + if (uint32_t Size = + Tables.GuardFlags & + uint32_t(COFF::GuardFlags::CF_FUNCTION_TABLE_SIZE_MASK)) { + // The size mask gives the number of extra bytes in addition to the 4-byte + // RVA of each entry in the table. As of writing only a 1-byte extra flag + // has been defined. + Size = (Size >> 28) + 4; + printRVATable(Tables.GuardFidTableVA, Tables.GuardFidTableCount, Size, PrintGuardFlags); - else + } else { printRVATable(Tables.GuardFidTableVA, Tables.GuardFidTableCount, 4); + } } if (Tables.GuardIatTableVA) {