From patchwork Sun Jul 2 10:18:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Waters X-Patchwork-Id: 115077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp11480923vqr; Sun, 2 Jul 2023 03:19:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlFn2krCTPNXdh9/TTFqRJStdzIMeyyiqrqF8NOkfRx90oxVNi8PFuJCyexii2aQ6OAG8Pm+ X-Received: by 2002:aa7:dd18:0:b0:51e:d96:15e4 with SMTP id i24-20020aa7dd18000000b0051e0d9615e4mr571178edv.19.1688293157149; Sun, 02 Jul 2023 03:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688293157; cv=none; d=google.com; s=arc-20160816; b=rC+K5tGEXWWl6Jka/SvKdGK6WwxE9zGZ6gWTo+wBQS+ml8QaE7k/p0Fhs4qeylYiCK hM3DkER7Td3meuBrogRW7k0ccETDV83m1kmto2aJ8Xt0nsAuUVd6mxAdF0/OPdpKq1Ki k2Z+AXsm58fssiEMqVsGQRUDZH7rV5h8sQy2Ojf13pAtV9kQHJD4sAItX7bwd7zJtaY6 oFdkibUwHK9NV9EsHnsfg1M1xxSSiN9gGb1UP4+5QBzSRbilcmTp2cZqmUX9AxN8U4Yb A+kNP/PLRig9m78pAB76aSD9MKYaCRSp4q2T26wEF5YW0oZnjzKJ86ZwlBzGUmtug66H lGjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=5aQAA6hSno3pMBnRxM0b4fe7QR5ddoNIj3eTPFUfOPk=; fh=NLxAvL/bDfPg4AGOtxqvQlND8vazkZrNzKLY8+LAbBY=; b=bxxsZk93p7NIy3v4wxMUOd+2ct7Mj0Qx0zGmgAbFCiZLiumFt/znkAqAktJtz+Dvx/ RVflVbkpR7M74f8X58Djn0DygIjR/XUWnQfpefGVAxv0vVrZNzSv3SWKlUxU7e7bBcKF V3Y/KkI2R9d6MTXIUZ9mwrVQVRK+hJMgp7ujfi431NCgKqmQj+syhsYG1Ovjfzes4b8/ oViQvYld9RaYENTWUrzslwcFVltcRAG8mJvpBWlijoBNP4SvxMFHlvBU7MS4KpBMTbHd 7+AER5WVRS8444ILECBrmOTsYKhtjcGTQ+c7pQvOF7++BK6l2RdtNeZkTpV/mKWxc0Dl jStQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=l11A1fEt; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b1-20020aa7d481000000b0051e065ab8besi708057edr.368.2023.07.02.03.19.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 03:19:17 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=l11A1fEt; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3321385841C for ; Sun, 2 Jul 2023 10:19:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F3321385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688293156; bh=5aQAA6hSno3pMBnRxM0b4fe7QR5ddoNIj3eTPFUfOPk=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=l11A1fEti0F63pRfNBHPzH1dpwQTQwhtv5V5p1BS1XoMiqw4YiEjxNUZ8z/iU+KcR Q4+d4M6MCvP+shUC22WnbtKnsotnSs0Cu9z4ubDSw4g5GcJ4uRZp0ZpQlr1l75rVuw zeqB3nElPbzNpUX9O6fVKU03+O/au1tpufe78l5U= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-403275472c5so31141661cf.0 for ; Sun, 02 Jul 2023 03:19:08 -0700 (PDT) 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-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 Date: Sun, 2 Jul 2023 18:18:31 +0800 Message-ID: Subject: [PATCH] Reimplement the .seh_scope directive To: binutils@sourceware.org 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 X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Julian Waters via Binutils From: Julian Waters Reply-To: Julian Waters Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770303685523507631?= X-GMAIL-MSGID: =?utf-8?q?1770303685523507631?= 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(-) -- 2.35.1.windows.2 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