From 52990b6f7cc678cec5e29e3cd0e7c0f4096de0be Mon Sep 17 00:00:00 2001 From: Mathias Berchtold Date: Sat, 22 Apr 2023 07:06:20 -0600 Subject: [PATCH] Always emit an absolute @feat.00 symbol for CFG support This allows link.exe to use the Control Flow Guard feature (/guard:cf) --- output/outcoff.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/output/outcoff.c b/output/outcoff.c index c2b4eb6e..1b6243fb 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -1042,8 +1042,8 @@ static void coff_write(void) /* fill in the .drectve section with -export's */ BuildExportTable(&Exports); - if (win32) { - /* add default value for @feat.00, this allows to 'link /safeseh' */ + /* Emit an absolute @feat.00 symbol */ + { uint32_t n; saa_rewind(coff_syms); @@ -1052,8 +1052,15 @@ static void coff_write(void) if (sym->strpos == -1 && !strcmp("@feat.00",sym->name)) break; } - if (n == coff_nsyms) - coff_deflabel("@feat.00", NO_SEG, 1, 0, NULL); + if (n == coff_nsyms) { + int64_t feat00_flags = 0; + if (win32) + /* marks the object for "registered SEH". this allows to 'link /safeseh' */ + feat00_flags |= 1; + + feat00_flags |= 0x800; /* object is CFG-aware */ + coff_deflabel("@feat.00", NO_SEG, feat00_flags, 0, NULL); + } } /*