[v2,4/7] x86_64_return_value_location: Support lvalue and rvalue references

Message ID 20230208195226.144143-5-iii@linux.ibm.com
State Superseded
Headers
Series Add Memory Sanitizer support |

Commit Message

Ilya Leoshkevich Feb. 8, 2023, 7:52 p.m. UTC
  On the low level, they are the same as pointers.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 backends/x86_64_retval.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Mark Wielaard Feb. 9, 2023, 1:45 p.m. UTC | #1
Hi Ilya,

On Wed, 2023-02-08 at 20:52 +0100, Ilya Leoshkevich wrote:
> On the low level, they are the same as pointers.

Yes, I can see how that would work for return types.
Do you happen to have a testcase for this?

Right below this code is a check whether the type has a
DW_AT_byte_size, and if not we'll assume 8 as (address) size if the
type is either DW_TAG_pointer_type or DW_TAG_ptr_to_member_type.
Should the same be done for DW_TAG_reference_type and
DW_TAG_rvalue_reference_type?

This doesn't seem x86_64 specific, other backends have similar code, I
assume they all need a similar update?

Thanks,

Mark

> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  backends/x86_64_retval.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/backends/x86_64_retval.c b/backends/x86_64_retval.c
> index f9114cb1..e668eacc 100644
> --- a/backends/x86_64_retval.c
> +++ b/backends/x86_64_retval.c
> @@ -106,6 +106,8 @@ x86_64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
>      case DW_TAG_enumeration_type:
>      case DW_TAG_pointer_type:
>      case DW_TAG_ptr_to_member_type:
> +    case DW_TAG_reference_type:
> +    case DW_TAG_rvalue_reference_type:
>        {
>  	Dwarf_Attribute attr_mem;
>  	if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
  
Ilya Leoshkevich Feb. 10, 2023, 1:20 a.m. UTC | #2
On Thu, 2023-02-09 at 14:45 +0100, Mark Wielaard wrote:
> Hi Ilya,
> 
> On Wed, 2023-02-08 at 20:52 +0100, Ilya Leoshkevich wrote:
> > On the low level, they are the same as pointers.
> 
> Yes, I can see how that would work for return types.
> Do you happen to have a testcase for this?

You can trigger the issue by compiling the following:

$ cat 1.cpp
int &foo() { throw; }
int &&bar() { throw; }

$ g++ -g 1.cpp -c

and then running

$ LD_LIBRARY_PATH=../libelf:../libdw ./funcretval -e 1.o

What would be a good way to integrate such a testcase?
Currently all tests are built with gcc, is it okay to add one
built with g++? If not, I guess the alternative would be to check in
multiple compressed object files built for different platforms?

> Right below this code is a check whether the type has a
> DW_AT_byte_size, and if not we'll assume 8 as (address) size if the
> type is either DW_TAG_pointer_type or DW_TAG_ptr_to_member_type.
> Should the same be done for DW_TAG_reference_type and
> DW_TAG_rvalue_reference_type?

Sounds reasonable. Here is what I have on x86_64:

 <1><5a>: Abbrev Number: 1 (DW_TAG_reference_type)
    <5b>   DW_AT_byte_size   : 8
 <1><80>: Abbrev Number: 7 (DW_TAG_rvalue_reference_type)
    <81>   DW_AT_byte_size   : 8

IIUC these checks handle weird compilers that do not emit
DW_AT_byte_size.

> This doesn't seem x86_64 specific, other backends have similar code,
> I
> assume they all need a similar update?

Oh, right, this issue seems to affect all of them.

> Thanks,
> 
> Mark
> 
> > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> > ---
> >  backends/x86_64_retval.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/backends/x86_64_retval.c b/backends/x86_64_retval.c
> > index f9114cb1..e668eacc 100644
> > --- a/backends/x86_64_retval.c
> > +++ b/backends/x86_64_retval.c
> > @@ -106,6 +106,8 @@ x86_64_return_value_location (Dwarf_Die
> > *functypedie, const Dwarf_Op **locp)
> >      case DW_TAG_enumeration_type:
> >      case DW_TAG_pointer_type:
> >      case DW_TAG_ptr_to_member_type:
> > +    case DW_TAG_reference_type:
> > +    case DW_TAG_rvalue_reference_type:
> >        {
> >         Dwarf_Attribute attr_mem;
> >         if (dwarf_formudata (dwarf_attr_integrate (typedie,
> > DW_AT_byte_size,
>
  
Frank Ch. Eigler Feb. 10, 2023, 4:22 p.m. UTC | #3
Hi -

> $ cat 1.cpp
> int &foo() { throw; }
> int &&bar() { throw; }
> $ g++ -g 1.cpp -c
> and then running
> 
> $ LD_LIBRARY_PATH=../libelf:../libdw ./funcretval -e 1.o
> 
> What would be a good way to integrate such a testcase?
> Currently all tests are built with gcc, is it okay to add one
> built with g++? [...]

Sure.


- FChE
  

Patch

diff --git a/backends/x86_64_retval.c b/backends/x86_64_retval.c
index f9114cb1..e668eacc 100644
--- a/backends/x86_64_retval.c
+++ b/backends/x86_64_retval.c
@@ -106,6 +106,8 @@  x86_64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     case DW_TAG_enumeration_type:
     case DW_TAG_pointer_type:
     case DW_TAG_ptr_to_member_type:
+    case DW_TAG_reference_type:
+    case DW_TAG_rvalue_reference_type:
       {
 	Dwarf_Attribute attr_mem;
 	if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,