From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by sourceware.org (Postfix) with ESMTPS id 8DF3A3858412 for ; Sun, 2 Jul 2023 10:19:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8DF3A3858412 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-403275472c5so31141661cf.0 for ; Sun, 02 Jul 2023 03:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688293148; x=1690885148; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=EZYnskVSrQErSQ+/qCBU1XYYsNYlG+rYl0SQN7qVLxo=; b=Grc3t8wwN7VA/VViaUOvasctv542+1QxqDyB/EJmynYjSg5LwXvzktBGB1JtWEtQ1J cX7/df7GRtf7lsd77wVZO7dB87RqxlUMo7EWDqVSpf04LnMY5mMXuPrajIpTDUQhrNVT RR+tMxE/nYJyF2MZo2SpN3/CtPbloKWMECWAKAlC7Gqv6CS6nKqo2EuDx6SsRoL1OZzg eNhZJOcVR8g7j6Haf03VkCz3nXy7uGSQqzdZar07sn1PxaVMFHMvjvV8qokBnaN1KnBe rNcCPECefGSCdAwuL0Jhx4zU9tG0KSQe2Q/NTDi9WYfLGhpqXpha3ZCfayZd85w/M32u dAfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688293148; x=1690885148; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EZYnskVSrQErSQ+/qCBU1XYYsNYlG+rYl0SQN7qVLxo=; b=LweZqxKDC7udxrC+BQlnEytQRK0t1hkrIV2JHDRPTtSecM6C+wH9wlINhTsD444TIM 9t9V7l/JBp7mmLzXLnVq6MFG3vjtFx9UwmH4gt0VTLNSeGB0Q8q41oQfqj18kYdpiIbj +LwNOtHj/PWfLxEMQWe8HsQyyBFPKGpFxuNjLrpKSf7MMbkMHSwLCnA5Gz0m8fWnaK02 X+zmPeddKBochy7Sgqn6kLN8Ew4XzSjg0wHDaHGFX0crB2yYKQbcdNpLIt97HCvjPB6t syivFDW591C1bRAnTujTjxI7I6q9KwPoR/uu5gNkQBQMrMU788ofFO0FCJeXV7wiO8F6 skjA== X-Gm-Message-State: AC+VfDwZx6c7tYzmCdiZPH5O9Zr3Xt1sFwYrPCuL2CT7HIWYHWefFFoi AWUOSocVRnqIBF8+ur1GO5T1sb2TkdbcLduAJU2d9ijWgiI= X-Google-Smtp-Source: ACHHUZ5IyVB5zho4yJexppRNf2l0Q/QQMu3nPvQdjIrosWDqMGkSNUyquNZX+KnYAGd0r/uqTnW9DCOS++3joXIVSi4= X-Received: by 2002:a05:622a:190b:b0:3fd:e976:54bd with SMTP id w11-20020a05622a190b00b003fde97654bdmr11811487qtc.56.1688293147694; Sun, 02 Jul 2023 03:19:07 -0700 (PDT) MIME-Version: 1.0 From: Julian Waters Date: Sun, 2 Jul 2023 18:18:31 +0800 Message-ID: Subject: [PATCH] Reimplement the .seh_scope directive To: binutils@sourceware.org Content-Type: multipart/alternative; boundary="0000000000005857d105ff7e6165" X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000005857d105ff7e6165 Content-Type: text/plain; charset="UTF-8" The .seh_scope directive was removed a little over a decade ago due to being too Microsoft specific. This has proven to be a mistake as there is now no easy way for reusable inline assembly to express Structured Exception Handling scopes for Microsoft Windows targets, combined with the handler count field that the xdata section requires. This patch reimplements a simpler version of .seh_scope, with the proper semantics in place >From cc9e143f8feb933ca8fc4b12deaab2985893b714 Mon Sep 17 00:00:00 2001 From: TheShermanTanker Date: Sun, 2 Jul 2023 16:22:18 +0800 Subject: [PATCH] Reimplement .seh_scope --- gas/config/obj-coff-seh.c | 26 ++++++++++++++++++++++++-- gas/config/obj-coff-seh.h | 5 ++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/gas/config/obj-coff-seh.c b/gas/config/obj-coff-seh.c index 7b4486a..b01a207 100644 --- a/gas/config/obj-coff-seh.c +++ b/gas/config/obj-coff-seh.c @@ -30,6 +32,7 @@ struct seh_seg_list { /* Local data. */ static seh_context *seh_ctx_cur = NULL; +static unsigned int scope = 0; static htab_t seh_hash; @@ -385,7 +388,21 @@ obj_coff_seh_handlerdata (int what ATTRIBUTE_UNUSED) return; demand_empty_rest_of_line (); - switch_xdata (seh_ctx_cur->subsection + 1, seh_ctx_cur->code_seg); + switch_xdata (seh_ctx_cur->subsection + (scope == 0) ? 1 : 2, 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; + + scope++; + switch_xdata (seh_ctx_cur->subsection + 2, seh_ctx_cur->code_seg); + s_rva (4); + subseg_set(seg, subseg); } /* Mark end of current context. */ @@ -442,7 +459,7 @@ obj_coff_seh_proc (int what ATTRIBUTE_UNUSED) { x_segcur = seh_hash_find_or_make (seh_ctx_cur->code_seg, ".xdata"); seh_ctx_cur->subsection = x_segcur->subseg; - x_segcur->subseg += 2; + x_segcur->subseg += 3; } SKIP_WHITESPACE (); @@ -918,6 +935,11 @@ write_function_xdata (seh_context *c) seh_x64_write_function_xdata (c); + if (scope > 0) { + switch_xdata (c->subsection + 1, c->code_seg); + out_four (scope); + } + subseg_set (save_seg, save_subseg); } diff --git a/gas/config/obj-coff-seh.h b/gas/config/obj-coff-seh.h index 8d77bac..feef17f 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. */ @@ -151,6 +153,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 --0000000000005857d105ff7e6165--