From patchwork Wed Feb 15 02:34:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 57344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3325381wrn; Tue, 14 Feb 2023 18:35:33 -0800 (PST) X-Google-Smtp-Source: AK7set9VNgqKwFSZ+zgcANRFjGxz6vdBD+hhLDql4w4H3n5bTj2gDM6pLKHYGsLTq9R+0UIHLiZW X-Received: by 2002:a17:906:a84a:b0:8af:370b:da59 with SMTP id dx10-20020a170906a84a00b008af370bda59mr596870ejb.17.1676428532901; Tue, 14 Feb 2023 18:35:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676428532; cv=none; d=google.com; s=arc-20160816; b=atlpbZ5KlJwdMx2njvHxBNH42bVtMGWgKG9wRL8Xe6IsJf0IRWIEgmcaEksEuFIjHf chMFtqkxT5xHiy3r3ERtghcMtbvTYFeSY+nYt82f9+t/1Er2DyNK2xYJs3/jLqGe5VF9 ZX/oGK3JxvxL8tXh2qCLOwgyzPhwA2B13/n790hQck/nfoXoA+kRxAHjqPvpthtnTpKA be+c9apT1eQMaEpvwS1G+huiCuguZRnJCVrVg8rT7w3TFEzPVBpdphUPgSCqLQsl3yhC dLmyPxSj1Q/ZNa2C8Lfft3E0Ip3Tr7rse0/mhMMX5IxJTxsLJFwIMpqVafRNhBa8sS+x rlRg== 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=g9+/K94C/2Qk7E8Y42cNPh/71XIvqLMUqO96aEhK3MA=; b=DxLPzjTzglxJ1BD9Obrue7VwcAhtheK3AWioDpEiim1S4NYVQm+FkQ8vS/DTLyYMYe 3iDZRAG4zRmHHmw/Wr0xKHPwckpEW9exPtbm5grSNUqL+1abprXWSl5ci7f4GJbS3WeR Lj69o+UKSrEDLiP8yTwkSpmmTKw/rb4zdEz/woWrNIicUVSdlnrFE5s4thGr9XVAbmWf 8aoGr71emwYGtMrMa8EP8DT1VdVOUGWRtEhjEBXvKHBxmD2q5wfBgYku5AYOzhjt3Dkf 7QvtA/caOG+nqcNOwQFt6TdY6vrnuee/I30hhIh+tMqt4Yx63WH2UbwqgjZ9No0KsDXD W/Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=W6XjuEwH; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id eu16-20020a170907299000b008b123fe4f19si4936057ejc.984.2023.02.14.18.35.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 18:35:32 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=W6XjuEwH; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 8BC483858C2C for ; Wed, 15 Feb 2023 02:35:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8BC483858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676428531; bh=g9+/K94C/2Qk7E8Y42cNPh/71XIvqLMUqO96aEhK3MA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=W6XjuEwHYEUuKfeie+FznrDcxMHC1uuFO4M/gYil5ZuP6+oEwQH0EwJXlvoXf9w+8 dTFY4fxKyvb+Y4J/bm/hqSZchE38OREeo4GVCJuvgAE6sjnt85EUllNOtDMujtiwo/ 88P6TKdKKRiejcN3sElKvS77uMsuVeXxpc72LGOo= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 46F2E3858CDB for ; Wed, 15 Feb 2023 02:35:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46F2E3858CDB Received: by mail-pj1-x102e.google.com with SMTP id d8-20020a17090ad98800b002344fa17c8bso605793pjv.5 for ; Tue, 14 Feb 2023 18:35:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=g9+/K94C/2Qk7E8Y42cNPh/71XIvqLMUqO96aEhK3MA=; b=JmEHR4+TIE1N8gLNbAc2q93SpF81o6xrFfQlb6AGTTYseUf0R9l7Yg9u+B162m6y6S iXqYr396UUOMkAuop1YXZuLBJIdduYOy8YesmaAsbkLlTvrM3DNXktgINkIxgmdaed/2 dGsToC95pg2dmDGRBjZGvSOw1wMLmT2f3a/53WJTHQNUkayq61hT9VSAm4vfPhHubCBq k0XM8M5tcuqwyaUbRLWZpMMlkaCkouFwPYzHn0d6LqUVGFjSLz/YL0DgFhHOiEuoVTr5 WRFEqGMq0s3wguhS2IfbQ0onl+av5f+p393Pv+L/mmkgeO1issNLnsvKLFnfcV6vtUMU /dQg== X-Gm-Message-State: AO0yUKXbhBC9Hc+us4SvhRCL2duNx7Bnf4Ps1WzH5KERH0c6h+13h7Bm iuK36GDIjKdSddx+aIpwNfkGcSRtQ4c= X-Received: by 2002:a17:902:e80b:b0:199:5111:9987 with SMTP id u11-20020a170902e80b00b0019951119987mr1902564plg.32.1676428499903; Tue, 14 Feb 2023 18:34:59 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id e20-20020a170902ed9400b0019a6e9ae01csm9195124plj.21.2023.02.14.18.34.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 18:34:59 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id E794B1140749; Wed, 15 Feb 2023 13:04:56 +1030 (ACDT) Date: Wed, 15 Feb 2023 13:04:56 +1030 To: binutils@sourceware.org Subject: binutils stabs type list Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.5 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?1757862725480337497?= X-GMAIL-MSGID: =?utf-8?q?1757862725480337497?= Fuzzers have found that specifying a large stab type number results in lots of memory being requested, as the list is extended with a 16 element array at a time until we reach the given stab type. It also takes a long time. Of course normal sane stab types use small positive integers, but it's not hard to modify the code to handle type numbers starting anyhere. * stabs.c (struct stab_types): Add base_index. (stab_find_slot): Simplify filenum check. Delete type number check. Don't allocate entire array from 0 to type number, allocate a sparse array. diff --git a/binutils/stabs.c b/binutils/stabs.c index 5b0249bdc10..85eebebafdd 100644 --- a/binutils/stabs.c +++ b/binutils/stabs.c @@ -121,6 +121,8 @@ struct stab_types { /* Next set of slots for this file. */ struct stab_types *next; + /* Where the TYPES array starts. */ + unsigned int base_index; /* Types indexed by type number. */ #define STAB_TYPES_SLOTS (16) debug_type types[STAB_TYPES_SLOTS]; @@ -3413,40 +3415,32 @@ stab_emit_pending_vars (void *dhandle, struct stab_handle *info) static debug_type * stab_find_slot (struct stab_handle *info, const int *typenums) { - int filenum; - int tindex; + unsigned int filenum; + unsigned int tindex; + unsigned int base_index; struct stab_types **ps; filenum = typenums[0]; tindex = typenums[1]; - if (filenum < 0 || (unsigned int) filenum >= info->files) + if (filenum >= info->files) { fprintf (stderr, _("Type file number %d out of range\n"), filenum); return NULL; } - if (tindex < 0) - { - fprintf (stderr, _("Type index number %d out of range\n"), tindex); - return NULL; - } ps = info->file_types + filenum; + base_index = tindex / STAB_TYPES_SLOTS * STAB_TYPES_SLOTS; + tindex -= base_index; + while (*ps && (*ps)->base_index < base_index) + ps = &(*ps)->next; - while (tindex >= STAB_TYPES_SLOTS) - { - if (*ps == NULL) - { - *ps = (struct stab_types *) xmalloc (sizeof **ps); - memset (*ps, 0, sizeof **ps); - } - ps = &(*ps)->next; - tindex -= STAB_TYPES_SLOTS; - } - if (*ps == NULL) + if (*ps == NULL || (*ps)->base_index != base_index) { - *ps = (struct stab_types *) xmalloc (sizeof **ps); - memset (*ps, 0, sizeof **ps); + struct stab_types *n = xcalloc (1, sizeof (*n)); + n->next = *ps; + n->base_index = base_index; + *ps = n; } return (*ps)->types + tindex;