summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOmar Sandoval <[email protected]>2024-02-26 11:32:51 -0800
committerMark Wielaard <[email protected]>2024-03-01 15:46:53 +0100
commit3979362ef98db16d1c6fe8fb12ee6a966305da49 (patch)
tree737175a327d12f48d0e2315f06a8763cbbf3fa20 /tests
parent94743d5239ea96a84f974c8ce02e4b4c43a84e13 (diff)
libdw: Handle overflowed DW_SECT_INFO offsets in DWARF package file indexes
Meta uses DWARF package files for our large, statically-linked C++ applications. Some of our largest applications have more than 4GB in .debug_info.dwo, but the section offsets in .debug_cu_index and .debug_tu_index are 32 bits; see the discussion here [1]. We implemented a workaround/extension for this in LLVM. Implement the equivalent in libdw. To test this, we need files with more than 4GB in .debug_info.dwo. I created these artificially by editing GCC's assembly output. They compress down to 6KB. I test them from run-large-elf-file.sh to take advantage of the existing checks for large file support. 1: https://discourse.llvm.org/t/dwarf-dwp-4gb-limit/63902. * libdw/dwarf_end.c (dwarf_package_index_free): New function. * tests/testfile-dwp-4-cu-index-overflow.bz2: New test file. * tests/testfile-dwp-4-cu-index-overflow.dwp.bz2: New test file. * tests/testfile-dwp-5-cu-index-overflow.bz2: New test file. * tests/testfile-dwp-5-cu-index-overflow.dwp.bz2: New test file. * tests/testfile-dwp-cu-index-overflow.source: New file. * tests/run-large-elf-file.sh: Check testfile-dwp-5-cu-index-overflow and testfile-dwp-4-cu-index-overflow. Signed-off-by: Omar Sandoval <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am7
-rwxr-xr-xtests/run-large-elf-file.sh174
-rwxr-xr-xtests/testfile-dwp-4-cu-index-overflow.bz2bin0 -> 4490 bytes
-rw-r--r--tests/testfile-dwp-4-cu-index-overflow.dwp.bz2bin0 -> 5584 bytes
-rwxr-xr-xtests/testfile-dwp-5-cu-index-overflow.bz2bin0 -> 4544 bytes
-rw-r--r--tests/testfile-dwp-5-cu-index-overflow.dwp.bz2bin0 -> 5790 bytes
-rw-r--r--tests/testfile-dwp-cu-index-overflow.source86
7 files changed, 266 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3f80c451..9141074f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -641,7 +641,12 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
testfile-dwp-4.bz2 testfile-dwp-4.dwp.bz2 \
testfile-dwp-4-strict.bz2 testfile-dwp-4-strict.dwp.bz2 \
testfile-dwp-5.bz2 testfile-dwp-5.dwp.bz2 testfile-dwp.source \
- run-cu-dwp-section-info.sh run-declfiles.sh
+ run-cu-dwp-section-info.sh run-declfiles.sh \
+ testfile-dwp-5-cu-index-overflow.bz2 \
+ testfile-dwp-5-cu-index-overflow.dwp.bz2 \
+ testfile-dwp-4-cu-index-overflow.bz2 \
+ testfile-dwp-4-cu-index-overflow.dwp.bz2 \
+ testfile-dwp-cu-index-overflow.source
if USE_VALGRIND
diff --git a/tests/run-large-elf-file.sh b/tests/run-large-elf-file.sh
index 7116de53..8108cb4b 100755
--- a/tests/run-large-elf-file.sh
+++ b/tests/run-large-elf-file.sh
@@ -122,4 +122,178 @@ test_file testfile38
# 64bit, big endian, non-rel
test_file testfile27
+# See testfile-dwp-cu-index-overflow.source
+testfiles testfile-dwp-5-cu-index-overflow testfile-dwp-5-cu-index-overflow.dwp
+
+testrun_compare ${abs_builddir}/cu-dwp-section-info testfile-dwp-5-cu-index-overflow.dwp << EOF
+file: testfile-dwp-5-cu-index-overflow.dwp
+INFO: 0x0 0x8000004c
+TYPES: 0x0 0x0
+ABBREV: 0x0 0x50
+LINE: 0x0 0x61
+LOCLISTS: 0x0 0x0
+STR_OFFSETS: 0x0 0x1c
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x8000004c 0x6f
+TYPES: 0x0 0x0
+ABBREV: 0x50 0x15e
+LINE: 0x61 0x63
+LOCLISTS: 0x0 0xd4
+STR_OFFSETS: 0x1c 0x24
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x22
+
+INFO: 0x800000bb 0xff
+TYPES: 0x0 0x0
+ABBREV: 0x50 0x15e
+LINE: 0x61 0x63
+LOCLISTS: 0x0 0xd4
+STR_OFFSETS: 0x1c 0x24
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x22
+
+INFO: 0x800001ba 0x8000004c
+TYPES: 0x0 0x0
+ABBREV: 0x1ae 0x50
+LINE: 0xc4 0x61
+LOCLISTS: 0x0 0x0
+STR_OFFSETS: 0x40 0x1c
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x100000206 0x6c
+TYPES: 0x0 0x0
+ABBREV: 0x1fe 0xc8
+LINE: 0x125 0x63
+LOCLISTS: 0x0 0x0
+STR_OFFSETS: 0x5c 0x20
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x100000272 0x6f
+TYPES: 0x0 0x0
+ABBREV: 0x1fe 0xc8
+LINE: 0x125 0x63
+LOCLISTS: 0x0 0x0
+STR_OFFSETS: 0x5c 0x20
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x1000002e1 0x182
+TYPES: 0x0 0x0
+ABBREV: 0x2c6 0x188
+LINE: 0x188 0x65
+LOCLISTS: 0xd4 0xee
+STR_OFFSETS: 0x7c 0x44
+MACRO: 0x0 0x0
+RNGLISTS: 0x22 0x43
+
+EOF
+
+testrun_compare ${abs_builddir}/get-units-split testfile-dwp-5-cu-index-overflow << EOF
+file: testfile-dwp-5-cu-index-overflow
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: filler1.cc
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: foo.cc
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: filler2.cc
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: bar.cc
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: main.cc
+
+EOF
+
+rm -f testfile-dwp-5-cu-index-overflow testfile-dwp-5-cu-index-overflow.dwp
+
+# See testfile-dwp-cu-index-overflow.source
+testfiles testfile-dwp-4-cu-index-overflow testfile-dwp-4-cu-index-overflow.dwp
+
+testrun_compare ${abs_builddir}/cu-dwp-section-info testfile-dwp-4-cu-index-overflow.dwp << EOF
+file: testfile-dwp-4-cu-index-overflow.dwp
+INFO: 0x0 0x8000004b
+TYPES: 0x0 0x0
+ABBREV: 0x0 0x58
+LINE: 0x0 0x2c
+LOCLISTS: 0x0 0x0
+STR_OFFSETS: 0x0 0x14
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x8000004b 0x116
+TYPES: 0x0 0x0
+ABBREV: 0x58 0x16f
+LINE: 0x2c 0x34
+LOCLISTS: 0x0 0x110
+STR_OFFSETS: 0x14 0x1c
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x80000161 0x8000004b
+TYPES: 0x0 0x0
+ABBREV: 0x1c7 0x58
+LINE: 0x60 0x2c
+LOCLISTS: 0x0 0x0
+STR_OFFSETS: 0x30 0x14
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x1000001ac 0x6e
+TYPES: 0x0 0x0
+ABBREV: 0x21f 0xd4
+LINE: 0x8c 0x34
+LOCLISTS: 0x0 0x0
+STR_OFFSETS: 0x44 0x18
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x10000021a 0x1b5
+TYPES: 0x0 0x0
+ABBREV: 0x2f3 0x19b
+LINE: 0xc0 0x35
+LOCLISTS: 0x110 0x12a
+STR_OFFSETS: 0x5c 0x3c
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x0 0x0
+TYPES: 0x0 0x6e
+ABBREV: 0x58 0x16f
+LINE: 0x2c 0x34
+LOCLISTS: 0x0 0x110
+STR_OFFSETS: 0x14 0x1c
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+INFO: 0x0 0x0
+TYPES: 0x6e 0x6b
+ABBREV: 0x21f 0xd4
+LINE: 0x8c 0x34
+LOCLISTS: 0x0 0x0
+STR_OFFSETS: 0x44 0x18
+MACRO: 0x0 0x0
+RNGLISTS: 0x0 0x0
+
+EOF
+
+testrun_compare ${abs_builddir}/get-units-split testfile-dwp-4-cu-index-overflow << EOF
+file: testfile-dwp-4-cu-index-overflow
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: filler1.cc
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: foo.cc
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: filler2.cc
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: bar.cc
+Got cudie unit_type: 4
+Found a skeleton unit, with split die: main.cc
+
+EOF
+
+rm -f testfile-dwp-4-cu-index-overflow testfile-dwp-4-cu-index-overflow.dwp
+
exit 0
diff --git a/tests/testfile-dwp-4-cu-index-overflow.bz2 b/tests/testfile-dwp-4-cu-index-overflow.bz2
new file mode 100755
index 00000000..2aaa4f40
--- /dev/null
+++ b/tests/testfile-dwp-4-cu-index-overflow.bz2
Binary files differ
diff --git a/tests/testfile-dwp-4-cu-index-overflow.dwp.bz2 b/tests/testfile-dwp-4-cu-index-overflow.dwp.bz2
new file mode 100644
index 00000000..0718c1b2
--- /dev/null
+++ b/tests/testfile-dwp-4-cu-index-overflow.dwp.bz2
Binary files differ
diff --git a/tests/testfile-dwp-5-cu-index-overflow.bz2 b/tests/testfile-dwp-5-cu-index-overflow.bz2
new file mode 100755
index 00000000..07185fe5
--- /dev/null
+++ b/tests/testfile-dwp-5-cu-index-overflow.bz2
Binary files differ
diff --git a/tests/testfile-dwp-5-cu-index-overflow.dwp.bz2 b/tests/testfile-dwp-5-cu-index-overflow.dwp.bz2
new file mode 100644
index 00000000..dce34e3f
--- /dev/null
+++ b/tests/testfile-dwp-5-cu-index-overflow.dwp.bz2
Binary files differ
diff --git a/tests/testfile-dwp-cu-index-overflow.source b/tests/testfile-dwp-cu-index-overflow.source
new file mode 100644
index 00000000..2de15441
--- /dev/null
+++ b/tests/testfile-dwp-cu-index-overflow.source
@@ -0,0 +1,86 @@
+# Dummy program that we patch to generate a dwp file with more than 4GB of
+# .debug_info.
+
+# Generate 2 dummy files that result in DWARF blocks.
+$ for (( i = 1; i <= 2; i++ )); do echo 'constexpr int filler'$i'[] = { 1 };' > filler$i.cc; done
+$ g++ -O2 -g -gsplit-dwarf -fdebug-types-section -dA -S filler{1,2}.cc foo.cc bar.cc main.cc
+# Patch the DWARF blocks to be 2GB.
+$ for (( i = 1; i <= 2; i++ )); do patch -p1 << EOF
+--- a/filler$i.s
++++ b/filler$i.s
+@@ -7,5 +7,5 @@
+ .section .debug_info.dwo,"e",@progbits
+ .Ldebug_info0:
+- .long 0x49 # Length of Compilation Unit Info
++ .long 0x80000048 # Length of Compilation Unit Info
+ .value 0x5 # DWARF version number
+ .byte 0x5 # DW_UT_split_compile
+@@ -51,9 +51,6 @@
+ .long 0x29 # DW_AT_type
+ # DW_AT_const_expr
+- .byte 0x4 # DW_AT_const_value
+- .byte 0x1 # fp or vector constant word 0
+- .byte 0 # fp or vector constant word 1
+- .byte 0 # fp or vector constant word 2
+- .byte 0 # fp or vector constant word 3
++ .long 0x80000000 # DW_AT_const_value
++ .fill 0x80000000
+ .byte 0 # end of children of DIE 0x14
+ .section .debug_info,"",@progbits
+@@ -171,5 +168,5 @@
+ .uleb128 0x19 # (DW_FORM_flag_present)
+ .uleb128 0x1c # (DW_AT_const_value)
+- .uleb128 0xa # (DW_FORM_block1)
++ .uleb128 0x4 # (DW_FORM_block4)
+ .byte 0
+ .byte 0
+EOF
+done
+$ for (( i = 1; i <= 2; i++ )); do as filler$i.s -o filler$i.o; done
+$ as foo.s -o foo.o
+$ as bar.s -o bar.o
+$ as main.s -o main.o
+$ g++ filler1.o foo.o filler2.o bar.o main.o -o testfile-dwp-5-cu-index-overflow
+# -continue-on-cu-index-overflow was added in LLVM 17:
+# https://reviews.llvm.org/D144565.
+$ llvm-dwp -continue-on-cu-index-overflow filler1.o foo.o filler2.o bar.o main.o -o testfile-dwp-5-cu-index-overflow.dwp
+
+# Same thing for DWARF 4.
+$ g++ -O2 -g -gdwarf-4 -gsplit-dwarf -fdebug-types-section -dA -S filler{1,2}.cc foo.cc bar.cc main.cc
+$ for (( i = 1; i <= 2; i++ )); do patch -p1 << EOF
+--- a/filler$i.s
++++ b/filler$i.s
+@@ -6,5 +6,5 @@
+ .section .debug_info.dwo,"e",@progbits
+ .Ldebug_info0:
+- .long 0x48 # Length of Compilation Unit Info
++ .long 0x80000047 # Length of Compilation Unit Info
+ .value 0x4 # DWARF version number
+ .long .Ldebug_abbrev0 # Offset Into Abbrev. Section
+@@ -49,9 +49,6 @@
+ .long 0x28 # DW_AT_type
+ # DW_AT_const_expr
+- .byte 0x4 # DW_AT_const_value
+- .byte 0x1 # fp or vector constant word 0
+- .byte 0 # fp or vector constant word 1
+- .byte 0 # fp or vector constant word 2
+- .byte 0 # fp or vector constant word 3
++ .long 0x80000000 # DW_AT_const_value
++ .fill 0x80000000
+ .byte 0 # end of children of DIE 0xb
+ .section .debug_info,"",@progbits
+@@ -172,5 +169,5 @@
+ .uleb128 0x19 # (DW_FORM_flag_present)
+ .uleb128 0x1c # (DW_AT_const_value)
+- .uleb128 0xa # (DW_FORM_block1)
++ .uleb128 0x4 # (DW_FORM_block4)
+ .byte 0
+ .byte 0
+EOF
+done
+$ for (( i = 1; i <= 2; i++ )); do as filler$i.s -o filler$i.o; done
+$ as foo.s -o foo.o
+$ as bar.s -o bar.o
+$ as main.s -o main.o
+$ g++ filler1.o foo.o filler2.o bar.o main.o -o testfile-dwp-4-cu-index-overflow
+$ llvm-dwp -continue-on-cu-index-overflow filler1.o foo.o filler2.o bar.o main.o -o testfile-dwp-4-cu-index-overflow.dwp