* [Bug backends/31142] New: riscv pass_by_flattened_arg not implemented
@ 2023-12-11 22:47 mark at klomp dot org
2023-12-12 12:26 ` [Bug backends/31142] " rehn at rivosinc dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: mark at klomp dot org @ 2023-12-11 22:47 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=31142
Bug ID: 31142
Summary: riscv pass_by_flattened_arg not implemented
Product: elfutils
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: backends
Assignee: unassigned at sourceware dot org
Reporter: mark at klomp dot org
CC: elfutils-devel at sourceware dot org
Target Milestone: ---
dwfl_module_return_value_location will fail for functions that return a struct
because that need pass_by_flattened_arg in backends/riscv_retval.c which is
currently:
static int
pass_by_flattened_arg (const Dwarf_Op **locp __attribute__ ((unused)),
Dwarf_Word size __attribute__ ((unused)),
Dwarf_Die *arg0 __attribute__ ((unused)),
Dwarf_Die *arg1 __attribute__ ((unused)))
{
/* ??? */
return -2;
}
This happens for example with the glibc div function which returns:
typedef struct
{
int quot; /* Quotient. */
int rem; /* Remainder. */
} div_t;
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug backends/31142] riscv pass_by_flattened_arg not implemented
2023-12-11 22:47 [Bug backends/31142] New: riscv pass_by_flattened_arg not implemented mark at klomp dot org
@ 2023-12-12 12:26 ` rehn at rivosinc dot com
2023-12-12 12:50 ` palmer at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rehn at rivosinc dot com @ 2023-12-12 12:26 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=31142
Robbin Ehn <rehn at rivosinc dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rehn at rivosinc dot com
--- Comment #1 from Robbin Ehn <rehn at rivosinc dot com> ---
I'm no expert in RV ABI, but from 18.2 RVG Calling Convention:
"Values are returned from functions in integer registers a0 and a1 and
floating-point registers fa0 and fa1. Floating-point values are returned in
floating-point registers only if they are primitives or members of a struct
consisting of only one or two floating-point values. Other return values that
fit into two pointer-words are returned in a0 and a1. Larger return values are
passed entirely
in memory; the caller allocates this memory region and passes a pointer to it
as an implicit first parameter to the callee."
AFAICT they should be packed into a0+a1 seen as 8/16 byte field.
rv32 a0 would be quot and a1 would be rem
rv64 a0 low 32-bit would be quot and a0 high 32-bit would be rem
This seems to be inline with what clang do, removes sign extension, shift and
or the values in.
Did this help ?
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug backends/31142] riscv pass_by_flattened_arg not implemented
2023-12-11 22:47 [Bug backends/31142] New: riscv pass_by_flattened_arg not implemented mark at klomp dot org
2023-12-12 12:26 ` [Bug backends/31142] " rehn at rivosinc dot com
@ 2023-12-12 12:50 ` palmer at gcc dot gnu.org
2023-12-13 15:01 ` mark at klomp dot org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: palmer at gcc dot gnu.org @ 2023-12-12 12:50 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=31142
Palmer Dabbelt <palmer at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |palmer at gcc dot gnu.org
--- Comment #2 from Palmer Dabbelt <palmer at gcc dot gnu.org> ---
(In reply to Robbin Ehn from comment #1)
> I'm no expert in RV ABI, but from 18.2 RVG Calling Convention:
>
> "Values are returned from functions in integer registers a0 and a1 and
> floating-point registers fa0 and fa1. Floating-point values are returned in
> floating-point registers only if they are primitives or members of a struct
> consisting of only one or two floating-point values. Other return values
> that fit into two pointer-words are returned in a0 and a1. Larger return
> values are passed entirely
> in memory; the caller allocates this memory region and passes a pointer to
> it as an implicit first parameter to the callee."
>
> AFAICT they should be packed into a0+a1 seen as 8/16 byte field.
>
> rv32 a0 would be quot and a1 would be rem
> rv64 a0 low 32-bit would be quot and a0 high 32-bit would be rem
>
> This seems to be inline with what clang do, removes sign extension, shift
> and or the values in.
>
> Did this help ?
FWIW, that looks right to me. I haven't really poked around elfutils before,
though, so I'm not really sure how to implement it...
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug backends/31142] riscv pass_by_flattened_arg not implemented
2023-12-11 22:47 [Bug backends/31142] New: riscv pass_by_flattened_arg not implemented mark at klomp dot org
2023-12-12 12:26 ` [Bug backends/31142] " rehn at rivosinc dot com
2023-12-12 12:50 ` palmer at gcc dot gnu.org
@ 2023-12-13 15:01 ` mark at klomp dot org
2023-12-21 1:41 ` mark at klomp dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: mark at klomp dot org @ 2023-12-13 15:01 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=31142
--- Comment #3 from Mark Wielaard <mark at klomp dot org> ---
(In reply to Robbin Ehn from comment #1)
> I'm no expert in RV ABI, but from 18.2 RVG Calling Convention:
>
> "Values are returned from functions in integer registers a0 and a1 and
> floating-point registers fa0 and fa1. Floating-point values are returned in
> floating-point registers only if they are primitives or members of a struct
> consisting of only one or two floating-point values. Other return values
> that fit into two pointer-words are returned in a0 and a1. Larger return
> values are passed entirely
> in memory; the caller allocates this memory region and passes a pointer to
> it as an implicit first parameter to the callee."
>
> AFAICT they should be packed into a0+a1 seen as 8/16 byte field.
>
> rv32 a0 would be quot and a1 would be rem
> rv64 a0 low 32-bit would be quot and a0 high 32-bit would be rem
>
> This seems to be inline with what clang do, removes sign extension, shift
> and or the values in.
>
> Did this help ?
Yes, thanks. I believe I know now which DWARF location description to use for a
function returning a (small) struct containing just integers or just floats.
The code is already there, it is just detecting the struct member types (and
total struct size).
I am not sure what this exactly means for a mix of an integers and floats in a
small struct. Does the calling convention actually handle that? If you have a
struct { int a; float f; } would that be returned with the first piece in a0
and the second piece in fa0? Or would such a return struct be returned entirely
in memory?
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug backends/31142] riscv pass_by_flattened_arg not implemented
2023-12-11 22:47 [Bug backends/31142] New: riscv pass_by_flattened_arg not implemented mark at klomp dot org
` (2 preceding siblings ...)
2023-12-13 15:01 ` mark at klomp dot org
@ 2023-12-21 1:41 ` mark at klomp dot org
2024-03-20 15:10 ` mark at klomp dot org
2024-03-20 19:40 ` mark at klomp dot org
5 siblings, 0 replies; 7+ messages in thread
From: mark at klomp dot org @ 2023-12-21 1:41 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=31142
Mark Wielaard <mark at klomp dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at sourceware dot org |mark at klomp dot org
Status|NEW |ASSIGNED
--- Comment #4 from Mark Wielaard <mark at klomp dot org> ---
The full calling convention (and return registers) rules are here:
https://raw.githubusercontent.com/riscv-non-isa/riscv-elf-psabi-doc/master/riscv-cc.adoc
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug backends/31142] riscv pass_by_flattened_arg not implemented
2023-12-11 22:47 [Bug backends/31142] New: riscv pass_by_flattened_arg not implemented mark at klomp dot org
` (3 preceding siblings ...)
2023-12-21 1:41 ` mark at klomp dot org
@ 2024-03-20 15:10 ` mark at klomp dot org
2024-03-20 19:40 ` mark at klomp dot org
5 siblings, 0 replies; 7+ messages in thread
From: mark at klomp dot org @ 2024-03-20 15:10 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=31142
--- Comment #5 from Mark Wielaard <mark at klomp dot org> ---
Proposed patch for the basic case(s):
https://inbox.sourceware.org/elfutils-devel/20240320150312.169280-1-mark@klomp.org/
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug backends/31142] riscv pass_by_flattened_arg not implemented
2023-12-11 22:47 [Bug backends/31142] New: riscv pass_by_flattened_arg not implemented mark at klomp dot org
` (4 preceding siblings ...)
2024-03-20 15:10 ` mark at klomp dot org
@ 2024-03-20 19:40 ` mark at klomp dot org
5 siblings, 0 replies; 7+ messages in thread
From: mark at klomp dot org @ 2024-03-20 19:40 UTC (permalink / raw)
To: elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=31142
Mark Wielaard <mark at klomp dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #6 from Mark Wielaard <mark at klomp dot org> ---
commit 669b648111d3bc27cd4756879f5fe5a18515de77
Author: Mark Wielaard <mark@klomp.org>
Date: Tue Mar 19 22:43:10 2024 +0000
riscv: Partial implementation of flatten_aggregate
dwfl_module_return_value_location would fail on riscv for functions
which return a (small) struct. This patch implements the simplest
cases of flatten_aggregate in backends/riscv_retval.c. It just handles
structs containing one or two members of the same base type which fit
completely or in pieces in one or two general or floating point
registers.
It also adds a specific test case run-funcretval-struct.sh containing
small structs of ints, longs, floats and doubles. All these testscases
now work for riscv. There is already a slightly more extensive
testcase for this in tests/run-funcretval.sh but that only has a
testcase for aarch64.
* backends/riscv_retval.c (flatten_aggregate_arg): Implement
for the simple cases where we have a struct with one or two
members of the same base type.
(pass_by_flattened_arg): Likewise. Call either
pass_in_gpr_lp64 or pass_in_fpr_lp64d.
(riscv_return_value_location_lp64ifd): Call
flatten_aggregate_arg including size.
* tests/Makefile.am (TESTS): Add run-funcretval-struct.sh
and run-funcretval-struct-native.sh.
(check_PROGRAMS): Add funcretval_test_struct.
(funcretval_test_struct_SOURCES): New.
(EXTRA_DIST): Add run-funcretval-struct.sh,
funcretval_test_struct_riscv.bz2 and
run-funcretval-struct-native.sh.
* tests/funcretval_test_struct_riscv.bz2: New test binary.
* tests/run-funcretval-struct-native.sh: New test.
* tests/run-funcretval-struct.sh: Likewise.
https://sourceware.org/bugzilla/show_bug.cgi?id=31142
Signed-off-by: Mark Wielaard <mark@klomp.org>
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-03-20 19:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-11 22:47 [Bug backends/31142] New: riscv pass_by_flattened_arg not implemented mark at klomp dot org
2023-12-12 12:26 ` [Bug backends/31142] " rehn at rivosinc dot com
2023-12-12 12:50 ` palmer at gcc dot gnu.org
2023-12-13 15:01 ` mark at klomp dot org
2023-12-21 1:41 ` mark at klomp dot org
2024-03-20 15:10 ` mark at klomp dot org
2024-03-20 19:40 ` mark at klomp dot org
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).