From patchwork Mon Nov 27 17:56:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 80838 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 D3D7C3858004 for ; Mon, 27 Nov 2023 17:57:26 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8EC36386186D for ; Mon, 27 Nov 2023 17:56:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EC36386186D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8EC36386186D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701107782; cv=none; b=RUP6Zu8UkxbO8wWhpxYm83cxcv8b1yYi6JGiV/RgrtwUeQP40CdZI+yFP/A7GhCMOvfkdyLHCyW46UC90T4aLVDIRNTl8otFuT0j+xa1PM5BIgUJ8rsLiHgFnxpCiwcFa/djec+7Jm9y1DAuFcGLRukZCpKnPD/C/DPHWG1gXI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701107782; c=relaxed/simple; bh=2O5xRD6HL9Ddz8HN9XPMSnjGVvSi3aVbvmlkG5fyn4c=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Q2ukAKrkD2beWTS0BFb2md+ZgRl2eeGdefXrsT7vSJuQ2Hv8ypzFzyFPrcD2DTlpqIvBmXXT0MTV5uv1tly6GlMBWqU02KKQtXi7WacD6w2I3TL4YHdsjQFTue6vKhs1rdgXDAAory9Sjgy+IrExG0djJuM1icT5YY/BWBHZFVI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701107780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dPZIjdABIZddpTNSfTlxpxAKUKtwyx1yxFnwVeAxVeY=; b=bReDDgI61LfXN+dT2/4GhpGk/ybb1esv1yhI4U81W4pi+neEoiLCSYcq1KD4tSS4HbwITt xcq940+pBbgjm5LwXjMmPYs2/saAaUUtM3zKgwl2pUioU8UO6GKwCtY78OLmATYCAfpuTk KYI00qdmFVPBUW6WecrvMK/QziM7h4o= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-15-rZRJq3VsM1uAEcQP7rBMtw-1; Mon, 27 Nov 2023 12:56:14 -0500 X-MC-Unique: rZRJq3VsM1uAEcQP7rBMtw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-332f6a34782so1705782f8f.2 for ; Mon, 27 Nov 2023 09:56:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701107773; x=1701712573; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dPZIjdABIZddpTNSfTlxpxAKUKtwyx1yxFnwVeAxVeY=; b=wtUsKVM3NDD0ynTiHpQTqTHGZexrrMpWPgoP3cZe3tWSt5srEYgukIEHXolRIcW2gr +UeUTucD3MjAuGG2dvpA7hI0opmLH++q8/ruMXKeYz02lT0ADUlYlOuxEWMo55y7MLgc U3qYqVa8ix1b0AimlmC8KfSxsmz2fgKBqvgj7d+/g464tLlt/TGA141G1pgHiHA6SGn3 cZ7aBTifS4rSeBC/k4ORjI4YK/p/7rIwFCqn/YKss2nlPMgWiN1ToNW3reuHMnixdE1s OKtv3KP6YGSZGpjXTsysG9ecRiRUEySQkSbTplv42OZ5ufGZYbBXgA/QBQGPAk3bRqhu QEjQ== X-Gm-Message-State: AOJu0YxTcvOVtelGnG8kv/fhzQkxCuiuT4/fx/uw+alKQ5d8Ts83kB1a XevoTfU5CK6Hi+6s1tOYIvrDuxdJP6hK0Xx/S9cYRYcvvfwaPFl/yc2Tl6IPrOdehjtRGt/gPhZ zx6wwrh/AInFMccdNwHg5Jvb58RgWuE7SF1o0PT7ZfBTcx/PzAfokmqM9gWXgrb6cfrpaP70WIh J2+RqXjg== X-Received: by 2002:a5d:594f:0:b0:332:f9e8:ce14 with SMTP id e15-20020a5d594f000000b00332f9e8ce14mr3831004wri.29.1701107773529; Mon, 27 Nov 2023 09:56:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IF17lGJa+BCgSk9Yi0/s6llmv/lMqM1yVR01p7FAoDS5vP98NKd9keiU4tYqDEs159lJ1O3hw== X-Received: by 2002:a5d:594f:0:b0:332:f9e8:ce14 with SMTP id e15-20020a5d594f000000b00332f9e8ce14mr3830992wri.29.1701107773100; Mon, 27 Nov 2023 09:56:13 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id t2-20020a5d4602000000b0032da4c98ab2sm12860609wrq.35.2023.11.27.09.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 09:56:12 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 7/7] gdb: generate dwarf-5 index identically as worker-thread count changes Date: Mon, 27 Nov 2023 17:56:01 +0000 Message-Id: <00faec4e7a5d52052639e6f23c3a0ffc670278f5.1701107594.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Similar to the previous commit, this commit ensures that the dwarf-5 index files are generated identically as the number of worker-threads changes. Building the dwarf-5 index makes use of a closed hash table, the bucket_hash local within debug_names::build(). Entries are added to bucket_hash from m_name_to_value_set, which, in turn, is populated by calls to debug_names::insert() in write_debug_names. The insert calls are ordered based on the entries within the cooked_index, and the ordering within cooked_index depends on the number of worker threads that GDB is using. My proposal is to sort each chain within the bucket_hash closed hash table prior to using this to build the dwarf-5 index. The buckets within bucket_hash will always have the same ordering (for a given GDB build with a given executable), and by sorting the chains within each bucket, we can be sure that GDB will see each entry in a deterministic order. I've extended the index creation test to cover this case. --- gdb/dwarf2/index-write.c | 17 +++++++++++++++-- gdb/testsuite/gdb.gdb/index-file.exp | 8 +++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index bc07bcb8f4c..1bc0c8ab57e 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -454,6 +454,11 @@ class c_str_view return strcmp (m_cstr, other.m_cstr) == 0; } + bool operator< (const c_str_view &other) const + { + return strcmp (m_cstr, other.m_cstr) < 0; + } + /* Return the underlying C string. Note, the returned string is only a reference with lifetime of this object. */ const char *c_str () const @@ -773,10 +778,18 @@ class debug_names } for (size_t bucket_ix = 0; bucket_ix < bucket_hash.size (); ++bucket_ix) { - const std::forward_list &hashitlist - = bucket_hash[bucket_ix]; + std::forward_list &hashitlist = bucket_hash[bucket_ix]; if (hashitlist.empty ()) continue; + + /* Sort the items within each bucket. This ensures that the + generated index files will be the same no matter the order in + which symbols were added into the index. */ + hashitlist.sort ([] (const hash_it_pair &a, const hash_it_pair &b) + { + return a.it->first < b.it->first; + }); + uint32_t &bucket_slot = m_bucket_table[bucket_ix]; /* The hashes array is indexed starting at 1. */ store_unsigned_integer (reinterpret_cast (&bucket_slot), diff --git a/gdb/testsuite/gdb.gdb/index-file.exp b/gdb/testsuite/gdb.gdb/index-file.exp index 08415920061..7154d234dd5 100644 --- a/gdb/testsuite/gdb.gdb/index-file.exp +++ b/gdb/testsuite/gdb.gdb/index-file.exp @@ -44,6 +44,9 @@ remote_exec host "mkdir -p ${dir1}" with_timeout_factor $timeout_factor { gdb_test_no_output "save gdb-index $dir1" \ "create gdb-index file" + + gdb_test_no_output "save gdb-index -dwarf-5 $dir1" \ + "create dwarf-index files" } # Close GDB. @@ -140,13 +143,16 @@ if { $worker_threads > 1 } { with_timeout_factor $timeout_factor { gdb_test_no_output "save gdb-index $dir2" \ "create second gdb-index file" + + gdb_test_no_output "save gdb-index -dwarf-5 $dir2" \ + "create second dwarf-index files" } # Close GDB. gdb_exit # Now check that the index files are identical. - foreach suffix { gdb-index } { + foreach suffix { gdb-index debug_names debug_str } { set result \ [remote_exec host \ "cmp -s \"$dir1/${index_filename_base}.${suffix}\" \"$dir2/${index_filename_base}.${suffix}\""]