From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id 7E1483858412 for ; Sun, 2 Jul 2023 10:16:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E1483858412 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-qk1-x72e.google.com with SMTP id af79cd13be357-7659c6cae2cso254650985a.1 for ; Sun, 02 Jul 2023 03:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688293003; x=1690885003; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=kyqDf+toW8tdwss82/Qi4581Iozx0nj7Z7Pw86pVyhs=; b=l6sCIytj45Ci7Nwe9qnWIAfUnDSAKqZovKfhjQ/iiX5peQ6HwrOa0nbtOaRuRu4Hst lgihstzBeUvLaLWCH153TfL2lMKIG0qHvvP3+svrtnIa4gF+mtoDeMel9cn7agl3G6DJ MEXJEZ2yoe8xPyRTlooTk7e5rJGogKHRqNuFZ1lExFqKc/VJXuDMLJ/6Go5oxMW4/vNe s57WNa/DVCEa4VEN9AZYFbXI7vFzEXzw2NLU6Lv2GF3ra4h0iP8N98zJap/FGPQXC8eG EUlxRft9SwXf8uar190eWBMGGmkECREXpyY64CeyzApCtsDN4wNTuJ/xnaYd6dTyili3 DFhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688293003; x=1690885003; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=kyqDf+toW8tdwss82/Qi4581Iozx0nj7Z7Pw86pVyhs=; b=mB1AUlGWv12ursuN2F/sauTXAcb9HzU2ahPeNughhB7rQnZJyb1LXr5WT88yipxRrC HoodFZvtV7Rt18pckJvcTMf5Wi7yScTnSa6h9lVymoeRF6DHg574/0ueC5RUXuViSJXO vUcboX47kPvtt/Zz58U6ej82KUSWPGhDfDm+nm54OMlgwLZbLzSYqiiYrfSHSqGpQyfG Y6zSsSfg4jBFxla6p5B4yZGYv0QNoaoCzNWLZH9E8ALKPBd44ahmgEDKuYfM/ctrnAny kcrMzhXtDFm7N7dDp0yZlzp+/0lc3eGbi0XAuaVdi54BIyHxfIPef985BSOV8nIciZ39 x6Dw== X-Gm-Message-State: AC+VfDzvKB/J8zHItXjgET9vEgpHk46Ts54LXNNeLEpMyLQe+OHYPkk7 sm9dKcPp/ThbA1WggrYdaer1CoBgJrRoRivxWY6DTYX8VAg= X-Google-Smtp-Source: ACHHUZ7aYdTp9zE6G6yMsfyWOOhz8MGrxMYukDlCdjONUkG7a7PSTrSJBJ/BmOuPuW9F1hup1Ve0b+g8qK/iTsukyBE= X-Received: by 2002:a05:620a:f14:b0:762:731:1b3e with SMTP id v20-20020a05620a0f1400b0076207311b3emr7288496qkl.18.1688293003637; Sun, 02 Jul 2023 03:16:43 -0700 (PDT) MIME-Version: 1.0 From: Julian Waters Date: Sun, 2 Jul 2023 18:16:07 +0800 Message-ID: Subject: Reimplement the .seh_scope directive To: binutils@sourceware.org Content-Type: multipart/alternative; boundary="000000000000c2369805ff7e58ca" X-Spam-Status: No, score=-8.0 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: --000000000000c2369805ff7e58ca 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. 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 --000000000000c2369805ff7e58ca--