* [PATCH] [gdb/testsuite] Fix 64-bit dwarf test-cases with -m32
@ 2021-11-01 17:56 Tom de Vries
2021-11-01 20:54 ` Andreas Schwab
0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2021-11-01 17:56 UTC (permalink / raw)
To: gdb-patches
When running test-case gdb.dwarf2/loc-sec-offset.exp with target board -m32,
I run into:
...
builtin_spawn -ignore SIGHUP gcc -fno-stack-protector -m32 \
-fdiagnostics-color=never -c -o loc-sec-offset-dw641.o \
loc-sec-offset-dw64.S^M
as: loc-sec-offset-dw641.o: unsupported relocation type: 0x1^M
loc-sec-offset-dw64.S: Assembler messages:^M
loc-sec-offset-dw64.S:29: Error: cannot represent relocation type \
BFD_RELOC_64^M
...
Looking at line 29, we have:
...
.8byte .Labbrev1_begin /* Abbrevs */
...
It would be nice if the assembler could handle this somehow. But I guess
it's not unreasonable that an assembler for a 32-bit architecture will object
to handling 64-bit labels.
Instead, work around this in the dwarf assembler by emitting:
...
.4byte .Labbrev1_begin /* Abbrevs (lsw) */
.4byte 0 /* Abbrevs (msw) */
...
Tested on x86_64-linux with target board unix/-m32.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28383
---
gdb/testsuite/lib/dwarf.exp | 44 +++++++++++++++++++++++++++++--------
gdb/testsuite/lib/gdb.exp | 23 +++++++++++++++++++
2 files changed, 58 insertions(+), 9 deletions(-)
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index b48cfad3b9e..044b7364beb 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -580,7 +580,7 @@ namespace eval Dwarf {
DW_FORM_GNU_strp_alt -
DW_FORM_sec_offset {
variable _cu_offset_size
- _op .${_cu_offset_size}byte $value
+ _op_offset $_cu_offset_size $value
}
DW_FORM_ref1 -
@@ -645,7 +645,7 @@ namespace eval Dwarf {
}
}
- _op .${_cu_offset_size}byte $_strings($value) "strp: $value"
+ _op_offset $_cu_offset_size $_strings($value) "strp: $value"
}
SPECIAL_expr {
@@ -971,6 +971,28 @@ namespace eval Dwarf {
_emit $text
}
+ proc _op_offset { size offset {comment ""} } {
+ if { $size == 4 } {
+ _op .4byte $offset $comment
+ } elseif { $size == 8 } {
+ if {[is_64_target]} {
+ _op .8byte $offset $comment
+ } else {
+ # This allows us to emit 64-bit dwarf for
+ # 32-bit targets.
+ if { [target_endianness] == "little" } {
+ _op .4byte $offset "$comment (lsw)"
+ _op .4byte 0 "$comment (msw)"
+ } else {
+ _op .4byte 0 "$comment (msw)"
+ _op .4byte $offset "$comment (lsw)"
+ }
+ }
+ } else {
+ error "Don't know how to handle offset size $size"
+ }
+ }
+
proc _compute_label {name} {
return ".L${name}"
}
@@ -1185,7 +1207,7 @@ namespace eval Dwarf {
if { $dwarf_version == 2 } {
_op .${addr_size}byte $argvec(label)
} else {
- _op .${offset_size}byte $argvec(label)
+ _op_offset $offset_size $argvec(label)
}
_op .sleb128 $argvec(offset)
}
@@ -1197,7 +1219,7 @@ namespace eval Dwarf {
if { $dwarf_version == 2 } {
_op .${addr_size}byte $argvec(label)
} else {
- _op .${offset_size}byte $argvec(label)
+ _op_offset $offset_size $argvec(label)
}
}
@@ -1344,9 +1366,9 @@ namespace eval Dwarf {
if { $_cu_version == 5 } {
_op .byte 0x1 "DW_UT_compile"
_op .byte $_cu_addr_size "Pointer size"
- _op .${_cu_offset_size}byte $my_abbrevs Abbrevs
+ _op_offset $_cu_offset_size $my_abbrevs Abbrevs
} else {
- _op .${_cu_offset_size}byte $my_abbrevs Abbrevs
+ _op_offset $_cu_offset_size $my_abbrevs Abbrevs
_op .byte $_cu_addr_size "Pointer size"
}
@@ -1440,7 +1462,7 @@ namespace eval Dwarf {
}
define_label $start_label
_op .2byte $_cu_version Version
- _op .${_cu_offset_size}byte $my_abbrevs Abbrevs
+ _op_offset $_cu_offset_size $my_abbrevs Abbrevs
_op .byte $_cu_addr_size "Pointer size"
_op .8byte $signature Signature
if { $type_label != "" } {
@@ -1666,7 +1688,9 @@ namespace eval Dwarf {
if { ${with-offset-array} } {
for {set list_idx 0} {$list_idx < $_debug_rnglists_list_count} {incr list_idx} {
set list_label [_compute_list_label $list_idx]
- _op .${_debug_rnglists_offset_size}byte "$list_label - $post_header_label" "offset of list $list_idx"
+ _op_offset $_debug_rnglists_offset_size \
+ "$list_label - $post_header_label" \
+ "offset of list $list_idx"
}
}
@@ -1852,7 +1876,9 @@ namespace eval Dwarf {
if { ${with-offset-array} } {
for {set list_idx 0} {$list_idx < $_debug_loclists_list_count} {incr list_idx} {
set list_label [_compute_list_label $list_idx]
- _op .${_debug_loclists_offset_size}byte "$list_label - $post_header_label" "offset of list $list_idx"
+ _op_offset $_debug_loclists_offset_size \
+ "$list_label - $post_header_label" \
+ "offset of list $list_idx"
}
}
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 7f02504262d..1d57c692c2d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -7078,6 +7078,29 @@ proc get_endianness { } {
return "little"
}
+# Get the target's default endianness and return it.
+gdb_caching_proc target_endianness {
+ global gdb_prompt
+
+ set me "target_endianness"
+
+ set src { int main() { return 0; } }
+ if {![gdb_simple_compile $me $src executable]} {
+ return 0
+ }
+
+ clean_restart $obj
+ if ![runto_main] {
+ return 0
+ }
+ set res [get_endianness]
+
+ gdb_exit
+ remote_file build delete $obj
+
+ return $res
+}
+
# ROOT and FULL are file names. Returns the relative path from ROOT
# to FULL. Note that FULL must be in a subdirectory of ROOT.
# For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
base-commit: 2047d95b897c7153368033c318185429f7809e4f
--
2.26.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [gdb/testsuite] Fix 64-bit dwarf test-cases with -m32
2021-11-01 17:56 [PATCH] [gdb/testsuite] Fix 64-bit dwarf test-cases with -m32 Tom de Vries
@ 2021-11-01 20:54 ` Andreas Schwab
2021-11-03 20:00 ` Tom de Vries
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2021-11-01 20:54 UTC (permalink / raw)
To: Tom de Vries via Gdb-patches
On Nov 01 2021, Tom de Vries via Gdb-patches wrote:
> When running test-case gdb.dwarf2/loc-sec-offset.exp with target board -m32,
> I run into:
> ...
> builtin_spawn -ignore SIGHUP gcc -fno-stack-protector -m32 \
> -fdiagnostics-color=never -c -o loc-sec-offset-dw641.o \
> loc-sec-offset-dw64.S^M
> as: loc-sec-offset-dw641.o: unsupported relocation type: 0x1^M
> loc-sec-offset-dw64.S: Assembler messages:^M
> loc-sec-offset-dw64.S:29: Error: cannot represent relocation type \
> BFD_RELOC_64^M
> ...
>
> Looking at line 29, we have:
> ...
> .8byte .Labbrev1_begin /* Abbrevs */
> ...
>
> It would be nice if the assembler could handle this somehow. But I guess
> it's not unreasonable that an assembler for a 32-bit architecture will object
> to handling 64-bit labels.
Shouldn't the 64-bit dwarf tests just be skipped on 32-bit targets?
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [gdb/testsuite] Fix 64-bit dwarf test-cases with -m32
2021-11-01 20:54 ` Andreas Schwab
@ 2021-11-03 20:00 ` Tom de Vries
2021-11-03 20:30 ` Andreas Schwab
0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2021-11-03 20:00 UTC (permalink / raw)
To: Andreas Schwab, Tom de Vries via Gdb-patches
On 11/1/21 9:54 PM, Andreas Schwab wrote:
> On Nov 01 2021, Tom de Vries via Gdb-patches wrote:
>
>> When running test-case gdb.dwarf2/loc-sec-offset.exp with target board -m32,
>> I run into:
>> ...
>> builtin_spawn -ignore SIGHUP gcc -fno-stack-protector -m32 \
>> -fdiagnostics-color=never -c -o loc-sec-offset-dw641.o \
>> loc-sec-offset-dw64.S^M
>> as: loc-sec-offset-dw641.o: unsupported relocation type: 0x1^M
>> loc-sec-offset-dw64.S: Assembler messages:^M
>> loc-sec-offset-dw64.S:29: Error: cannot represent relocation type \
>> BFD_RELOC_64^M
>> ...
>>
>> Looking at line 29, we have:
>> ...
>> .8byte .Labbrev1_begin /* Abbrevs */
>> ...
>>
>> It would be nice if the assembler could handle this somehow. But I guess
>> it's not unreasonable that an assembler for a 32-bit architecture will object
>> to handling 64-bit labels.
>
> Shouldn't the 64-bit dwarf tests just be skipped on 32-bit targets?
Because ?
Thanks,
- Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [gdb/testsuite] Fix 64-bit dwarf test-cases with -m32
2021-11-03 20:00 ` Tom de Vries
@ 2021-11-03 20:30 ` Andreas Schwab
2021-11-19 14:08 ` Tom de Vries
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2021-11-03 20:30 UTC (permalink / raw)
To: Tom de Vries; +Cc: Tom de Vries via Gdb-patches
On Nov 03 2021, Tom de Vries wrote:
> On 11/1/21 9:54 PM, Andreas Schwab wrote:
>> On Nov 01 2021, Tom de Vries via Gdb-patches wrote:
>>
>>> When running test-case gdb.dwarf2/loc-sec-offset.exp with target board -m32,
>>> I run into:
>>> ...
>>> builtin_spawn -ignore SIGHUP gcc -fno-stack-protector -m32 \
>>> -fdiagnostics-color=never -c -o loc-sec-offset-dw641.o \
>>> loc-sec-offset-dw64.S^M
>>> as: loc-sec-offset-dw641.o: unsupported relocation type: 0x1^M
>>> loc-sec-offset-dw64.S: Assembler messages:^M
>>> loc-sec-offset-dw64.S:29: Error: cannot represent relocation type \
>>> BFD_RELOC_64^M
>>> ...
>>>
>>> Looking at line 29, we have:
>>> ...
>>> .8byte .Labbrev1_begin /* Abbrevs */
>>> ...
>>>
>>> It would be nice if the assembler could handle this somehow. But I guess
>>> it's not unreasonable that an assembler for a 32-bit architecture will object
>>> to handling 64-bit labels.
>>
>> Shouldn't the 64-bit dwarf tests just be skipped on 32-bit targets?
>
> Because ?
Because 32-bit targets have no way to represent 8-byte relocations.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [gdb/testsuite] Fix 64-bit dwarf test-cases with -m32
2021-11-03 20:30 ` Andreas Schwab
@ 2021-11-19 14:08 ` Tom de Vries
0 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2021-11-19 14:08 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Tom de Vries via Gdb-patches
On 11/3/21 9:30 PM, Andreas Schwab wrote:
> On Nov 03 2021, Tom de Vries wrote:
>
>> On 11/1/21 9:54 PM, Andreas Schwab wrote:
>>> On Nov 01 2021, Tom de Vries via Gdb-patches wrote:
>>>
>>>> When running test-case gdb.dwarf2/loc-sec-offset.exp with target board -m32,
>>>> I run into:
>>>> ...
>>>> builtin_spawn -ignore SIGHUP gcc -fno-stack-protector -m32 \
>>>> -fdiagnostics-color=never -c -o loc-sec-offset-dw641.o \
>>>> loc-sec-offset-dw64.S^M
>>>> as: loc-sec-offset-dw641.o: unsupported relocation type: 0x1^M
>>>> loc-sec-offset-dw64.S: Assembler messages:^M
>>>> loc-sec-offset-dw64.S:29: Error: cannot represent relocation type \
>>>> BFD_RELOC_64^M
>>>> ...
>>>>
>>>> Looking at line 29, we have:
>>>> ...
>>>> .8byte .Labbrev1_begin /* Abbrevs */
>>>> ...
>>>>
>>>> It would be nice if the assembler could handle this somehow. But I guess
>>>> it's not unreasonable that an assembler for a 32-bit architecture will object
>>>> to handling 64-bit labels.
>>>
>>> Shouldn't the 64-bit dwarf tests just be skipped on 32-bit targets?
>>
>> Because ?
>
> Because 32-bit targets have no way to represent 8-byte relocations.
>
> Andreas.
>
I tried a hello world with gcc-11, -m32 and -gdwarf64:
...
$ gcc-11 ~/hello.c -g -gdwarf64 -m32 -save-temps -dA
...
and looked at a section offset:
...
.long .Ldebug_line0, 0 # DW_AT_stmt_list
...
This comes from dw2_assemble_integer, where we have:
...
void
dw2_assemble_integer (int size, rtx x)
{
if (size == 2 * (int) DWARF2_ADDR_SIZE && !CONST_SCALAR_INT_P (x))
{
/* On 32-bit targets with -gdwarf64, DImode values with
relocations usually result in assembler errors. Assume
all such values are positive and emit the relocation only
in the least significant half. */
...
So, it seems I chose the same solution as gcc.
I'll commit this shortly.
Thanks,
- Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-19 14:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 17:56 [PATCH] [gdb/testsuite] Fix 64-bit dwarf test-cases with -m32 Tom de Vries
2021-11-01 20:54 ` Andreas Schwab
2021-11-03 20:00 ` Tom de Vries
2021-11-03 20:30 ` Andreas Schwab
2021-11-19 14:08 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).