From patchwork Thu Dec 12 05:33:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 102832 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BD0513858C35 for ; Thu, 12 Dec 2024 05:35:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD0513858C35 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TJD4IjFM X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id EDF823858C48 for ; Thu, 12 Dec 2024 05:33:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDF823858C48 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EDF823858C48 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733981605; cv=none; b=wB4guZuhRe1tdQNyHENmDNySvvDmtOdjWMfH7p0s8V2TobfKjNnQbSc31Vc8Ok3btbyB5nPAqUOZkS7Tc7dRsW89y9gtu6oXlKn8Xz2XsNfintRYFW+SO5V3PLRutflFfcs/56TiLX/GfeWaBbdApmYBnZKcHrZOi56OipM6Y8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733981605; c=relaxed/simple; bh=ExKXF7xUjXLtlVwALt58/s7WrUX/pBPPMOPOeNwUPfw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=D6RNthu3OCGvGVO0Y2TgN/iAT3Ts2h15pOYX0z753z0k9dUWhBkD0BlUfjJQR2hmnTDaNH9KBcrWFWv8TpaMQ1s55XDtZuQtNyNBfJx8RAJO55puLARKKpX3xfYPkW598FMShkR45ta5ag3tndYt2EIWvvIlQGxBRsrOyXfF9n4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDF823858C48 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-21683192bf9so2031335ad.3 for ; Wed, 11 Dec 2024 21:33:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733981603; x=1734586403; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=3fO4+RpQGjtsZLBBG8cI66wEIxtfDHPL9qc75+JpzWs=; b=TJD4IjFMdiyV5JTxQ3x+9zfo9iFKsexvpzCcpQNZFMSwhowzzpcDY6SOS7YuN7jrKO S+j67lmkBQkfOxuqAbTR6KoGSwANB27Rz5l6vd44H022yi7GnaZiQYlMRzACUMdJHoY1 AOtAMLObNu4NzrEs/IVkqgS2enD9ribeG0M8WF6yw92TlaMTZbYyQYYiSjbiLGSvMMpy UeHnJIBdCo7m8kte2QUVpK6Vdb1B0WL6vCXdzjLeAEuAF9d4XEs1ezAJx+weGcOtqZeI weN3R8AGeJqT2IWem813Pv05DJSAFd4TCOUNNTEDmZ59Nlr8GBPr5q+PYqKNCjvNpGEw D5wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733981603; x=1734586403; 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=3fO4+RpQGjtsZLBBG8cI66wEIxtfDHPL9qc75+JpzWs=; b=wVHhOPBDOkl+vxHgiUWTiP5WCGnaOCYT+aqIHWoUBryQ+GFLMnyUoowIoHFp8ptDIW qDIZOw+xv88Cox17Pe9Mk2NRXEDPFUBDPa9dMGM6H0mMe0RBAzpgxjHJcEV88l1nA85O U/+39gsJqwqG1l4bBXe+nApNPjE/dY4ULSqIBlOBNtUFGxey45Wpoft3XcChyi1MPwNf IM4yn+UVCFl4A1FFbp8Vb9/frKUGn3kqh92L8bTl5mcR5tXrop71tVYs+BbbesfHDybH 3Wn/DKdfQDrc6aOXZwJq04BKu95MeHij2YBl99men6eNaE+Gmnz6ZgSSkTJMkDOciyj5 q0Lw== X-Gm-Message-State: AOJu0YzkowFUAV1av63cvDjhCZLAK0ISOoYFpp9j4zDXEFimU8f+7Uig 59h++bgYqfsjBT6oGwpx76m8gRuOQS3Rk43g8YxakAu2E/nIT+TRE2pq0A== X-Gm-Gg: ASbGnctHQTBdiCgamL0SymToLJlamcv1UtOP2bLaKhDaUtFf2VVj37iM2CIBHePRVC1 UwXfYfHHQK5z55Ty2BexLP+Ac7uEy8nA1UeJp7GlQoLQEJoerZ/Nd0T9iyUcK3nMgiFRgyUg6Sz 5Sl5oX79pjRgs+9xzSQ4QRRVdCVsm9dWGEfxsD8PI+n5YDNKCfYNPAC/R0vfWnVmz3uEeOH06sw tLRo+gxJEm4VAA/34Uk2Ae9sWNtgJh0f4vuQDvOYC6+rvpdg7Pl1jBUjPL6UGqpud3QCg== X-Google-Smtp-Source: AGHT+IH1Af31uUFM+/hfKImm6B9pyNyUWxzCFvS3bbnwnTeVeh8hZa5wCZc6DJofgHjqitzggcIBxw== X-Received: by 2002:a17:903:2b0b:b0:216:69ca:7707 with SMTP id d9443c01a7336-2177851dbc7mr89848405ad.30.1733981603562; Wed, 11 Dec 2024 21:33:23 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:4d08:cebd:d73f:b794]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-216432f3809sm67218505ad.153.2024.12.11.21.33.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 21:33:23 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id CE1E811424B1; Thu, 12 Dec 2024 16:03:20 +1030 (ACDT) Date: Thu, 12 Dec 2024 16:03:20 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Use bfd id to validate dwarf2 cache Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3032.1 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.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org Using a bfd pointer to validate the cache isn't very robust. If a bfd is closed somehow without clearing the cache, then it's possible that another bfd is opened using the same memory and thus orig_bfd compares equal to the new bfd. * dwarf2.c (struct dwarf2_debug): Add orig_bfd_id. Delete orig_bfd. (_bfd_dwarf2_slurp_debug_info): Validate stash with orig_bfd_id. diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 151ed0237ca..e93a331c5b4 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -292,12 +292,6 @@ struct dwarf2_debug /* Per-file stuff. */ struct dwarf2_debug_file f, alt; - /* Pointer to the original bfd for which debug was loaded. This is what - we use to compare and so check that the cached debug data is still - valid - it saves having to possibly dereference the gnu_debuglink each - time. */ - bfd *orig_bfd; - /* If the most recent call to bfd_find_nearest_line was given an address in an inlined function, preserve a pointer into the calling chain for subsequent calls to bfd_find_inliner_info to @@ -315,6 +309,9 @@ struct dwarf2_debug /* Array of sections with adjusted VMA. */ struct adjusted_section *adjusted_sections; + /* Used to validate the cached debug data. */ + unsigned int orig_bfd_id; + /* Number of times find_line is called. This is used in the heuristic for enabling the info hash tables. */ int info_hash_count; @@ -5401,7 +5398,7 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd, if (stash != NULL) { - if (stash->orig_bfd == abfd + if (stash->orig_bfd_id == abfd->id && section_vma_same (abfd, stash)) { /* Check that we did previously find some debug information @@ -5425,7 +5422,7 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd, return false; *pinfo = stash; } - stash->orig_bfd = abfd; + stash->orig_bfd_id = abfd->id; stash->debug_sections = debug_sections; stash->f.syms = symbols; if (!save_section_vma (abfd, stash))