[llvm] [BOLT][DWARF][NFC] Add mc opt to DWARFRewriter.cpp (PR #100800)
Sayhaan Siddiqui via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 26 11:56:05 PDT 2024
https://github.com/sayhaan created https://github.com/llvm/llvm-project/pull/100800
Running into an error with removing DWP where the assertion `Assertion `RelaxAllView &&
"RegisterMCTargetOptionsFlags not created."'` failed. This is a result of DWP bringing the option in, and the option being removed with DWP.
https://reviews.llvm.org/D75579
https://reviews.llvm.org/D106417
>From 3b8935a600ea0f243c18d27864d43848785fad08 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Thu, 25 Jul 2024 17:01:38 -0700
Subject: [PATCH 1/3] [BOLT][DWARF][NFC] Fix DebugStrOffsetsWriter so
updateAddressMap can't be called after it is finalized
Summary:
Test Plan:
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: https://phabricator.intern.facebook.com/D60293063
---
bolt/include/bolt/Core/DebugData.h | 5 +++++
bolt/lib/Core/DIEBuilder.cpp | 3 +++
bolt/lib/Core/DebugData.cpp | 1 +
bolt/lib/Rewrite/DWARFRewriter.cpp | 2 ++
bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test | 2 +-
5 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/bolt/include/bolt/Core/DebugData.h b/bolt/include/bolt/Core/DebugData.h
index 5935ffaa46af7..ba988102a0fb5 100644
--- a/bolt/include/bolt/Core/DebugData.h
+++ b/bolt/include/bolt/Core/DebugData.h
@@ -503,10 +503,15 @@ class DebugStrOffsetsWriter {
return StrOffsetSectionWasModified;
}
+ std::unordered_map<uint64_t, bool> &getDebugStrOffsetFinalized() {
+ return DebugStrOffsetFinalized;
+ }
+
private:
std::unique_ptr<DebugStrOffsetsBufferVector> StrOffsetsBuffer;
std::unique_ptr<raw_svector_ostream> StrOffsetsStream;
std::map<uint32_t, uint32_t> IndexToAddressMap;
+ std::unordered_map<uint64_t, bool> DebugStrOffsetFinalized;
SmallVector<uint32_t, 5> StrOffsets;
std::unordered_map<uint64_t, uint64_t> ProcessedBaseOffsets;
bool StrOffsetSectionWasModified = false;
diff --git a/bolt/lib/Core/DIEBuilder.cpp b/bolt/lib/Core/DIEBuilder.cpp
index b0f550fd77318..df055e418ccce 100644
--- a/bolt/lib/Core/DIEBuilder.cpp
+++ b/bolt/lib/Core/DIEBuilder.cpp
@@ -77,6 +77,9 @@ static void addStringHelper(DebugStrOffsetsWriter &StrOffstsWriter,
DIEValue &DIEAttrInfo, StringRef Str) {
uint32_t NewOffset = StrWriter.addString(Str);
if (Unit.getVersion() >= 5) {
+ assert(StrOffstsWriter.getDebugStrOffsetFinalized().count(
+ Unit.getOffset()) == 0 &&
+ "debug_str_offsets was already finalized.");
StrOffstsWriter.updateAddressMap(DIEAttrInfo.getDIEInteger().getValue(),
NewOffset);
return;
diff --git a/bolt/lib/Core/DebugData.cpp b/bolt/lib/Core/DebugData.cpp
index 002f58c474346..c1662271abe8b 100644
--- a/bolt/lib/Core/DebugData.cpp
+++ b/bolt/lib/Core/DebugData.cpp
@@ -906,6 +906,7 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
}
StrOffsetSectionWasModified = false;
+ DebugStrOffsetFinalized[Unit.getOffset()] = true;
clear();
}
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 674b5f17adb3f..adf4c7a32e579 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -757,6 +757,8 @@ void DWARFRewriter::updateDebugInfo() {
: std::optional<std::string>(opts::DwarfOutputPath.c_str());
std::string DWOName = DIEBlder.updateDWONameCompDir(
*StrOffstsWriter, *StrWriter, *CU, DwarfOutputPath, std::nullopt);
+ if (CU->getVersion() >= 5)
+ StrOffstsWriter->finalizeSection(*CU, DIEBlder);
processSplitCU(*CU, **SplitCU, DIEBlder, *TempRangesSectionWriter,
AddressWriter, DWOName, DwarfOutputPath);
}
diff --git a/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test b/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test
index a325395fd5320..45734bdb229fd 100644
--- a/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test
+++ b/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test
@@ -6,7 +6,7 @@
; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-df-input-lowpc-ranges-other.s \
; RUN: -split-dwarf-file=mainOther.dwo -o other.o
; RUN: %clang %cflags main.o other.o -o main.exe
-; RUN: llvm-bolt main.exe -o main.exe.bolt --update-debug-sections
+; RUN: llvm-bolt main.exe -o main.exe.bolt --update-debug-sections --cu-processing-batch-size=2
; RUN: llvm-dwarfdump --show-form --verbose --debug-rnglists main.exe.bolt &> %t/foo.txt
; RUN: llvm-dwarfdump --show-form --verbose --debug-addr main.exe.bolt >> %t/foo.txt
; RUN: llvm-dwarfdump --show-form --verbose --debug-info main.exe.bolt >> %t/foo.txt
>From 8c807df42af8c61c992d575a7b8fe1ccd2f81a91 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Fri, 26 Jul 2024 11:12:28 -0700
Subject: [PATCH 2/3] Updates to tests
---
...-df-input-lowpc-ranges-cus-batch-size.test | 135 ++++++++++++++++++
.../X86/dwarf5-df-input-lowpc-ranges-cus.test | 2 +-
2 files changed, 136 insertions(+), 1 deletion(-)
create mode 100644 bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus-batch-size.test
diff --git a/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus-batch-size.test b/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus-batch-size.test
new file mode 100644
index 0000000000000..db4d7468eb2b6
--- /dev/null
+++ b/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus-batch-size.test
@@ -0,0 +1,135 @@
+; RUN: rm -rf %t
+; RUN: mkdir %t
+; RUN: cd %t
+; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-df-input-lowpc-ranges-main.s \
+; RUN: -split-dwarf-file=main.dwo -o main.o
+; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-df-input-lowpc-ranges-other.s \
+; RUN: -split-dwarf-file=mainOther.dwo -o other.o
+; RUN: %clang %cflags main.o other.o -o main.exe
+; RUN: llvm-bolt main.exe -o main.exe.bolt --update-debug-sections --cu-processing-batch-size=1
+; RUN: llvm-bolt main.exe -o main-batch.exe.bolt --update-debug-sections --cu-processing-batch-size=2
+; RUN: llvm-dwarfdump --show-form --verbose --debug-rnglists main.exe.bolt &> %t/foo.txt
+; RUN: llvm-dwarfdump --show-form --verbose --debug-addr main.exe.bolt >> %t/foo.txt
+; RUN: llvm-dwarfdump --show-form --verbose --debug-info main.exe.bolt >> %t/foo.txt
+; RUN: cat %t/foo.txt | FileCheck -check-prefix=BOLT %s
+; RUN: llvm-dwarfdump --show-form --verbose --debug-rnglists main.exe.bolt &> %t/foo-batch.txt
+; RUN: llvm-dwarfdump --show-form --verbose --debug-addr main.exe.bolt >> %t/foo-batch.txt
+; RUN: llvm-dwarfdump --show-form --verbose --debug-info main.exe.bolt >> %t/foo-batch.txt
+; RUN: cat %t/foo-batch.txt | FileCheck -check-prefix=BOLT-BATCH %s
+; RUN: llvm-dwarfdump --show-form --verbose --debug-info main.dwo.dwo mainOther.dwo.dwo &> %t/mainddwodwo.txt
+; RUN: cat %t/mainddwodwo.txt | FileCheck -check-prefix=BOLT-DWO-MAIN %s
+
+;; Tests that BOLT correctly handles Skeleton CU which has DW_AT_low_pc/DW_AT_ranges as input and handles multiple CUs with ranges
+;; and with multiple batch sizes.
+
+; BOLT: Addrs: [
+; BOLT-NEXT: 0x[[#%.16x,ADDR1:]]
+; BOLT-NEXT: 0x[[#%.16x,ADDR2:]]
+; BOLT-NEXT: 0x[[#%.16x,ADDR3:]]
+; BOLT-NEXT: 0x[[#%.16x,ADDR4:]]
+; BOLT-NEXT: 0x[[#%.16x,ADDR5:]]
+
+; BOLT: Addrs: [
+; BOLT-NEXT: 0x[[#%.16x,ADDR6:]]
+; BOLT-NEXT: 0x[[#%.16x,ADDR7:]]
+; BOLT-NEXT: 0x[[#%.16x,ADDR8:]]
+; BOLT-NEXT: 0x[[#%.16x,ADDR9:]]
+; BOLT-NEXT: 0x[[#%.16x,ADDR10:]]
+
+; BOLT: DW_TAG_skeleton_unit
+; BOLT: DW_AT_dwo_name [DW_FORM_strx1] (indexed (00000001) string = "main.dwo.dwo")
+; BOLT-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
+; BOLT-NEXT: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x00000010
+; BOLT-NEXT: [0x[[#ADDR1]], 0x[[#ADDR1 + 0x16]])
+; BOLT-NEXT: [0x[[#ADDR1 + 0x16]], 0x[[#ADDR1 + 0x24]])
+; BOLT-NEXT: [0x[[#ADDR1 + 0x24]], 0x[[#ADDR1 + 0x29]])
+; BOLT-NEXT: [0x[[#ADDR1 + 0x30]], 0x[[#ADDR1 + 0x46]])
+; BOLT-NEXT: [0x[[#ADDR1 + 0x50]], 0x[[#ADDR1 + 0x77]])
+; BOLT-NEXT: [0x[[#ADDR1 + 0x77]], 0x[[#ADDR1 + 0x85]])
+; BOLT-NEXT: [0x[[#ADDR1 + 0x85]], 0x[[#ADDR1 + 0x9f]])
+; BOLT-NEXT: DW_AT_addr_base [DW_FORM_sec_offset] (0x00000008)
+; BOLT-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x0000000c)
+
+; BOLT: DW_TAG_skeleton_unit
+; BOLT: DW_AT_dwo_name [DW_FORM_strx1] (indexed (00000001) string = "mainOther.dwo.dwo")
+; BOLT-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
+; BOLT-NEXT: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x0000003b
+; BOLT-NEXT: [0x[[#ADDR6]], 0x[[#ADDR6 + 0x16]])
+; BOLT-NEXT: [0x[[#ADDR6 + 0x16]], 0x[[#ADDR6 + 0x24]])
+; BOLT-NEXT: [0x[[#ADDR6 + 0x24]], 0x[[#ADDR6 + 0x29]])
+; BOLT-NEXT: [0x[[#ADDR6 + 0x30]], 0x[[#ADDR6 + 0x46]])
+; BOLT-NEXT: [0x[[#ADDR6 + 0x50]], 0x[[#ADDR6 + 0x70]])
+; BOLT-NEXT: [0x[[#ADDR6 + 0x70]], 0x[[#ADDR6 + 0x7e]])
+; BOLT-NEXT: [0x[[#ADDR6 + 0x7e]], 0x[[#ADDR6 + 0x98]])
+; BOLT-NEXT: DW_AT_addr_base [DW_FORM_sec_offset] (0x00000038)
+; BOLT-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x00000037)
+
+; BOLT-BATCH: Addrs: [
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR1:]]
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR2:]]
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR3:]]
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR4:]]
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR5:]]
+
+; BOLT-BATCH: Addrs: [
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR6:]]
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR7:]]
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR8:]]
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR9:]]
+; BOLT-BATCH-NEXT: 0x[[#%.16x,ADDR10:]]
+
+; BOLT-BATCH: DW_TAG_skeleton_unit
+; BOLT-BATCH: DW_AT_dwo_name [DW_FORM_strx1] (indexed (00000001) string = "main.dwo.dwo")
+; BOLT-BATCH-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
+; BOLT-BATCH-NEXT: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x00000010
+; BOLT-BATCH-NEXT: [0x[[#ADDR1]], 0x[[#ADDR1 + 0x16]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR1 + 0x16]], 0x[[#ADDR1 + 0x24]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR1 + 0x24]], 0x[[#ADDR1 + 0x29]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR1 + 0x30]], 0x[[#ADDR1 + 0x46]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR1 + 0x50]], 0x[[#ADDR1 + 0x77]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR1 + 0x77]], 0x[[#ADDR1 + 0x85]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR1 + 0x85]], 0x[[#ADDR1 + 0x9f]])
+; BOLT-BATCH-NEXT: DW_AT_addr_base [DW_FORM_sec_offset] (0x00000008)
+; BOLT-BATCH-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x0000000c)
+
+; BOLT-BATCH: DW_TAG_skeleton_unit
+; BOLT-BATCH: DW_AT_dwo_name [DW_FORM_strx1] (indexed (00000001) string = "mainOther.dwo.dwo")
+; BOLT-BATCH-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
+; BOLT-BATCH-NEXT: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x0000003b
+; BOLT-BATCH-NEXT: [0x[[#ADDR6]], 0x[[#ADDR6 + 0x16]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR6 + 0x16]], 0x[[#ADDR6 + 0x24]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR6 + 0x24]], 0x[[#ADDR6 + 0x29]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR6 + 0x30]], 0x[[#ADDR6 + 0x46]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR6 + 0x50]], 0x[[#ADDR6 + 0x70]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR6 + 0x70]], 0x[[#ADDR6 + 0x7e]])
+; BOLT-BATCH-NEXT: [0x[[#ADDR6 + 0x7e]], 0x[[#ADDR6 + 0x98]])
+; BOLT-BATCH-NEXT: DW_AT_addr_base [DW_FORM_sec_offset] (0x00000038)
+; BOLT-BATCH-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x00000037)
+
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN-NEXT: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x00000014
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000000, 0x0000000000000016)
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000016, 0x0000000000000024)
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000024, 0x0000000000000029))
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN-NEXT: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x1) rangelist = 0x00000020
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000002, 0x0000000000000029)
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000029, 0x0000000000000037)
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000037, 0x0000000000000051))
+
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN-NEXT: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x00000014
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000000, 0x0000000000000016)
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000016, 0x0000000000000024)
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000024, 0x0000000000000029))
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN: DW_TAG_subprogram
+; BOLT-DWO-MAIN-NEXT: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x1) rangelist = 0x00000020
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000002, 0x0000000000000022)
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000022, 0x0000000000000030)
+; BOLT-DWO-MAIN-NEXT: [0x0000000000000030, 0x000000000000004a))
diff --git a/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test b/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test
index 45734bdb229fd..a325395fd5320 100644
--- a/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test
+++ b/bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test
@@ -6,7 +6,7 @@
; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-df-input-lowpc-ranges-other.s \
; RUN: -split-dwarf-file=mainOther.dwo -o other.o
; RUN: %clang %cflags main.o other.o -o main.exe
-; RUN: llvm-bolt main.exe -o main.exe.bolt --update-debug-sections --cu-processing-batch-size=2
+; RUN: llvm-bolt main.exe -o main.exe.bolt --update-debug-sections
; RUN: llvm-dwarfdump --show-form --verbose --debug-rnglists main.exe.bolt &> %t/foo.txt
; RUN: llvm-dwarfdump --show-form --verbose --debug-addr main.exe.bolt >> %t/foo.txt
; RUN: llvm-dwarfdump --show-form --verbose --debug-info main.exe.bolt >> %t/foo.txt
>From b60551c538ec8e1fd3e6fc60f665a26ed05812bb Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui <sayhaan at meta.com>
Date: Fri, 26 Jul 2024 11:53:54 -0700
Subject: [PATCH 3/3] [BOLT][DWARF][NFC] Add mc opt to DWARFRewriter.cpp
---
bolt/lib/Rewrite/DWARFRewriter.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index adf4c7a32e579..59cfbaf7e228d 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -32,6 +32,7 @@
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCTargetOptionsCommandFlags.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
@@ -56,6 +57,8 @@
#undef DEBUG_TYPE
#define DEBUG_TYPE "bolt"
+static mc::RegisterMCTargetOptionsFlags MOF;
+
static void printDie(const DWARFDie &DIE) {
DIDumpOptions DumpOpts;
DumpOpts.ShowForm = true;
More information about the llvm-commits
mailing list