public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Julian Waters <tanksherman27@gmail.com>
To: binutils@sourceware.org
Subject: Re: [PATCH] Reimplement the .seh_scope directive
Date: Mon, 3 Jul 2023 14:12:33 +0800	[thread overview]
Message-ID: <CAP2b4GPpt-p975y8FQNduxxeGpgi-LooTFHR122XYmNmG6xcgg@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 116 bytes --]

Here is the patch attached as a file, if the mailing list doesn't slice it
out once I send it

best regards,
Julian

[-- Attachment #2: 0001-Reimplement-the-.seh_scope-directive.patch --]
[-- Type: application/octet-stream, Size: 2904 bytes --]

From bb304d4eff54db673b13eaafa2b082862b80122e Mon Sep 17 00:00:00 2001
From: TheShermanTanker <tanksherman27@gmail.com>
Date: Mon, 3 Jul 2023 14:09:53 +0800
Subject: [PATCH] Reimplement the .seh_scope directive

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

diff --git a/gas/config/obj-coff-seh.c b/gas/config/obj-coff-seh.c
index 7b4486a..e5dd8f2 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)
@@ -902,6 +918,14 @@ seh_x64_write_function_xdata (seh_context *c)
   /* Handler data will be tacked in here by subsections.  */
 }
 
+static inline void
+seh_x64_maybe_write_scope_count (seh_context *c)
+{
+  if (c->scopes > 0) {
+    out_four (c->scopes);
+  }
+}
+
 /* Write out xdata for one function.  */
 
 static void
@@ -918,6 +942,8 @@ write_function_xdata (seh_context *c)
 
   seh_x64_write_function_xdata (c);
 
+  seh_x64_maybe_write_scope_count (c);
+
   subseg_set (save_seg, save_subseg);
 }
 
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


             reply	other threads:[~2023-07-03  6:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-03  6:12 Julian Waters [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-07-03  3:22 Julian Waters
2023-07-02 10:18 Julian Waters

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAP2b4GPpt-p975y8FQNduxxeGpgi-LooTFHR122XYmNmG6xcgg@mail.gmail.com \
    --to=tanksherman27@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).