From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from t03.bc.larksuite.com (t03.bc.larksuite.com [209.127.231.39]) by sourceware.org (Postfix) with UTF8SMTPS id 232233858C5F for ; Thu, 18 May 2023 09:06:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 232233858C5F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=oss.cipunited.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=oss.cipunited.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=s1; d=oss-cipunited-com.20200927.dkim.feishu.cn; t=1684400772; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=HldGA9MuxrgfZrciT5daH56i8pFiFXOYhZ7kGQNMM9I=; b=kVBmw8lJr11BbhRdGKNX81oHZzHWvpTkhB91eiktcvPATaJjWxTjYIUyaAnk268C9i2J47 DfZD4qZU7ZCwZbeo6CNdTbSYt7O24mh+Q1lLUanrhaRVKOS83uhGFxQcJemqI2Pmk8kcSf xP3Iz91N9zSPzepKbSW9IbYtihS+ezssMP2/5abPWkQ6d5O0n0BykPGh8aZ9B2yJZpmvgq 1w2SkYROySO1PFOSdlqePX714Er5W4Qi/r9FVyVFAdB51FRQWSUOA9RAewupv4qy7+ir2B cVwpRSlrVY2auVszyvKJMA0SnwHBnKrlUvDBLkDZ1Y4bk1LyPfaoQ1h51OupOw== Subject: Re: [PATCH 5/5] backends: Fix run-native-test.sh and run-funcretval++11.sh run fail on mips Message-Id: <18c61cc3-f777-596d-f329-392481b82bc1@oss.cipunited.com> X-Lms-Return-Path: Content-Type: multipart/alternative; boundary=03f59793726af0b510d89e9fea87b53d7080ebd4673193970c96431a1571 From: "Ying Huang" Date: Thu, 18 May 2023 17:06:00 +0800 In-Reply-To: <4958c19be43be2315c26d104b1ada85dbde89142.camel@klomp.org> Cc: Mime-Version: 1.0 References: <20230411081141.1762395-1-ying.huang@oss.cipunited.com> <20230411081141.1762395-6-ying.huang@oss.cipunited.com> <4958c19be43be2315c26d104b1ada85dbde89142.camel@klomp.org> Content-Language: en-US To: "Mark Wielaard" , Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,HTML_MESSAGE,KAM_SHORT,NICE_REPLY_A,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --03f59793726af0b510d89e9fea87b53d7080ebd4673193970c96431a1571 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Hi, =E5=9C=A8 2023/5/12 00:38, Mark Wielaard =E5=86=99=E9=81=93: >> diff --git a/backends/mips_regs.c b/backends/mips_regs.c >> >> + >> +ssize_t >> +mips_register_info (Ebl *ebl __attribute__ ((unused)), >> + int regno, char *name, size_t namelen, >> + const char **prefix, const char **setname, >> + int *bits, int *type) >> +{ >> + if (name =3D=3D NULL) >> + return 66; >> + >> + if (regno < 0 || regno > 65 || namelen < 4) >> + return -1; >> + >> + *prefix =3D "$"; >> +=20=20 >> + if (regno < 32) >> + { >> + *setname =3D "integer"; >> + *type =3D DW_ATE_signed; >> + *bits =3D 32; >> + if (regno < 32 + 10) >> + { >> + name[0] =3D regno + '0'; >> + namelen =3D 1; >> + } >> + else >> + { >> + name[0] =3D (regno / 10) + '0'; >> + name[1] =3D (regno % 10) + '0'; >> + namelen =3D 2; >> + } >> + } >> + else if (regno < 64) >> + { >> + *setname =3D "FPU"; >> + *type =3D DW_ATE_float; >> + *bits =3D 32; >> + name[0] =3D 'f'; >> + if (regno < 32 + 10) >> + { >> + name[1] =3D (regno - 32) + '0'; >> + namelen =3D 2; >> + } >> + else >> + { >> + name[1] =3D (regno - 32) / 10 + '0'; >> + name[2] =3D (regno - 32) % 10 + '0'; >> + namelen =3D 3; >> + } >> > OK, but indentation seems slightly off. space vs tabs? =C2=A0=C2=A0=C2=A0 Yes, those lines that not aligned are tabs, I would fix = it. Thanks. > >> diff --git a/backends/mips_retval.c b/backends/mips_retval.c >> new file mode 100644 >> index 00000000..fd9aaefa >> --- /dev/null >> +++ b/backends/mips_retval.c >> @@ -0,0 +1,261 @@ >> +/* Function return value location for Linux/mips ABI. >> + Copyright (C) 2005 Red Hat, Inc. >> + Copyright (C) 2023 CIP United Inc. >> + This file is part of elfutils. >> + >> + This file is free software; you can redistribute it and/or modify >> + it under the terms of either >> + >> + * the GNU Lesser General Public License as published by the Free >> + Software Foundation; either version 3 of the License, or (at >> + your option) any later version >> + >> + or >> + >> + * the GNU General Public License as published by the Free >> + Software Foundation; either version 2 of the License, or (at >> + your option) any later version >> + >> + or both in parallel, as here. >> + >> + elfutils is distributed in the hope that it will be useful, but >> + WITHOUT ANY WARRANTY; without even the implied warranty of >> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> + General Public License for more details. >> + >> + You should have received copies of the GNU General Public License and >> + the GNU Lesser General Public License along with this program. If >> + not, see . */ >> + >> +#ifdef HAVE_CONFIG_H >> +# include >> +#endif >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#define BACKEND mips_ >> +#include "libebl_CPU.h" >> +#include "libdwP.h" >> + >> +/* All the possible MIPS ARCHs. */ >> +enum mips_arch >> + { >> + MIPS_ARCH_UNKNOWN =3D 0, >> + MIPS_ARCH_32, >> + MIPS_ARCH_64, >> + MIPS_ARCH_LAST >> + }; >> + >> +/* Find the mips ARCH of the current file */ >> +enum mips_arch find_mips_arch(Elf *elf) >> +{ >> + GElf_Ehdr ehdr_mem; >> + GElf_Ehdr *ehdr =3D gelf_getehdr (elf, &ehdr_mem); >> + >> + if (ehdr =3D=3D NULL) >> + return MIPS_ARCH_LAST; >> + >> + GElf_Word elf_flags =3D ehdr->e_flags; >> + >> + /* Check elf_flags to see if it specifies the ARCH being used. */ >> + switch ((elf_flags & EF_MIPS_ARCH)) >> + { >> + case E_MIPS_ARCH_32: >> + case EF_MIPS_ARCH_32R2: >> + case E_MIPS_ARCH_32R6: >> + return MIPS_ARCH_32; >> + case E_MIPS_ARCH_64: >> + case EF_MIPS_ARCH_64R2: >> + case E_MIPS_ARCH_64R6: >> + return MIPS_ARCH_64; >> + default: >> + return MIPS_ARCH_32; >> + } >> + >> + return MIPS_ARCH_UNKNOWN; >> +} >> >> +unsigned int >> +mips_arch_regsize (enum mips_arch arch) >> +{ >> + switch (arch) >> + { >> + case MIPS_ARCH_32: >> + return 4; >> + case MIPS_ARCH_64: >> + return 8; >> + case MIPS_ARCH_UNKNOWN: >> + case MIPS_ARCH_LAST: >> + default: >> + return 0; >> + } >> +} > So this is different from checking ELFCLASS32/64? =C2=A0=C2=A0=C2=A0 OK, I would change to use ELFCLASS32/64: > >> +/* $v0 or pair $v0, $v1 */ >> +static const Dwarf_Op loc_intreg_o32[] =3D >> + { >> + { .atom =3D DW_OP_reg2 }, { .atom =3D DW_OP_piece, .number =3D 4 }, >> + { .atom =3D DW_OP_reg3 }, { .atom =3D DW_OP_piece, .number =3D 4 }, >> + }; >> + >> +static const Dwarf_Op loc_intreg[] =3D >> + { >> + { .atom =3D DW_OP_reg2 }, { .atom =3D DW_OP_piece, .number =3D 8 }, >> + { .atom =3D DW_OP_reg3 }, { .atom =3D DW_OP_piece, .number =3D 8 }, >> + }; >> +#define nloc_intreg 1 >> +#define nloc_intregpair 4 >> + >> +/* $f0 (float), or pair $f0, $f1 (double). >> + * f2/f3 are used for COMPLEX (=3D 2 doubles) returns in Fortran */ >> +static const Dwarf_Op loc_fpreg_o32[] =3D >> + { >> + { .atom =3D DW_OP_regx, .number =3D 32 }, { .atom =3D DW_OP_piece, = .number =3D 4 }, >> + { .atom =3D DW_OP_regx, .number =3D 33 }, { .atom =3D DW_OP_piece, = .number =3D 4 }, >> + { .atom =3D DW_OP_regx, .number =3D 34 }, { .atom =3D DW_OP_piece, = .number =3D 4 }, >> + { .atom =3D DW_OP_regx, .number =3D 35 }, { .atom =3D DW_OP_piece, = .number =3D 4 }, >> + }; >> + >> +/* $f0, or pair $f0, $f2. */ >> +static const Dwarf_Op loc_fpreg[] =3D >> + { >> + { .atom =3D DW_OP_regx, .number =3D 32 }, { .atom =3D DW_OP_piece, = .number =3D 8 }, >> + { .atom =3D DW_OP_regx, .number =3D 34 }, { .atom =3D DW_OP_piece, = .number =3D 8 }, >> + }; >> +#define nloc_fpreg 1 >> +#define nloc_fpregpair 4 >> +#define nloc_fpregquad 8 >> + >> +/* The return value is a structure and is actually stored in stack space >> + passed in a hidden argument by the caller. But, the compiler >> + helpfully returns the address of that space in $v0. */ >> +static const Dwarf_Op loc_aggregate[] =3D >> + { >> + { .atom =3D DW_OP_breg2, .number =3D 0 } >> + }; >> +#define nloc_aggregate 1 >> + >> +int >> +mips_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **lo= cp) >> +{ >> + /* First find the ARCH used by the elf object */ >> + enum mips_arch arch =3D find_mips_arch(functypedie->cu->dbg->elf); >> + /* Something went seriously wrong while trying to figure out the ARCH= */ >> + if (arch =3D=3D MIPS_ARCH_LAST) >> + return -1; >> + >> + /* We couldn't identify the ARCH, but the file seems valid */ >> + if (arch =3D=3D MIPS_ARCH_UNKNOWN) >> + return -3; >> + >> + unsigned int regsize =3D mips_arch_regsize (arch); >> + if (!regsize) >> + return -2; >> + >> + /* Start with the function's type, and get the DW_AT_type attribute, >> + which is the type of the return value. */ >> +=20=20 >> + Dwarf_Attribute attr_mem; >> + Dwarf_Attribute *attr =3D dwarf_attr_integrate (functypedie, DW_AT_ty= pe, &attr_mem); >> + if (attr =3D=3D NULL) >> + /* The function has no return value, like a `void' function in C. = */ >> + return 0; >> + >> + Dwarf_Die die_mem; >> + Dwarf_Die *typedie =3D dwarf_formref_die (attr, &die_mem); >> + int tag =3D dwarf_tag (typedie); >> + >> + /* Follow typedefs and qualifiers to get to the actual type. */ >> + while (tag =3D=3D DW_TAG_typedef >> + || tag =3D=3D DW_TAG_const_type || tag =3D=3D DW_TAG_volatile_type >> + || tag =3D=3D DW_TAG_restrict_type) >> + { >> + attr =3D dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); >> + typedie =3D dwarf_formref_die (attr, &die_mem); >> + tag =3D dwarf_tag (typedie); >> + } >> + >> + switch (tag) >> + { >> + case -1: >> + return -1; >> + >> + case DW_TAG_subrange_type: >> + if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size)) >> + { >> + attr =3D dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); >> + typedie =3D dwarf_formref_die (attr, &die_mem); >> + tag =3D dwarf_tag (typedie); >> + } >> + /* Fall through. */ >> + FALLTHROUGH; >> + >> + case DW_TAG_base_type: >> + case DW_TAG_enumeration_type: >> + CASE_POINTER: >> + { >> + Dwarf_Word size; >> + if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size, >> + &attr_mem), &size) !=3D 0) >> + { >> + if (dwarf_is_pointer (tag)) >> + size =3D regsize; >> + else >> + return -1; >> + } >> + if (tag =3D=3D DW_TAG_base_type) >> + { >> + Dwarf_Word encoding; >> + if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding, >> + &attr_mem), &encoding) !=3D 0) >> + return -1; >> + >> +#define ARCH_LOC(loc, regsize) ((regsize) =3D=3D 4 ? (loc ## _o32) : (l= oc)) >> + >> + if (encoding =3D=3D DW_ATE_float) >> + { >> + *locp =3D ARCH_LOC(loc_fpreg, regsize); >> + if (size <=3D regsize) >> + return nloc_fpreg; >> + >> + if (size <=3D 2*regsize) >> + return nloc_fpregpair; >> + >> + if (size <=3D 4*regsize && arch =3D=3D MIPS_ARCH_32) >> + return nloc_fpregquad; >> + >> + goto aggregate; >> + } >> + } >> + *locp =3D ARCH_LOC(loc_intreg, regsize); >> + if (size <=3D regsize) >> + return nloc_intreg; >> + if (size <=3D 2*regsize) >> + return nloc_intregpair; >> + >> + /* Else fall through. Shouldn't happen though (at least with gcc) */ >> + } >> + FALLTHROUGH; >> + >> + case DW_TAG_structure_type: >> + case DW_TAG_class_type: >> + case DW_TAG_union_type: >> + case DW_TAG_array_type: >> + aggregate: >> + /* XXX TODO: Can't handle structure return with other ABI's yet := -/ */ >> + if ((arch !=3D MIPS_ARCH_32) && (arch !=3D MIPS_ARCH_64)) >> + return -2; >> + >> + *locp =3D loc_aggregate; >> + return nloc_aggregate; >> + } >> + >> + /* XXX We don't have a good way to return specific errors from ebl ca= lls. >> + This value means we do not understand the type, but it is well-for= med >> + DWARF and might be valid. */ >> + return -2; >> +} > OK. This looks plausible. Would be good to have a reference to the > actual calling convention. > > Thanks, > > Mark Thanks, YIng= --03f59793726af0b510d89e9fea87b53d7080ebd4673193970c96431a1571--