From patchwork Sat Mar 20 16:26:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 1456155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=PT67lMud; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2mR42FSnz9sW4 for ; Sun, 21 Mar 2021 03:28:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 96F6F3870860; Sat, 20 Mar 2021 16:27:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 818EF385803D for ; Sat, 20 Mar 2021 16:27:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 818EF385803D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=harmstone.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mark.harmstone@gmail.com Received: by mail-wm1-x330.google.com with SMTP id z6-20020a1c4c060000b029010f13694ba2so6817531wmf.5 for ; Sat, 20 Mar 2021 09:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LOHkWADY9YzOUEbSqd/holjMZYB3KYH9efxvD1/viMg=; b=PT67lMud5EzCCG/aANpCtn/DqA0OW5yB4/ZfROitDCpkR/UGcF/NxOivxJ1L54Se4j QhI1RS9zDokPZHDuK3pr0scyY0eKlgijVyW069cT1J6k85kdyiVh7NTU42jxHi155nfQ 30X/bIp/5ptlmwIMiFlr3VITXrMIJMBsdONo6dEi14kPjiHcBn2xNgZWd+iK/D5Z1JgL yRo+aHvMMNm3IBOeuK9kVt0gUHRloqHYKNC3SJSuDZXTRwydlzl2UwTiwNEocN+PLXwD P06cSm737ZVVQ3cV5qDlM3e1TDzSdlfHwtHq/rcA9yNWUM4wHIrfbo5yD8hQGUr02YtY J8Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=LOHkWADY9YzOUEbSqd/holjMZYB3KYH9efxvD1/viMg=; b=f5lXLkspE+WHxVAttdOeOu4QSn3rfIfgTzyhQW0LlfJNdQmZaDTTWdowqWJDc/6L8F Ua+h6ViVRBRdGipj93exg2S6dC4XnFsgfzfIwCjuhez+A+eod0sXn29+xkUROaBd8mUs mo8Ui5r5GeFY/GAjmExtgO17cj0s3Cse+ScwXJwYmW1A9loLoJYWPDyuUG4PL0EoOSb8 RTECWpmmfG93znBRO6GsBGD9Hg55AlxD3Y2TjiRa3eWunOtPymONBV0lB3Kuz7dpeIgA z/xfV+zbtrw9ocjVSefmK9+ciPGa/5JmgTWmJZY6iNY/pd2Bh34dCjcekVrG3OjdyXXD ulHA== X-Gm-Message-State: AOAM5333fynY4R9G4c8jX1JZa2e7Y+Uv90LaakjfEk3sSMxcyRmLkoGK SU48/2ciLxRXVtx3kUTv172PBP/xnKk= X-Google-Smtp-Source: ABdhPJw1zPHFrsMt/z81sr/MoynheMVMuQrJ8MAJU2+n7xjJIg+uqq0guHlN3TYhUKfKRxYOCr0Ndw== X-Received: by 2002:a1c:f406:: with SMTP id z6mr8708521wma.24.1616257637145; Sat, 20 Mar 2021 09:27:17 -0700 (PDT) Received: from localhost.localdomain ([2a02:8010:64ea:0:fad1:11ff:fead:57db]) by smtp.gmail.com with ESMTPSA id v18sm14200785wrf.41.2021.03.20.09.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 09:27:16 -0700 (PDT) From: Mark Harmstone To: gcc-patches@gcc.gnu.org Subject: [PATCH 21/24] pdbout: Don't output unused types. Date: Sat, 20 Mar 2021 16:26:49 +0000 Message-Id: <20210320162652.23346-21-mark@harmstone.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210320162652.23346-1-mark@harmstone.com> References: <20210320162652.23346-1-mark@harmstone.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Mark Harmstone Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" --- gcc/pdbout.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++- gcc/pdbout.h | 1 + 2 files changed, 254 insertions(+), 3 deletions(-) diff --git a/gcc/pdbout.c b/gcc/pdbout.c index 8dbd8f58a87..3d15c620db5 100644 --- a/gcc/pdbout.c +++ b/gcc/pdbout.c @@ -1438,7 +1438,8 @@ write_type (struct pdb_type *t) } } -/* Output the .debug$T section, which contains all the types used. */ +/* Output the .debug$T section, which contains all the types used. + * Types defined but not used will not be output. */ static void write_pdb_type_section (void) { @@ -1450,7 +1451,8 @@ write_pdb_type_section (void) n = types; while (n) { - write_type (n); + if (n->used) + write_type (n); n = n->next; } @@ -1476,6 +1478,227 @@ write_pdb_type_section (void) } } +/* Loop through our list of types. If a type is marked as used but a type + * it refers to isn't, marked that type as used too. */ +static void +mark_referenced_types_used (void) +{ + struct pdb_type *t; + bool changed; + + do + { + changed = false; + + t = types; + while (t) + { + if (!t->used) + { + t = t->next; + continue; + } + + if (t->udt_src_line && !t->udt_src_line->used) + { + t->udt_src_line->used = true; + changed = true; + } + + switch (t->cv_type) + { + case LF_MODIFIER: + { + struct pdb_modifier *mod = (struct pdb_modifier *) t->data; + + if (mod->type && !mod->type->used) + { + mod->type->used = true; + changed = true; + } + + break; + } + + case LF_POINTER: + { + struct pdb_pointer *ptr = (struct pdb_pointer *) t->data; + + if (ptr->type && !ptr->type->used) + { + ptr->type->used = true; + changed = true; + } + + break; + } + + case LF_PROCEDURE: + { + struct pdb_proc *proc = (struct pdb_proc *) t->data; + + if (proc->arg_list && !proc->arg_list->used) + { + proc->arg_list->used = true; + changed = true; + } + + if (proc->return_type && !proc->return_type->used) + { + proc->return_type->used = true; + changed = true; + } + + break; + } + + case LF_ARGLIST: + { + struct pdb_arglist *al = (struct pdb_arglist *) t->data; + + for (unsigned int i = 0; i < al->count; i++) + { + if (al->args[i] && !al->args[i]->used) + { + al->args[i]->used = true; + changed = true; + } + } + + break; + } + + case LF_FIELDLIST: + { + struct pdb_fieldlist *fl = (struct pdb_fieldlist *) t->data; + + for (unsigned int i = 0; i < fl->count; i++) + { + if (fl->entries[i].type && !fl->entries[i].type->used) + { + fl->entries[i].type->used = true; + changed = true; + } + } + + break; + } + + case LF_BITFIELD: + { + struct pdb_bitfield *bf = (struct pdb_bitfield *) t->data; + + if (bf->underlying_type && !bf->underlying_type->used) + { + bf->underlying_type->used = true; + changed = true; + } + + break; + } + + case LF_ARRAY: + { + struct pdb_array *arr = (struct pdb_array *) t->data; + + if (arr->type && !arr->type->used) + { + arr->type->used = true; + changed = true; + } + + if (arr->index_type && !arr->index_type->used) + { + arr->index_type->used = true; + changed = true; + } + + break; + } + + case LF_CLASS: + case LF_STRUCTURE: + case LF_UNION: + { + struct pdb_struct *str = (struct pdb_struct *) t->data; + + if (str->field_type && !str->field_type->used) + { + str->field_type->used = true; + changed = true; + } + + // forward declarations should propagate usedness + // to actual types + if (str->property.s.fwdref && str->name) + { + struct pdb_type *t2 = struct_types; + + while (t2) + { + if (t2->cv_type == t->cv_type) + { + struct pdb_struct *str2 = + (struct pdb_struct *) t2->data; + + if (!str2->property.s.fwdref && str2->name + && !strcmp (str->name, str2->name)) + { + if (!t2->used) + { + t2->used = true; + changed = true; + } + + break; + } + } + + t2 = t2->next2; + } + } + + break; + } + + case LF_ENUM: + { + struct pdb_enum *en = (struct pdb_enum *) t->data; + + if (en->type && !en->type->used) + { + en->type->used = true; + changed = true; + } + + if (en->field_type && !en->field_type->used) + { + en->field_type->used = true; + changed = true; + } + + break; + } + + case LF_UDT_SRC_LINE: + { + struct pdb_udt_src_line *pusl = + (struct pdb_udt_src_line *) t->data; + + if (pusl->source_file && !pusl->source_file->used) + { + pusl->source_file->used = true; + changed = true; + } + } + } + + t = t->next; + } + } + while (changed); +} + /* Loop through our types and assign them sequential numbers. */ static void number_types (void) @@ -1486,7 +1709,7 @@ number_types (void) t = types; while (t) { - if (t->id != 0) + if (!t->used || t->id != 0) { t = t->next; continue; @@ -1535,6 +1758,8 @@ number_types (void) static void pdbout_finish (const char *filename ATTRIBUTE_UNUSED) { + mark_referenced_types_used (); + number_types (); write_pdb_section (); @@ -2014,6 +2239,9 @@ pdbout_begin_function (tree func) f->block.num = 0; f->block.children = f->block.last_child = NULL; + if (f->type) + f->type->used = true; + funcs = f; cur_func = f; @@ -2053,6 +2281,9 @@ pdbout_late_global_decl (tree var) v->public_flag = TREE_PUBLIC (var); v->type = find_type (TREE_TYPE (var)); + if (v->type) + v->type->used = true; + global_vars = v; } @@ -2085,6 +2316,7 @@ find_type_bitfield (struct pdb_type *underlying_type, unsigned int size, type->tree = NULL; type->next = type->next2 = NULL; type->id = 0; + type->used = false; type->udt_src_line = NULL; bf = (struct pdb_bitfield *) type->data; @@ -2138,6 +2370,7 @@ add_struct_forward_declaration (tree t, const char *name) strtype->tree = NULL; strtype->next = strtype->next2 = NULL; strtype->id = 0; + strtype->used = false; strtype->udt_src_line = NULL; str = (struct pdb_struct *) strtype->data; @@ -2253,6 +2486,7 @@ add_type_fieldlist (struct pdb_type *t) t->next = t->next2 = NULL; t->id = 0; + t->used = false; t->udt_src_line = NULL; if (last_entry) @@ -2518,6 +2752,7 @@ find_type_struct (tree t, bool is_union) strtype->next = strtype->next2 = NULL; strtype->id = 0; + strtype->used = false; strtype->udt_src_line = NULL; str = (struct pdb_struct *) strtype->data; @@ -2599,6 +2834,7 @@ find_type_array (tree t) arrtype->tree = t; arrtype->next = arrtype->next2 = NULL; arrtype->id = 0; + arrtype->used = false; arrtype->udt_src_line = NULL; arr = (struct pdb_array *) arrtype->data; @@ -2668,6 +2904,7 @@ add_arglist_type (struct pdb_type *t) t->next = NULL; t->next2 = NULL; + t->used = false; t->udt_src_line = NULL; t->id = 0; @@ -2787,6 +3024,7 @@ find_type_enum (tree t) enumtype->tree = t; enumtype->next = enumtype->next2 = NULL; enumtype->id = 0; + enumtype->used = false; enumtype->udt_src_line = NULL; en = (struct pdb_enum *) enumtype->data; @@ -2861,6 +3099,7 @@ find_type_pointer (tree t) ptrtype->tree = t; ptrtype->next = ptrtype->next2 = NULL; ptrtype->id = 0; + ptrtype->used = false; ptrtype->udt_src_line = NULL; ptr = (struct pdb_pointer *) ptrtype->data; @@ -2989,6 +3228,7 @@ find_type_function (tree t) proctype->tree = t; proctype->next = proctype->next2 = NULL; proctype->id = 0; + proctype->used = false; proctype->udt_src_line = NULL; proc = (struct pdb_proc *) proctype->data; @@ -3055,6 +3295,7 @@ find_type_modifier (tree t) type->tree = t; type->next = type->next2 = NULL; type->id = 0; + type->used = false; type->udt_src_line = NULL; mod = (struct pdb_modifier *) type->data; @@ -3103,6 +3344,7 @@ add_builtin_type (tree t, uint16_t id) type->tree = t; type->next = type->next2 = NULL; type->id = id; + type->used = false; type->udt_src_line = NULL; if (last_type) @@ -3418,6 +3660,7 @@ add_string_type (const char *s) type->cv_type = LF_STRING_ID; type->tree = NULL; type->next = type->next2 = NULL; + type->used = false; type->udt_src_line = NULL; type->id = 0; @@ -3455,6 +3698,7 @@ add_udt_src_line_type (struct pdb_type *ref_type, type->cv_type = LF_UDT_SRC_LINE; type->tree = NULL; type->next = type->next2 = NULL; + type->used = false; type->udt_src_line = NULL; type->id = 0; @@ -4802,6 +5046,9 @@ pdbout_function_decl_block (tree block) add_local (IDENTIFIER_POINTER (DECL_NAME (f)), f, type, DECL_RTL (f), BLOCK_NUMBER (block)); + + if (type) + type->used = true; } f = TREE_CHAIN (f); @@ -4835,6 +5082,9 @@ pdbout_function_decl (tree decl) add_local (IDENTIFIER_POINTER (DECL_NAME (f)), f, type, DECL_RTL (f), 0); + + if (type) + type->used = true; } f = TREE_CHAIN (f); diff --git a/gcc/pdbout.h b/gcc/pdbout.h index 2b97ac83999..5390fdb0f95 100644 --- a/gcc/pdbout.h +++ b/gcc/pdbout.h @@ -286,6 +286,7 @@ struct pdb_type uint16_t id; tree_node *tree; uint16_t cv_type; + bool used; struct pdb_type *udt_src_line; uint8_t data[1]; };