[PATCH] Reimplement the .seh_scope directive

Julian Waters tanksherman27@gmail.com
Mon Jul 3 03:22:40 GMT 2023


A second revision of the patch, with a small bugfix

>From 89463e94572a022b55c793d299857f85afadd2ff Mon Sep 17 00:00:00 2001
From: TheShermanTanker <tanksherman27@gmail.com>
Date: Mon, 3 Jul 2023 10:42:18 +0800
Subject: [PATCH] Reimplement the .seh_scope directive

---
 gas/config/obj-coff-seh.c | 20 ++++++++++++++++++++
 gas/config/obj-coff-seh.h |  8 +++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gas/config/obj-coff-seh.c b/gas/config/obj-coff-seh.c
index 7b4486a..87eed0f 100644
--- a/gas/config/obj-coff-seh.c
+++ b/gas/config/obj-coff-seh.c
@@ -388,6 +388,20 @@ obj_coff_seh_handlerdata (int what ATTRIBUTE_UNUSED)
   switch_xdata (seh_ctx_cur->subsection + 1, seh_ctx_cur->code_seg);
 }

+static void obj_coff_seh_scope (int what)
+{
+  if (!verify_context_and_target (".seh_scope", seh_kind_x64))
+    return;
+
+  segT seg = now_seg;
+  int subseg = now_subseg;
+
+  seh_ctx_cur->scopes++;
+  switch_xdata (seh_ctx_cur->subsection + 1, seh_ctx_cur->code_seg);
+  s_rva (4);
+  subseg_set(seg, subseg);
+}
+
 /* Mark end of current context.  */

 static void
@@ -436,6 +450,8 @@ obj_coff_seh_proc (int what ATTRIBUTE_UNUSED)

   seh_ctx_cur = XCNEW (seh_context);

+  seh_ctx_cur->scopes = 0;
+
   seh_ctx_cur->code_seg = now_seg;

   if (seh_get_target_kind () == seh_kind_x64)
@@ -899,6 +915,10 @@ seh_x64_write_function_xdata (seh_context *c)
       emit_expr (&c->handler, 4);
     }

+  if (c->scopes > 0) {
+    out_four (c->scopes);
+  }
+
   /* Handler data will be tacked in here by subsections.  */
 }

diff --git a/gas/config/obj-coff-seh.h b/gas/config/obj-coff-seh.h
index 8d77bac..7c92921 100644
--- a/gas/config/obj-coff-seh.h
+++ b/gas/config/obj-coff-seh.h
@@ -57,6 +57,7 @@
   .seh_savexmm
   .seh_pushframe
   .seh_code
+  .seh_scope
 */

 /* architecture specific pdata/xdata handling.  */
@@ -75,7 +76,8 @@
  {"seh_no32", obj_coff_seh_32, 0}, \
  {"seh_handler", obj_coff_seh_handler, 0}, \
  {"seh_code", obj_coff_seh_code, 0}, \
- {"seh_handlerdata", obj_coff_seh_handlerdata, 0},
+ {"seh_handlerdata", obj_coff_seh_handlerdata, 0}, \
+ {"seh_scope", obj_coff_seh_scope, 0},

 /* Type definitions.  */

@@ -128,6 +130,9 @@ typedef struct seh_context
   int elems_count;
   int elems_max;
   seh_prologue_element *elems;
+
+  /* Scope count for x64 .xdata */
+  unsigned int scopes;
 } seh_context;

 typedef enum seh_kind {
@@ -151,6 +156,7 @@ static void obj_coff_seh_proc  (int);
 static void obj_coff_seh_handler (int);
 static void obj_coff_seh_handlerdata (int);
 static void obj_coff_seh_code (int);
+static void obj_coff_seh_scope (int);

 #define UNDSEC bfd_und_section_ptr

-- 
2.35.1.windows.2


More information about the Binutils mailing list