From 33960ce5a8e26baf05521fd7f8be5c5abb6bb0ff Mon Sep 17 00:00:00 2001 From: Sayhaan Siddiqui <49014204+sayhaan@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:35:38 -0700 Subject: [PATCH] [BOLT][DWARF] Sort GDBIndexTUEntryVector (#101264) Sorts GDBIndexTUEntryVector in decreasing order by hash to ensure determinism when parallelized. --- bolt/include/bolt/Core/GDBIndex.h | 8 ++++++++ bolt/lib/Core/GDBIndex.cpp | 3 +-- .../X86/dwarf4-split-gdb-index-types-gdb-generated.test | 8 ++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bolt/include/bolt/Core/GDBIndex.h b/bolt/include/bolt/Core/GDBIndex.h index 6604c2a11472..0ebcf4ecfe99 100644 --- a/bolt/include/bolt/Core/GDBIndex.h +++ b/bolt/include/bolt/Core/GDBIndex.h @@ -53,6 +53,14 @@ public: const GDBIndexTUEntryType &getGDBIndexTUEntryVector() const { return GDBIndexTUEntryVector; } + + /// Sorts entries in GDBIndexTUEntryVector according to the TypeHash. + void sortGDBIndexTUEntryVector() { + llvm::stable_sort(GDBIndexTUEntryVector, [](const GDBIndexTUEntry &LHS, + const GDBIndexTUEntry &RHS) { + return LHS.TypeHash > RHS.TypeHash; + }); + } }; } // namespace bolt diff --git a/bolt/lib/Core/GDBIndex.cpp b/bolt/lib/Core/GDBIndex.cpp index 9e6d24167d55..c7fb4889646b 100644 --- a/bolt/lib/Core/GDBIndex.cpp +++ b/bolt/lib/Core/GDBIndex.cpp @@ -23,7 +23,6 @@ void GDBIndex::updateGdbIndexSection( DebugARangesSectionWriter &ARangesSectionWriter) { if (!BC.getGdbIndexSection()) return; - // See https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html // for .gdb_index section format. @@ -141,7 +140,7 @@ void GDBIndex::updateGdbIndexSection( write64le(Buffer + 8, CUInfo.second.Length + 4); Buffer += 16; } - + sortGDBIndexTUEntryVector(); // Rewrite TU CU List, since abbrevs can be different. // Entry example: // 0: offset = 0x00000000, type_offset = 0x0000001e, type_signature = diff --git a/bolt/test/X86/dwarf4-split-gdb-index-types-gdb-generated.test b/bolt/test/X86/dwarf4-split-gdb-index-types-gdb-generated.test index c9b12574caa3..6caf5870fca0 100644 --- a/bolt/test/X86/dwarf4-split-gdb-index-types-gdb-generated.test +++ b/bolt/test/X86/dwarf4-split-gdb-index-types-gdb-generated.test @@ -17,10 +17,10 @@ # POSTCHECK-NEXT: 0: Offset = 0x0, Length = 0x34 # POSTCHECK-NEXT: 1: Offset = 0x34, Length = 0x34 # POSTCHECK: Types CU list offset = 0x38, has 4 entries -# POSTCHECK-NEXT: 0: offset = 0x00000000, type_offset = 0x0000001e, type_signature = 0x675d23e4f33235f2 -# POSTCHECK-NEXT: 1: offset = 0x0000004a, type_offset = 0x0000001e, type_signature = 0x49dc260088be7e56 -# POSTCHECK-NEXT: 2: offset = 0x00000000, type_offset = 0x0000001e, type_signature = 0x104ec427d2ebea6f -# POSTCHECK-NEXT: 3: offset = 0x0000004a, type_offset = 0x0000001e, type_signature = 0xb4580bc1535df1e4 +# POSTCHECK-NEXT: 0: offset = 0x0000004a, type_offset = 0x0000001e, type_signature = 0xb4580bc1535df1e4 +# POSTCHECK-NEXT: 1: offset = 0x00000000, type_offset = 0x0000001e, type_signature = 0x675d23e4f33235f2 +# POSTCHECK-NEXT: 2: offset = 0x0000004a, type_offset = 0x0000001e, type_signature = 0x49dc260088be7e56 +# POSTCHECK-NEXT: 3: offset = 0x00000000, type_offset = 0x0000001e, type_signature = 0x104ec427d2ebea6f # POSTCHECK: Address area offset = 0x98, has 2 entries # POSTCHECK-NEXT: Low/High address = [0x[[#%.4x,ADDR:]], # POSTCHECK-SAME: 0x[[#ADDR + 0x7a]]) (Size: 0x7a), CU id = 0