From patchwork Fri Mar 3 03:47:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 63750 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp207371wrd; Thu, 2 Mar 2023 19:47:29 -0800 (PST) X-Google-Smtp-Source: AK7set8orjfc+RCa2HxvQYmX/5Tru9bFXokEZnqPfeV20sOMSrdDNvgDZVetukSLqAN32t+uE1WT X-Received: by 2002:a17:907:1c15:b0:8af:2fa1:2226 with SMTP id nc21-20020a1709071c1500b008af2fa12226mr235767ejc.6.1677815249355; Thu, 02 Mar 2023 19:47:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677815249; cv=none; d=google.com; s=arc-20160816; b=cqon5v/7mnNty2X2MN9jmrptgi1HdAFXHs7d09VN7d2q18o3LtXQ9LCeQlfyOVpGJd U39+kDPJqmfLe/MRjbNBHulwTPVshskz/mxkX4nUwoJ+X+MURvmesrgBj8kCjTb/dk2G lcENDRkQumDB9fs91oQg5InoSySU75lnbP4jnT1Z2FwvXEVM9ylbFn9331sOzoh7lzSh UupHlrQs0U+3mOlH2cq9gCp8KPhD3Hwlu4FIEucbfiDAMFn5FCNFkucP8vSMwmoOwswg 2dAGF3/QdhoZFgjuTLTIz17b//hST7QEE01T7sPRCB273jz8MWQ430fnJ+LnP7oRsyu4 xFkw== 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 :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=920hMTWam8S50E90worOwiidP4eKHfWHH9NDwUpt0QI=; b=CQymoeESzTP7yLsrth/U57zy5Ud8+7Pg1rcS+JcuMHEYeSFBkj8cGU341PacrTeUxl DH2ovEWk3B+ZSj/i5hSfnNOiaDxc3+hJoeVE+1QCyvDyInEJ+9pB3NZ6FhO9d8f5l5pi LB8zT4kJM0ixOy3fjI8DYgZ0TjYEJ79tHBTxPf/YmFBP3yExDH/m0SiZwV1Z2/HGz21N a88PRKYiIqXbaY7VC7AL1JL5NNmIzjwq2v4gMSKOfekjWNI76B8lu8k7wr8mdy9IXQ4/ rUFYXMqXlK989twlxP2sMJo6lnKzInQx62i52lZz8N8CqKC3j7ZsLLhrTaNYic667w62 yLsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=p09livgB; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id nc42-20020a1709071c2a00b008de4a641fdcsi1411371ejc.760.2023.03.02.19.47.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 19:47:29 -0800 (PST) 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=p09livgB; 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 CDDC63857B8E for ; Fri, 3 Mar 2023 03:47:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CDDC63857B8E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677815244; bh=920hMTWam8S50E90worOwiidP4eKHfWHH9NDwUpt0QI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=p09livgBCrYYDcEnMEenbAp8UZV3OcXZ8JeVE4VKVSBBjeWC48FE3NdwSHnu5KrI9 ZrQz2RIJdolBpWpa7RSSgNliDfqhwU3gNAbkHK9NEBKzfdAEJyI0uo+iX79rVtqK6a ntxnVG1z+g3BpYRfFmzVOMZ2M8D8l718O1W6B0YI= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id ACF7B385840C for ; Fri, 3 Mar 2023 03:47:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACF7B385840C Received: by mail-pj1-x102c.google.com with SMTP id l1so1258267pjt.2 for ; Thu, 02 Mar 2023 19:47:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677815234; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=920hMTWam8S50E90worOwiidP4eKHfWHH9NDwUpt0QI=; b=C9W1Ev/H7EYtUz03rUWtFXQfK7lC+gPrYGmddNFAfzUdyZVKbt3P3GHaPJXxEhsQaJ dUoaMEyEMvfwEl9h9TQcDaOW0PuQqjMwpe/k/g8diqgqRHzaYTVOhHtxGK095pdP74yB 2xObgifflDJWaY8iwEfSRvVsCAlvTOFQdhj3DJIt4zaI/8lFq09hyABkyawdMUUgC0K8 +QvYtRTpDwWnNdEucfoOIQUovRD//rg14oGPkum70x1ILq0dCowKCD+cryoGeDQD5CHf 51pOeJtq/xZPuckonU9iXsZIHydq0dAHRQm/RbIlajLhabMhK0fijSlGKD8sxTvXBcfh B1kg== X-Gm-Message-State: AO0yUKWIuS2lNQUiSfuwkvknF60QX0nos+XB50qcC9TsXg6wMbld+Qgr TgnLOMHn8QRiy6etK8B0NLm0ZvOrwCA= X-Received: by 2002:a17:902:c412:b0:19c:be03:d18b with SMTP id k18-20020a170902c41200b0019cbe03d18bmr696337plk.22.1677815234133; Thu, 02 Mar 2023 19:47:14 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:9d58:af40:9a5d:9a54]) by smtp.gmail.com with ESMTPSA id kv4-20020a17090328c400b0019bd934434esm413220plb.53.2023.03.02.19.47.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 19:47:13 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id C2A2F1142CC6; Fri, 3 Mar 2023 14:17:11 +1030 (ACDT) Date: Fri, 3 Mar 2023 14:17:11 +1030 To: binutils@sourceware.org Subject: Tidy type handling in binutils/rdcoff.c Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: 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: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra 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?1759316802489194291?= X-GMAIL-MSGID: =?utf-8?q?1759316802489194291?= There isn't really any good reason for code in rdcoff.c to distinguish between "basic" types and any other type. This patch dispenses with the array reserved for basic types and instead handles all types using coff_get_slot, simplifying the code. * rdcoff.c (struct coff_types, coff_slots): Merge. Delete coff_slots. (T_MAX): Delete. (parse_coff_base_type): Use coff_get_slot to store baseic types. (coff_get_slot, parse_coff_type, parse_coff_base_type), (parse_coff_struct_type, parse_coff_enum_type), (parse_coff_symbol, parse_coff): Pass types as coff_types**. diff --git a/binutils/rdcoff.c b/binutils/rdcoff.c index 1a4f00da913..4d18d47ca11 100644 --- a/binutils/rdcoff.c +++ b/binutils/rdcoff.c @@ -58,82 +58,58 @@ struct coff_symbols long coff_symno; }; -/* The largest basic type we are prepared to handle. */ - -#define T_MAX (T_LNGDBL) - -/* This structure is used to hold slots. */ +/* This structure is used to map symbol indices to types. */ -struct coff_slots +struct coff_types { /* Next set of slots. */ - struct coff_slots *next; - /* Where the SLOTS array starts. */ + struct coff_types *next; + /* Where the TYPES array starts. */ unsigned int base_index; /* Slots. */ #define COFF_SLOTS (16) - debug_type slots[COFF_SLOTS]; + debug_type types[COFF_SLOTS]; }; -/* This structure is used to map symbol indices to types. */ - -struct coff_types -{ - /* Slots. */ - struct coff_slots *slots; - /* Basic types. */ - debug_type basic[T_MAX + 1]; -}; - -static debug_type *coff_get_slot (struct coff_types *, long); -static debug_type parse_coff_type - (bfd *, struct coff_symbols *, struct coff_types *, long, int, - union internal_auxent *, bool, void *); static debug_type parse_coff_base_type - (bfd *, struct coff_symbols *, struct coff_types *, long, int, + (bfd *, struct coff_symbols *, struct coff_types **, long, int, union internal_auxent *, void *); static debug_type parse_coff_struct_type - (bfd *, struct coff_symbols *, struct coff_types *, int, + (bfd *, struct coff_symbols *, struct coff_types **, int, union internal_auxent *, void *); static debug_type parse_coff_enum_type - (bfd *, struct coff_symbols *, struct coff_types *, + (bfd *, struct coff_symbols *, struct coff_types **, union internal_auxent *, void *); -static bool parse_coff_symbol - (bfd *, struct coff_types *, asymbol *, long, struct internal_syment *, - void *, debug_type, bool); -static bool external_coff_symbol_p (int sym_class); /* Return the slot for a type. */ static debug_type * -coff_get_slot (struct coff_types *types, long indx) +coff_get_slot (struct coff_types **types, long indx) { - struct coff_slots **pps; unsigned int base_index; - pps = &types->slots; base_index = indx / COFF_SLOTS * COFF_SLOTS; indx -= base_index; - while (*pps && (*pps)->base_index < base_index) - pps = &(*pps)->next; + while (*types && (*types)->base_index < base_index) + types = &(*types)->next; - if (*pps == NULL || (*pps)->base_index != base_index) + if (*types == NULL || (*types)->base_index != base_index) { - struct coff_slots *n = xcalloc (1, sizeof (*n)); - n->next = *pps; + struct coff_types *n = xcalloc (1, sizeof (*n)); + n->next = *types; n->base_index = base_index; - *pps = n; + *types = n; } - return (*pps)->slots + indx; + return (*types)->types + indx; } /* Parse a COFF type code in NTYPE. */ static debug_type parse_coff_type (bfd *abfd, struct coff_symbols *symbols, - struct coff_types *types, long coff_symno, int ntype, + struct coff_types **types, long coff_symno, int ntype, union internal_auxent *pauxent, bool useaux, void *dhandle) { @@ -230,21 +206,11 @@ parse_coff_type (bfd *abfd, struct coff_symbols *symbols, static debug_type parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols, - struct coff_types *types, long coff_symno, int ntype, + struct coff_types **types, long coff_symno, int ntype, union internal_auxent *pauxent, void *dhandle) { debug_type ret; - bool set_basic; - const char *name; - debug_type *slot; - - if (ntype >= 0 - && ntype <= T_MAX - && types->basic[ntype] != DEBUG_TYPE_NULL) - return types->basic[ntype]; - - set_basic = true; - name = NULL; + const char *name = NULL; switch (ntype) { @@ -321,11 +287,6 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols, else ret = parse_coff_struct_type (abfd, symbols, types, ntype, pauxent, dhandle); - - slot = coff_get_slot (types, coff_symno); - *slot = ret; - - set_basic = false; break; case T_UNION: @@ -334,11 +295,6 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols, else ret = parse_coff_struct_type (abfd, symbols, types, ntype, pauxent, dhandle); - - slot = coff_get_slot (types, coff_symno); - *slot = ret; - - set_basic = false; break; case T_ENUM: @@ -347,21 +303,14 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols, (bfd_signed_vma *) NULL); else ret = parse_coff_enum_type (abfd, symbols, types, pauxent, dhandle); - - slot = coff_get_slot (types, coff_symno); - *slot = ret; - - set_basic = false; break; } if (name != NULL) ret = debug_name_type (dhandle, name, ret); - if (set_basic - && ntype >= 0 - && ntype <= T_MAX) - types->basic[ntype] = ret; + debug_type *slot = coff_get_slot (types, coff_symno); + *slot = ret; return ret; } @@ -370,7 +319,7 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols, static debug_type parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols, - struct coff_types *types, int ntype, + struct coff_types **types, int ntype, union internal_auxent *pauxent, void *dhandle) { long symend; @@ -479,7 +428,7 @@ parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols, static debug_type parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols, - struct coff_types *types ATTRIBUTE_UNUSED, + struct coff_types **types ATTRIBUTE_UNUSED, union internal_auxent *pauxent, void *dhandle) { long symend; @@ -549,7 +498,7 @@ parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols, /* Handle a single COFF symbol. */ static bool -parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types *types, +parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types **types, asymbol *sym, long coff_symno, struct internal_syment *psyment, void *dhandle, debug_type type, bool within_function) @@ -657,8 +606,7 @@ bool parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle) { struct coff_symbols symbols; - struct coff_types types; - int i; + struct coff_types *types; long next_c_file; const char *fnname; int fnclass; @@ -673,9 +621,7 @@ parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle) symbols.symno = 0; symbols.coff_symno = 0; - types.slots = NULL; - for (i = 0; i <= T_MAX; i++) - types.basic[i] = DEBUG_TYPE_NULL; + types= NULL; next_c_file = -1; fnname = NULL;