From patchwork Wed May 2 21:53:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 907730 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-477142-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=golang.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="WoOioTu7"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40bsVZ2hWtz9s35 for ; Thu, 3 May 2018 07:53:54 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:cc:content-type; q=dns; s=default; b=VpxKBXqhqLm1dsaD7RMLymNVygi6UtRK08YcBPzLoLE gWuXFMTx+EmctGL6cRafvBYxHEkwGccvBDvYp0NP/klu797rTYFUnxO/zFfejdkH HHBXnCCvGrxKoAWgRk/L2DyXYHrvQqZY4SS4d+sIvrf9p48YRPeCbE8AITVQe5A4 = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:cc:content-type; s=default; bh=l2gkWEXk+2letvSjfvVpB2ksorA=; b=WoOioTu7b50J730n0 8Qt/8PHSGe+VzQil09nt2NszFfqX3Gb08iuTzLagI9eF6HIyAQSRPfLcczzaHiMi m9M/4E7jGPZx2nHS4v39S62ntsF70jRmkMhZ68WuViQOTg4dRby0ry6GOPJyrVUC 5dx+35VDdWMNhq5SbWycVAK/ZI= Received: (qmail 42396 invoked by alias); 2 May 2018 21:53:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 42386 invoked by uid 89); 2 May 2018 21:53:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=259805, 0x02 X-HELO: mail-wm0-f52.google.com Received: from mail-wm0-f52.google.com (HELO mail-wm0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 May 2018 21:53:36 +0000 Received: by mail-wm0-f52.google.com with SMTP id w194so3179285wmf.2 for ; Wed, 02 May 2018 14:53:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=dr45XAATzwMzV4BuKvK8honJKTVKGF8NHMfBBVixEfM=; b=P1HQsq4NH1q18qdUvvf8rKDvokdRReLvcn5eW+9KR4Rr813Sn3WcawRBoWFv7606ww A2Cht+IfZdnmV75Z93+U+EJRvMMSxtn8xLy3fmpffihzo0qcot2RYznMVoyGYE5NDCbM JJn1SDPguTzUvH06T7y4T+SDxnhckqNtqXwJ9m9/b7wZjO1+Y+oG13JOK+z7jvrv9EAZ Wytp5lKMdxcB5/zvUslX20q9XIHMkTcYX1R6CfdR40drG1vvERwtDNFm1FbtuMB03oPo FphmC5d+C3YTdF9jEZ5VsYnth2IXds8USoYSZqMZw0v2jvSnLHxiCbLUTc5NPnDNlfa0 RTDA== X-Gm-Message-State: ALQs6tCm3Ta03O7XywH2IP1oSSCBZ1cfd74j0+G59+Tiy9yGYuPiV3xl Xk7xgfA3+ighuzop2e1CNX4934dkvhcWkyEYIsNa7PNj X-Google-Smtp-Source: AB8JxZpV18dZHDIIV8jwb2jBI0dHPXpPatkd0VgFrvkWNBFvo5nFNMmUQcSU1mUIaAHBp1KcIoLcYwO/mLBUasSVeLI= X-Received: by 2002:a50:a926:: with SMTP id l35-v6mr15133877edc.106.1525298013926; Wed, 02 May 2018 14:53:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.245.189 with HTTP; Wed, 2 May 2018 14:53:33 -0700 (PDT) From: Ian Lance Taylor Date: Wed, 2 May 2018 14:53:33 -0700 Message-ID: Subject: libgo patch committed: break dependence on unwind-pe.h To: gcc-patches , gofrontend-dev@googlegroups.com Cc: Than McIntosh This patch by Than McIntosh breaks the dependence of go-unwind.c on unwind-pe.h, by adding the required definitions and code directly to go-unwind.c. go-unwind.c still depends on the public unwind.h API. This makes it easier to build libgo separately. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian Index: libgo/runtime/go-unwind.c =================================================================== --- libgo/runtime/go-unwind.c (revision 259805) +++ libgo/runtime/go-unwind.c (working copy) @@ -10,11 +10,30 @@ #include #include "unwind.h" -#define NO_SIZE_OF_ENCODED_VALUE -#include "unwind-pe.h" #include "runtime.h" +/* These constants are documented here: + https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA/dwarfext.html + */ + +#define DW_EH_PE_omit 0xff +#define DW_EH_PE_absptr 0x00 +#define DW_EH_PE_uleb128 0x01 +#define DW_EH_PE_udata2 0x02 +#define DW_EH_PE_udata4 0x03 +#define DW_EH_PE_udata8 0x04 +#define DW_EH_PE_sleb128 0x09 +#define DW_EH_PE_sdata2 0x0A +#define DW_EH_PE_sdata4 0x0B +#define DW_EH_PE_sdata8 0x0C +#define DW_EH_PE_pcrel 0x10 +#define DW_EH_PE_textrel 0x20 +#define DW_EH_PE_datarel 0x30 +#define DW_EH_PE_funcrel 0x40 +#define DW_EH_PE_aligned 0x50 +#define DW_EH_PE_indirect 0x80 + /* The code for a Go exception. */ #ifdef __ARM_EABI_UNWINDER__ @@ -109,6 +128,150 @@ throwException () abort (); } +static inline _Unwind_Ptr +encoded_value_base (uint8_t encoding, struct _Unwind_Context *context) +{ + if (encoding == DW_EH_PE_omit) + return 0; + switch (encoding & 0x70) + { + case DW_EH_PE_absptr: + case DW_EH_PE_pcrel: + case DW_EH_PE_aligned: + return 0; + case DW_EH_PE_textrel: + return _Unwind_GetTextRelBase(context); + case DW_EH_PE_datarel: + return _Unwind_GetDataRelBase(context); + case DW_EH_PE_funcrel: + return _Unwind_GetRegionStart(context); + } + abort (); +} + +/* Read an unsigned leb128 value. */ + +static inline const uint8_t * +read_uleb128 (const uint8_t *p, _uleb128_t *val) +{ + unsigned int shift = 0; + _uleb128_t result = 0; + uint8_t byte; + + do + { + byte = *p++; + result |= ((_uleb128_t)byte & 0x7f) << shift; + shift += 7; + } + while (byte & 0x80); + + *val = result; + return p; +} + +/* Similar, but read a signed leb128 value. */ + +static inline const uint8_t * +read_sleb128 (const uint8_t *p, _sleb128_t *val) +{ + unsigned int shift = 0; + _uleb128_t result = 0; + uint8_t byte; + + do + { + byte = *p++; + result |= ((_uleb128_t)byte & 0x7f) << shift; + shift += 7; + } + while (byte & 0x80); + + /* sign extension */ + if (shift < (8 * sizeof(result)) && (byte & 0x40) != 0) + result |= (((_uleb128_t)~0) << shift); + + *val = (_sleb128_t)result; + return p; +} + +#define ROUND_UP_TO_PVB(x) (x + sizeof(void *) - 1) &- sizeof(void *) + +#define COPY_AND_ADVANCE(dst, ptr, typ) \ + (dst = *((const typ*)ptr), \ + ptr += sizeof(typ)) + +static inline const uint8_t * +read_encoded_value (struct _Unwind_Context *context, uint8_t encoding, + const uint8_t *p, _Unwind_Ptr *val) +{ + _Unwind_Ptr base = encoded_value_base (encoding, context); + _Unwind_Internal_Ptr decoded = 0; + const uint8_t *origp = p; + + if (encoding == DW_EH_PE_aligned) + { + _Unwind_Internal_Ptr uip = (_Unwind_Internal_Ptr)p; + uip = ROUND_UP_TO_PVB (uip); + decoded = *(_Unwind_Internal_Ptr *)uip; + p = (const uint8_t *)(uip + sizeof(void *)); + } + else + { + switch (encoding & 0x0f) + { + case DW_EH_PE_sdata2: + case DW_EH_PE_udata2: + COPY_AND_ADVANCE (decoded, p, uint16_t); + break; + case DW_EH_PE_sdata4: + case DW_EH_PE_udata4: + COPY_AND_ADVANCE (decoded, p, uint32_t); + break; + case DW_EH_PE_sdata8: + case DW_EH_PE_udata8: + COPY_AND_ADVANCE (decoded, p, uint64_t); + break; + case DW_EH_PE_uleb128: + { + _uleb128_t value; + p = read_uleb128 (p, &value); + decoded = (_Unwind_Internal_Ptr)value; + break; + } + case DW_EH_PE_sleb128: + { + _sleb128_t value; + p = read_sleb128 (p, &value); + decoded = (_Unwind_Internal_Ptr)value; + break; + } + case DW_EH_PE_absptr: + decoded = (_Unwind_Internal_Ptr)(*(const void *const *)p); + p += sizeof(void *); + break; + default: + abort (); + } + + if (decoded == 0) + { + *val = decoded; + return p; + } + + if ((encoding & 0x70) == DW_EH_PE_pcrel) + decoded += ((_Unwind_Internal_Ptr)origp); + else + decoded += base; + + if ((encoding & DW_EH_PE_indirect) != 0) + decoded = *(_Unwind_Internal_Ptr *)decoded; + } + *val = decoded; + return p; +} + /* The rest of this code is really similar to gcc/unwind-c.c and libjava/exception.cc. */