Skip to content

Commit

Permalink
move feature flags to appropriate layer
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaSmith057 committed Dec 10, 2024
1 parent 48cb999 commit c91253a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
14 changes: 0 additions & 14 deletions src/coff/coff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/dumpers/coffdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/linker/lnk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/linker/lnk_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
18 changes: 16 additions & 2 deletions src/msvc_crt/msvc_crt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c91253a

Please sign in to comment.