From c91253a19e73d69c7d8ce560bbef947cd3c0be6b Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Tue, 10 Dec 2024 14:07:26 -0800 Subject: [PATCH] move feature flags to appropriate layer --- src/coff/coff.h | 14 -------------- src/dumpers/coffdump.c | 2 +- src/linker/lnk.c | 8 +++++--- src/linker/lnk_obj.c | 4 ++-- src/msvc_crt/msvc_crt.h | 18 ++++++++++++++++-- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/coff/coff.h b/src/coff/coff.h index 80e34c87..cc79a86a 100644 --- a/src/coff/coff.h +++ b/src/coff/coff.h @@ -523,20 +523,6 @@ struct COFF_Reloc #pragma pack(pop) -// feature flags in absolute symbol @feat.00 -enum -{ - COFF_FeatFlag_HAS_SAFE_SEH = (1 << 0), // /safeseh - COFF_FeatFlag_UNKNOWN_4 = (1 << 4), - COFF_FeatFlag_GUARD_STACK = (1 << 8), // /GS - COFF_FeatFlag_SDL = (1 << 9), // /sdl - COFF_FeatFlag_GUARD_CF = (1 << 11), // /guard:cf - COFF_FeatFlag_GUARD_EH_CONT = (1 << 14), // /guard:ehcont - COFF_FeatFlag_NO_RTTI = (1 << 17), // /GR- - COFF_FeatFlag_KERNEL = (1 << 30), // /kernel -}; -typedef U32 COFF_FeatFlags; - //////////////////////////////// #define COFF_RES_ALIGN 4u diff --git a/src/dumpers/coffdump.c b/src/dumpers/coffdump.c index 5e6376f4..89a820d0 100644 --- a/src/dumpers/coffdump.c +++ b/src/dumpers/coffdump.c @@ -1274,7 +1274,7 @@ pe_format_debug_directory(Arena *arena, String8List *out, String8 indent, String } } break; case PE_DebugDirectoryType_VC_FEATURE: { - MSVCRT_VCFeatures *feat = str8_deserial_get_raw_ptr(raw_entry, 0, sizeof(*feat)); + MSCRT_VCFeatures *feat = str8_deserial_get_raw_ptr(raw_entry, 0, sizeof(*feat)); if (feat) { coff_printf("Pre-VC++ 11.0: %u", feat->pre_vcpp); coff_printf("C/C++: %u", feat->c_cpp); diff --git a/src/linker/lnk.c b/src/linker/lnk.c index b0d2a380..fe3d414f 100644 --- a/src/linker/lnk.c +++ b/src/linker/lnk.c @@ -40,6 +40,7 @@ #include "msf/msf.h" #include "msf/msf_parse.h" #include "pdb/pdb.h" +#include "msvc_crt/msvc_crt.h" #include "base/base_inc.c" #include "os/os_inc.c" @@ -49,6 +50,7 @@ #include "codeview/codeview.c" #include "msf/msf_parse.c" #include "pdb/pdb.c" +#include "msvc_crt/msvc_crt.c" #if defined(__clang__) # pragma clang diagnostic pop @@ -717,7 +719,7 @@ lnk_make_res_obj(TP_Context *tp, COFF_Symbol16 coff_feat00 = {0}; MemoryCopyStr8(&coff_feat00.name, str8_lit("@feat.00")); - coff_feat00.value = COFF_FeatFlag_HAS_SAFE_SEH|COFF_FeatFlag_UNKNOWN_4; + coff_feat00.value = MSCRT_FeatFlag_HAS_SAFE_SEH|MSCRT_FeatFlag_UNKNOWN_4; coff_feat00.section_number = COFF_SYMBOL_ABS_SECTION_16; coff_feat00.storage_class = COFF_SymStorageClass_STATIC; coff_symbol16_list_push(scratch.arena, &coff_symbol_list, coff_feat00); @@ -1441,8 +1443,8 @@ lnk_build_guard_tables(TP_Context *tp, // collect symbols from objs for (LNK_ObjNode *obj_node = obj_list.first; obj_node != NULL; obj_node = obj_node->next) { LNK_Obj *obj = &obj_node->data; - COFF_FeatFlags feat_flags = lnk_obj_get_features(obj); - B32 has_guard_flags = (feat_flags & COFF_FeatFlag_GUARD_CF) || (feat_flags & COFF_FeatFlag_GUARD_EH_CONT); + MSCRT_FeatFlags feat_flags = lnk_obj_get_features(obj); + B32 has_guard_flags = (feat_flags & MSCRT_FeatFlag_GUARD_CF) || (feat_flags & MSCRT_FeatFlag_GUARD_EH_CONT); if (has_guard_flags) { LNK_SymbolArray symbol_arr = lnk_symbol_array_from_list(scratch.arena, obj->symbol_list); if (guard_flags & LNK_Guard_Cf) { diff --git a/src/linker/lnk_obj.c b/src/linker/lnk_obj.c index 7af15d2f..b6c9c487 100644 --- a/src/linker/lnk_obj.c +++ b/src/linker/lnk_obj.c @@ -1067,10 +1067,10 @@ lnk_init_directives(Arena *arena, String8 obj_path, U64 chunk_count, String8 *se return directive_info; } -internal COFF_FeatFlags +internal MSCRT_FeatFlags lnk_obj_get_features(LNK_Obj *obj) { - COFF_FeatFlags result = 0; + MSCRT_FeatFlags result = 0; LNK_Symbol *sym = lnk_symbol_list_search(obj->symbol_list, str8_lit("@feat.00"), 0); if (sym) { Assert(LNK_Symbol_IsDefined(sym->type)); diff --git a/src/msvc_crt/msvc_crt.h b/src/msvc_crt/msvc_crt.h index 8c77094a..21106ee0 100644 --- a/src/msvc_crt/msvc_crt.h +++ b/src/msvc_crt/msvc_crt.h @@ -6,14 +6,28 @@ //////////////////////////////// -typedef struct MSVCRT_VCFeatures +// feature flags in absolute symbol @feat.00 +enum +{ + MSCRT_FeatFlag_HAS_SAFE_SEH = (1 << 0), // /safeseh + MSCRT_FeatFlag_UNKNOWN_4 = (1 << 4), + MSCRT_FeatFlag_GUARD_STACK = (1 << 8), // /GS + MSCRT_FeatFlag_SDL = (1 << 9), // /sdl + MSCRT_FeatFlag_GUARD_CF = (1 << 11), // /guard:cf + MSCRT_FeatFlag_GUARD_EH_CONT = (1 << 14), // /guard:ehcont + MSCRT_FeatFlag_NO_RTTI = (1 << 17), // /GR- + MSCRT_FeatFlag_KERNEL = (1 << 30), // /kernel +}; +typedef U32 MSCRT_FeatFlags; + +typedef struct MSCRT_VCFeatures { U32 pre_vcpp; U32 c_cpp; U32 gs; U32 sdl; U32 guard_n; -} MSVCRT_VCFeatures; +} MSCRT_VCFeatures; //////////////////////////////// // GS Handler