[1/3,binutils/readelf] Fix printing of dwarf4 .debug_str_offsets.dwo
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Testing passed
|
Commit Message
When compiling a hello world with dwarf4 split dwarf:
...
$ gcc -gdwarf-4 -gsplit-dwarf hello.c -save-temps -dA
...
we have in a-hello.s these three initial entries in .debug_str_offsets:
...
.section .debug_str_offsets.dwo,"e",@progbits
.4byte 0 // indexed string 0x0: short int
.4byte 0xa // indexed string 0x1: /home/vries/binutils
.4byte 0x1f // indexed string 0x2: main
...
but "readelf -ws a.out" starts at the third entry:
...
Contents of the .debug_str_offsets.dwo section (loaded from a-hello.dwo):
Length: 0x30
Index Offset [String]
0 00000000 main
...
This is a regression since commit 407115429b3 ("Modified changes for
split-dwarf and dwarf-5."), which introduced a variable
debug_str_offsets_hdr_len in display_debug_str_offsets.
Fix this by setting display_debug_str_offsets to 0 for the dwarf4 case.
PR 31734
---
binutils/dwarf.c | 1 +
.../binutils-all/readelf-debug-str-offsets-dw4.d | 14 ++++++++++++++
.../binutils-all/readelf-debug-str-offsets-dw4.s | 6 ++++++
binutils/testsuite/binutils-all/readelf.exp | 1 +
4 files changed, 22 insertions(+)
create mode 100644 binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
create mode 100644 binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
base-commit: 414aa6987f21a814851e5f3113388a3616993fa3
Comments
On Tue, May 14, 2024 at 12:55:20PM +0200, Tom de Vries wrote:
> When compiling a hello world with dwarf4 split dwarf:
> ...
> $ gcc -gdwarf-4 -gsplit-dwarf hello.c -save-temps -dA
> ...
> we have in a-hello.s these three initial entries in .debug_str_offsets:
> ...
> .section .debug_str_offsets.dwo,"e",@progbits
> .4byte 0 // indexed string 0x0: short int
> .4byte 0xa // indexed string 0x1: /home/vries/binutils
> .4byte 0x1f // indexed string 0x2: main
> ...
> but "readelf -ws a.out" starts at the third entry:
> ...
> Contents of the .debug_str_offsets.dwo section (loaded from a-hello.dwo):
>
> Length: 0x30
> Index Offset [String]
> 0 00000000 main
> ...
>
> This is a regression since commit 407115429b3 ("Modified changes for
> split-dwarf and dwarf-5."), which introduced a variable
> debug_str_offsets_hdr_len in display_debug_str_offsets.
>
> Fix this by setting display_debug_str_offsets to 0 for the dwarf4 case.
>
> PR 31734
> ---
> binutils/dwarf.c | 1 +
> .../binutils-all/readelf-debug-str-offsets-dw4.d | 14 ++++++++++++++
> .../binutils-all/readelf-debug-str-offsets-dw4.s | 6 ++++++
> binutils/testsuite/binutils-all/readelf.exp | 1 +
> 4 files changed, 22 insertions(+)
> create mode 100644 binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
> create mode 100644 binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
>
> diff --git a/binutils/dwarf.c b/binutils/dwarf.c
> index c5ccc50dae7..8125c64e1b6 100644
> --- a/binutils/dwarf.c
> +++ b/binutils/dwarf.c
> @@ -7969,6 +7969,7 @@ display_debug_str_offsets (struct dwarf_section *section,
> length = section->size;
> curr = section->start;
> entries_end = end;
> + debug_str_offsets_hdr_len = 0;
>
> printf (_(" Length: %#" PRIx64 "\n"), length);
> printf (_(" Index Offset [String]\n"));
> diff --git a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
> new file mode 100644
> index 00000000000..23581e70f3e
> --- /dev/null
> +++ b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
> @@ -0,0 +1,14 @@
> +#name: readelf -ws readelf-debug-str-offsets-dw4
> +#source: readelf-debug-str-offsets-dw4.s
> +#readelf: -ws
> +
> +Contents of the .debug_str.dwo section:
> +
> + 0x00000000 46495253 54005345 434f4e44 00 FIRST.SECOND.
> +
> +Contents of the .debug_str_offsets.dwo section:
> +
> + Length: 0x8
> + Index Offset \[String\]
> + 0 00000000 FIRST
> + 1 00000006 SECOND
> diff --git a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
> new file mode 100644
> index 00000000000..68f64dde234
> --- /dev/null
> +++ b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
> @@ -0,0 +1,6 @@
> + .section .debug_str.dwo,"MS",@progbits,1
Use %progbits here and elsewhere, otherwise this will break on arm.
> + .string "FIRST"
Use .asciz rather than .string, for hppa. .string on hppa doesn't
have a terminating zero. OK with those changes.
> + .string "SECOND"
> + .section .debug_str_offsets.dwo,"MS",@progbits,1
> + .4byte 0
> + .4byte 6
> diff --git a/binutils/testsuite/binutils-all/readelf.exp b/binutils/testsuite/binutils-all/readelf.exp
> index 09ed75f8761..9f20cb42812 100644
> --- a/binutils/testsuite/binutils-all/readelf.exp
> +++ b/binutils/testsuite/binutils-all/readelf.exp
> @@ -402,6 +402,7 @@ if {[which $AS] != 0} then {
> run_dump_test "retain1b"
> run_dump_test "readelf-maskos-1a"
> run_dump_test "readelf-maskos-1b"
> + run_dump_test "readelf-debug-str-offsets-dw4"
> if {![istarget *-*-hpux*]} then {
> run_dump_test pr26548
> if {![binutils_assemble_flags $srcdir/$subdir/pr26548.s tmpdir/pr26548e.o {--defsym ERROR=1}]} then {
>
> base-commit: 414aa6987f21a814851e5f3113388a3616993fa3
> --
> 2.35.3
@@ -7969,6 +7969,7 @@ display_debug_str_offsets (struct dwarf_section *section,
length = section->size;
curr = section->start;
entries_end = end;
+ debug_str_offsets_hdr_len = 0;
printf (_(" Length: %#" PRIx64 "\n"), length);
printf (_(" Index Offset [String]\n"));
new file mode 100644
@@ -0,0 +1,14 @@
+#name: readelf -ws readelf-debug-str-offsets-dw4
+#source: readelf-debug-str-offsets-dw4.s
+#readelf: -ws
+
+Contents of the .debug_str.dwo section:
+
+ 0x00000000 46495253 54005345 434f4e44 00 FIRST.SECOND.
+
+Contents of the .debug_str_offsets.dwo section:
+
+ Length: 0x8
+ Index Offset \[String\]
+ 0 00000000 FIRST
+ 1 00000006 SECOND
new file mode 100644
@@ -0,0 +1,6 @@
+ .section .debug_str.dwo,"MS",@progbits,1
+ .string "FIRST"
+ .string "SECOND"
+ .section .debug_str_offsets.dwo,"MS",@progbits,1
+ .4byte 0
+ .4byte 6
@@ -402,6 +402,7 @@ if {[which $AS] != 0} then {
run_dump_test "retain1b"
run_dump_test "readelf-maskos-1a"
run_dump_test "readelf-maskos-1b"
+ run_dump_test "readelf-debug-str-offsets-dw4"
if {![istarget *-*-hpux*]} then {
run_dump_test pr26548
if {![binutils_assemble_flags $srcdir/$subdir/pr26548.s tmpdir/pr26548e.o {--defsym ERROR=1}]} then {