From patchwork Thu Apr 27 15:15:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1774482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=Bw861s1r; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q6fSG0wSpz23vG for ; Fri, 28 Apr 2023 01:15:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 916C338582AB for ; Thu, 27 Apr 2023 15:15:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id BE5453858D33 for ; Thu, 27 Apr 2023 15:15:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE5453858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=jVkiNsc44t4+UugfaeptQ7UTiLyaRtS5AKq0RSxoLDQ=; b=Bw861s1rufGwjPK3zs0uh0UClV LGxbiww969qzo19Cz6QyEsRHZC1G0N8rnlaHPMEOu/zHTmapnq7lI9r9elq2s+VlwOINDcLZtAp/3 LxxQggSQPJhqs5wPi6DsmlJzdWvQE4guYz8729kqOfG5ACu20+QOxKTZSTDyTKgvM/jX2EqPYfq+d xNhJLQ5Jib9F56B7+tS+a4FRxvNMEdrneGjFjAXKtq7HAUKf7qixLJzTcuWOlfQf5hgWZtK6Q+bpS E0nlUaDlrux9PfxH8HHO3VTZgxSwk/ftl0qm3DXQJ4BtTJsrr18tSAh0PBmcZihNiyq3RxNhJlYeU hymu9pPg==; Received: from [185.62.158.67] (port=63599 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ps3Ku-0004AP-08 for gcc-patches@gcc.gnu.org; Thu, 27 Apr 2023 11:15:08 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] Synchronize include/ctf.h with upstream binutils/libctf. Date: Thu, 27 Apr 2023 16:15:05 +0100 Message-ID: <002001d9791b$0d55b960$28012c20$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adl5GllMY73BNagyT9qmQp8yllgf0w== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch updates include/ctf.h to match the current libctf version in binutils' include/. I recently attempted to build a uber tree (following some notes that are so old they used CVS) and noticed that binutils won't build with GCC's top-level include, due to CTF_F_IDXSORTED not being defined in ctf.h. There was also a discrepancy with ansidecl.h but I'm unsure how (best) to resolve that issue. This patch was tested on x86_64-pc-linux-gnu with a make bootstrap and make -k check, both with and without --target_board=unix{-m32}, with no new failures, to confirm that the usage of ctf.h in ctfout.cc and dwarf2ctf.cc is compatible with the new version. Ok for mainline? 2023-04-27 Roger Sayle include/ChangeLog * ctf.h: Import latest version from binutils/libctf. Thanks in advance, Roger diff --git a/include/ctf.h b/include/ctf.h index b867fc5..4263799 100644 --- a/include/ctf.h +++ b/include/ctf.h @@ -1,5 +1,5 @@ /* CTF format description. - Copyright (C) 2021-2023 Free Software Foundation, Inc. + Copyright (C) 2019-2023 Free Software Foundation, Inc. This file is part of libctf. @@ -89,13 +89,13 @@ extern "C" entries and reorder them accordingly (dropping the indexes in the process). Variable records (as distinct from data objects) provide a modicum of support - for non-ELF systems, mapping a variable name to a CTF type ID. The variable - names are sorted into ASCIIbetical order, permitting binary searching. We do - not define how the consumer maps these variable names to addresses or + for non-ELF systems, mapping a variable or function name to a CTF type ID. + The names are sorted into ASCIIbetical order, permitting binary searching. + We do not define how the consumer maps these variable names to addresses or anything else, or indeed what these names represent: they might be names looked up at runtime via dlsym() or names extracted at runtime by a debugger or anything else the consumer likes. Variable records with identically- - named entries in the data object section are removed. + named entries in the data object or function index section are removed. The data types section is a list of variable size records that represent each type, in order by their ID. The types themselves form a directed graph, @@ -132,6 +132,12 @@ extern "C" #define CTF_MAX_SIZE 0xfffffffe /* Max size of a v2 type in bytes. */ #define CTF_LSIZE_SENT 0xffffffff /* Sentinel for v2 ctt_size. */ +# define CTF_MAX_TYPE_V1 0xffff /* Max type identifier value. */ +# define CTF_MAX_PTYPE_V1 0x7fff /* Max parent type identifier value. */ +# define CTF_MAX_VLEN_V1 0x3ff /* Max struct, union, enums or args. */ +# define CTF_MAX_SIZE_V1 0xfffe /* Max size of a type in bytes. */ +# define CTF_LSIZE_SENT_V1 0xffff /* Sentinel for v1 ctt_size. */ + /* Start of actual data structure definitions. Every field in these structures must have corresponding code in the @@ -144,6 +150,20 @@ typedef struct ctf_preamble unsigned char ctp_flags; /* Flags (see below). */ } ctf_preamble_t; +typedef struct ctf_header_v2 +{ + ctf_preamble_t cth_preamble; + uint32_t cth_parlabel; /* Ref to name of parent lbl uniq'd against. */ + uint32_t cth_parname; /* Ref to basename of parent. */ + uint32_t cth_lbloff; /* Offset of label section. */ + uint32_t cth_objtoff; /* Offset of object section. */ + uint32_t cth_funcoff; /* Offset of function section. */ + uint32_t cth_varoff; /* Offset of variable section. */ + uint32_t cth_typeoff; /* Offset of type section. */ + uint32_t cth_stroff; /* Offset of string section. */ + uint32_t cth_strlen; /* Length of string section in bytes. */ +} ctf_header_v2_t; + typedef struct ctf_header { ctf_preamble_t cth_preamble; @@ -182,13 +202,19 @@ typedef struct ctf_header # define CTF_VERSION_1_UPGRADED_3 2 # define CTF_VERSION_2 3 -/* Note: some flags may be valid only in particular format versions. */ - #define CTF_VERSION_3 4 #define CTF_VERSION CTF_VERSION_3 /* Current version. */ -#define CTF_F_COMPRESS 0x1 /* Data buffer is compressed by libctf. */ -#define CTF_F_NEWFUNCINFO 0x2 /* New v3 func info section format. */ +/* All of these flags bar CTF_F_COMPRESS and CTF_F_IDXSORTED are bug-workaround + flags and are valid only in format v3: in v2 and below they cannot occur and + in v4 and later, they will be recycled for other purposes. */ + +#define CTF_F_COMPRESS 0x1 /* Data buffer is compressed by libctf. */ +#define CTF_F_NEWFUNCINFO 0x2 /* New v3 func info section format. */ +#define CTF_F_IDXSORTED 0x4 /* Index sections already sorted. */ +#define CTF_F_DYNSTR 0x8 /* Strings come from .dynstr. */ +#define CTF_F_MAX (CTF_F_COMPRESS | CTF_F_NEWFUNCINFO | CTF_F_IDXSORTED \ + | CTF_F_DYNSTR) typedef struct ctf_lblent { @@ -209,6 +235,52 @@ typedef struct ctf_varent ctf_type_t. Use of this member is indicated by the presence of CTF_LSIZE_SENT in ctt_size. */ +/* In v1, the same applies, only the limit is (USHRT_MAX - 1) and + CTF_MAX_SIZE_V1, and CTF_LSIZE_SENT_V1 is the sentinel. */ + +typedef struct ctf_stype_v1 +{ + uint32_t ctt_name; /* Reference to name in string table. */ + unsigned short ctt_info; /* Encoded kind, variant length (see below). */ +#ifndef __GNUC__ + union + { + unsigned short _size; /* Size of entire type in bytes. */ + unsigned short _type; /* Reference to another type. */ + } _u; +#else + __extension__ + union + { + unsigned short ctt_size; /* Size of entire type in bytes. */ + unsigned short ctt_type; /* Reference to another type. */ + }; +#endif +} ctf_stype_v1_t; + +typedef struct ctf_type_v1 +{ + uint32_t ctt_name; /* Reference to name in string table. */ + unsigned short ctt_info; /* Encoded kind, variant length (see below). */ +#ifndef __GNUC__ + union + { + unsigned short _size; /* Always CTF_LSIZE_SENT_V1. */ + unsigned short _type; /* Do not use. */ + } _u; +#else + __extension__ + union + { + unsigned short ctt_size; /* Always CTF_LSIZE_SENT_V1. */ + unsigned short ctt_type; /* Do not use. */ + }; +#endif + uint32_t ctt_lsizehi; /* High 32 bits of type size in bytes. */ + uint32_t ctt_lsizelo; /* Low 32 bits of type size in bytes. */ +} ctf_type_v1_t; + + typedef struct ctf_stype { uint32_t ctt_name; /* Reference to name in string table. */ @@ -424,6 +496,13 @@ typedef struct ctf_slice unsigned short cts_bits; } ctf_slice_t; +typedef struct ctf_array_v1 +{ + unsigned short cta_contents; /* Reference to type of array contents. */ + unsigned short cta_index; /* Reference to type of array index. */ + uint32_t cta_nelems; /* Number of elements. */ +} ctf_array_v1_t; + typedef struct ctf_array { uint32_t cta_contents; /* Reference to type of array contents. */ @@ -440,6 +519,28 @@ typedef struct ctf_array #define CTF_LSTRUCT_THRESH 536870912 +/* In v1, the same is true, except that lmembers are used for structs >= 8192 + bytes in size. (The ordering of members in the ctf_member_* structures is + different to improve padding.) */ + +#define CTF_LSTRUCT_THRESH_V1 8192 + +typedef struct ctf_member_v1 +{ + uint32_t ctm_name; /* Reference to name in string table. */ + unsigned short ctm_type; /* Reference to type of member. */ + unsigned short ctm_offset; /* Offset of this member in bits. */ +} ctf_member_v1_t; + +typedef struct ctf_lmember_v1 +{ + uint32_t ctlm_name; /* Reference to name in string table. */ + unsigned short ctlm_type; /* Reference to type of member. */ + unsigned short ctlm_pad; /* Padding. */ + uint32_t ctlm_offsethi; /* High 32 bits of member offset in bits. */ + uint32_t ctlm_offsetlo; /* Low 32 bits of member offset in bits. */ +} ctf_lmember_v1_t; + typedef struct ctf_member_v2 { uint32_t ctm_name; /* Reference to name in string table. */ @@ -498,13 +599,13 @@ struct ctf_archive /* Offset of the name table. */ uint64_t ctfa_names; - /* Offset of the CTF table. Each element starts with a size (a uint64_t - in network byte order) then a ctf_dict_t of that size. */ + /* Offset of the CTF table. Each element starts with a size (a little- + endian uint64_t) then a ctf_dict_t of that size. */ uint64_t ctfa_ctfs; }; -/* An array of ctfa_nnamed of this structure lies at - ctf_archive[ctf_archive->ctfa_modents] and gives the ctfa_ctfs or +/* An array of ctfa_ndicts of this structure lies at + ctf_archive[sizeof(struct ctf_archive)] and gives the ctfa_ctfs or ctfa_names-relative offsets of each name or ctf_dict_t. */ typedef struct ctf_archive_modent