From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from s01.bc.larksuite.com (s01.bc.larksuite.com [209.127.230.13]) by sourceware.org (Postfix) with UTF8SMTPS id 794313857722 for ; Tue, 16 May 2023 08:01:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 794313857722 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=1684224089; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=pJhtCpdCfdcJ8nJc7/1iVC162d1qhoMT3xDQT0nY+LM=; b=qHOEv1i+1KnWWttcKXPyyCKi7o0JgNO1z/XuSuwlHAosL/54unIYzaGnZqONyX+QoC/BEV sS1JCI2xfUWIdqfgWVf8tPysvkFJZ8nGOlMr2SFClM4oE8sfzWAk+QFNHGsRSLvnm56j6k 826wE+bYtnDR5FvvaYDqbpeqIn7aGqWfzqQ/yFINnEm0Aeg/ZUK4LxBBseiNTMMpbG87Uj xQ4+Yym41le34TLiLj5U1U2clkatQsDEAm4tJWlljjpwB8xPSA2Uzxh63qzlWWSt0p/2HL VhHAsYKWq7VxJkzudkfp7L8hjySoBhwXfH3e6r3r+YobQ5pDPwJ3L9IQ84hQ6A== Cc: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=75f4d0ab47c081a1061ba265dd4b84a3da42ca0caff6ba9f7d75e006f2f4 Date: Tue, 16 May 2023 16:01:18 +0800 In-Reply-To: <3a59ea20739cde776aad7945ca4cc09055e1db6f.camel@klomp.org> To: "Mark Wielaard" , Message-Id: <8758b0a3-8221-0859-966e-d3a1c99abcf7@oss.cipunited.com> X-Lms-Return-Path: From: "Ying Huang" Subject: Re: [PATCH 2/5] readelf: Adapt src/readelf -h/-S/-r/-w/-l/-d/-a on mips References: <20230411081141.1762395-1-ying.huang@oss.cipunited.com> <20230411081141.1762395-3-ying.huang@oss.cipunited.com> <3a59ea20739cde776aad7945ca4cc09055e1db6f.camel@klomp.org> Content-Language: en-US Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,BODY_8BITS,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: --75f4d0ab47c081a1061ba265dd4b84a3da42ca0caff6ba9f7d75e006f2f4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Hi, =E5=9C=A8 2023/5/11 22:31, Mark Wielaard =E5=86=99=E9=81=93: > Hi, > > On Tue, 2023-04-11 at 16:12 +0800, Ying Huang wrote: >> diff --git a/backends/mips_attrs.c b/backends/mips_attrs.c >> new file mode 100644 >> index 00000000..1419814e >> --- /dev/null >> +++ b/backends/mips_attrs.c >> @@ -0,0 +1,107 @@ >> +/* Object attribute tags for MIPS. >> + 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 >> + >> +#define BACKEND arm_ > You mean mips_ =C2=A0=C2=A0=C2=A0 Yes, it should be mips_, thanks! >> diff --git a/backends/mips_init.c b/backends/mips_init.c >> index f70d62e4..5bba822b 100644 >> --- a/backends/mips_init.c >> +++ b/backends/mips_init.c >> @@ -45,5 +45,12 @@ mips_init (Elf *elf __attribute__ ((unused)), >> /* We handle it. */ >> mips_init_reloc (eh); >> HOOK (eh, reloc_simple_type); >> + HOOK (eh, section_type_name); >> + HOOK (eh, machine_flag_check); >> + HOOK (eh, machine_flag_name); >> + HOOK (eh, segment_type_name); >> + HOOK (eh, dynamic_tag_check); >> + HOOK (eh, dynamic_tag_name); >> + HOOK (eh, check_object_attribute); >> return eh; >> } > OK > But see below for also hooking reloc_type_check and reloc_type_name. =C2=A0=C2=A0=C2=A0 OK, I would add hook for reloc_type_check and reloc_type= _name. >>=20=20 >> typedef union >> @@ -2218,8 +2302,11 @@ enum >> Val_GNU_MIPS_ABI_FP_64 =3D 6, >> /* Using -mips32r2 -mfp64 -mno-odd-spreg. */ >> Val_GNU_MIPS_ABI_FP_64A =3D 7, >> + /* This is reserved for backward-compatibility with an earlier >> + implementation of the MIPS NaN2008 functionality. */ >> + Val_GNU_MIPS_ABI_FP_NAN2008 =3D 8, >> /* Maximum allocated FP ABI value. */ >> - Val_GNU_MIPS_ABI_FP_MAX =3D 7 >> + Val_GNU_MIPS_ABI_FP_MAX =3D 9 >> }; >>=20=20 >> /* HPPA specific definitions. */ > We take elf.h from glibc so please suggest these additions first on > libc-alpha@sourceware.org =C2=A0=C2=A0=C2=A0 I have submitted patch to libc-alpha@sourceware.org and = modify the=C2=A0 Val_GNU_MIPS_ABI_FP_MAX to 8. https://sourceware.org/pipermail/libc-alpha/2023-May/148112.html > >> diff --git a/src/readelf.c b/src/readelf.c >> index 6950204e..6e9a02c1 100644 >> --- a/src/readelf.c >> +++ b/src/readelf.c >> @@ -1125,7 +1125,7 @@ print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr) >> ehdr->e_ident[EI_VERSION] =3D=3D EV_CURRENT ? _("(current)") >> : "(\?\?\?)"); >>=20=20 >> - char buf[512]; >> + char buf[64]; >> printf (_(" OS/ABI: %s\n"), >> ebl_osabi_name (ebl, ehdr->e_ident[EI_OSABI], buf, sizeof (buf))); >> > Can you explain why reducing this buffer to 64 is OK? =C2=A0=C2=A0=C2=A0 Because the OS/ABI and Flags are not as long as 256, may= be I did not think enough, can not it be reduced? > >> @@ -2193,17 +2193,41 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr *ehdr, El= f_Scn *scn, GElf_Shdr *shdr) >> (long int) GELF_R_SYM (rel->r_info)); >> } >> else if (GELF_ST_TYPE (sym->st_info) !=3D STT_SECTION) >> - printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n", >> - class =3D=3D ELFCLASS32 ? 10 : 18, rel->r_offset, >> - likely (ebl_reloc_type_check (ebl, >> - GELF_R_TYPE (rel->r_info))) >> - /* Avoid the leading R_ which isn't carrying any >> - information. */ >> - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), >> - buf, sizeof (buf)) + 2 >> - : _(""), >> - class =3D=3D ELFCLASS32 ? 10 : 18, sym->st_value, >> - elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name)); >> + { >> + unsigned long inf =3D rel->r_info; >> + printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n", >> + class =3D=3D ELFCLASS32 ? 10 : 18, rel->r_offset, >> + likely (ebl_reloc_type_check (ebl, >> + GELF_R_TYPE (rel->r_info))) >> + /* Avoid the leading R_ which isn't carrying any >> + information. */ >> + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), >> + buf, sizeof (buf)) + 2 >> + : _(""), >> + class =3D=3D ELFCLASS32 ? 10 : 18, sym->st_value, >> + elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name)); >> + >> + /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 = */ >> + if(ebl->elf->class =3D=3D ELFCLASS64 && ebl->elf->state.e= lf64.ehdr->e_machine =3D=3D EM_MIPS) >> + { >> + unsigned int type2 =3D ELF64_MIPS_R_TYPE2 (inf); >> + unsigned int type3 =3D ELF64_MIPS_R_TYPE3 (inf); >> + const char * rtype2 =3D ebl_reloc_type_name (ebl, type2, buf, sizeo= f (buf)) + 2; >> + const char * rtype3 =3D ebl_reloc_type_name (ebl, type3, buf, sizeo= f (buf)) + 2; >> + printf(" Type2: "); >> + if (rtype2 =3D=3D NULL) >> + printf (_("unrecognized: %-7lx"), (unsigned long) type2 & = 0xffffffff); >> + else >> + printf ("%-17.17s", rtype2); >> + >> + printf ("\n Type3: "); >> + if (rtype3 =3D=3D NULL) >> + printf (_("unrecognized: %-7lx"), (unsigned long) type3 & = 0xffffffff); >> + else >> + printf ("%-17.17s", rtype3); >> + printf("\n"); >> + } >> + } > I think this is OK, but it would be good to see an example. =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 Relocation section [ 2] '.rela.text' for section [ 1] '.= text' at offset 0x29908 contains 1979 entries: =C2=A0 Offset=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 Type=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 Value=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Addend Name =C2=A0 0x0000000000000008=C2=A0 MIPS_GPREL16=C2=A0=C2=A0=C2=A0 000000000000= 000000=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 +0 .text =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A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=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Type3: MIPS_NONE=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0 0x0000000000000054=C2=A0 MIPS_CALL16=C2=A0=C2=A0=C2=A0=C2=A0 0000000= 00000000000=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 +0 gelf_update_ehdr =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Type2: MIPS_NONE=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Type3: MIPS_NONE =C2=A0=C2=A0=C2=A0 >> else >> { >> /* This is a relocation against a STT_SECTION symbol. */ >> @@ -2420,18 +2492,42 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, E= lf_Scn *scn, GElf_Shdr *shdr) >> (long int) (sym->st_shndx =3D=3D SHN_XINDEX >> ? xndx : sym->st_shndx)); >> else >> - printf ("\ >> + { >> + unsigned long inf =3D rel->r_info; >> + printf ("\ >> %#0*" PRIx64 " %-15s %#0*" PRIx64 " %+6" PRId64 " %s\n", >> - class =3D=3D ELFCLASS32 ? 10 : 18, rel->r_offset, >> - ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info)) >> - /* Avoid the leading R_ which isn't carrying any >> - information. */ >> - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), >> - buf, sizeof (buf)) + 2 >> - : _(""), >> - class =3D=3D ELFCLASS32 ? 10 : 18, sym->st_value, >> - rel->r_addend, >> - elf_strptr (ebl->elf, shstrndx, secshdr->sh_name)); >> + class =3D=3D ELFCLASS32 ? 10 : 18, rel->r_offset, >> + ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info)) >> + /* Avoid the leading R_ which isn't carrying any >> + information. */ >> + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), >> + buf, sizeof (buf)) + 2 >> + : _(""), >> + class =3D=3D ELFCLASS32 ? 10 : 18, sym->st_value, >> + rel->r_addend, >> + elf_strptr (ebl->elf, shstrndx, secshdr->sh_name)); >> + >> + /* copy binutils-2.34/binutils/readelf.c dump_relocat= ions+1753 */ >> + if(ebl->elf->class =3D=3D ELFCLASS64 && ebl->elf->state.elf64.ehdr-= >e_machine =3D=3D EM_MIPS) >> + { >> + unsigned int type2 =3D ELF64_MIPS_R_TYPE2 (inf); >> + unsigned int type3 =3D ELF64_MIPS_R_TYPE3 (inf); >> + const char * rtype2 =3D ebl_reloc_type_name (ebl, type2, buf, s= izeof (buf)) + 2; >> + const char * rtype3 =3D ebl_reloc_type_name (ebl, type3, buf, s= izeof (buf)) + 2; >> + printf(" Type2: "); >> + if (rtype2 =3D=3D NULL) >> + printf (_("unrecognized: %-7lx"), (unsigned long) type= 2 & 0xffffffff); >> + else >> + printf ("%-17.17s", rtype2); >> + >> + printf ("\n Type3: "); >> + if (rtype3 =3D=3D NULL) >> + printf (_("unrecognized: %-7lx"), (unsigned long) type= 3 & 0xffffffff); >> + else >> + printf ("%-17.17s", rtype3); >> + printf("\n"); >> + } >> + } >> } >> } >> } > And again. Adding testcase would be nice. > > So this handles both REL and RELA, does mips support both? =C2=A0=C2=A0=C2=A0 OK, I would like to add testcase. =C2=A0=C2=A0=C2=A0 Both support. > >> @@ -11633,7 +11729,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GEl= f_Ehdr *ehdr) >> GElf_Shdr shdr_mem; >> GElf_Shdr *shdr =3D gelf_getshdr (scn, &shdr_mem); >>=20=20 >> - if (shdr !=3D NULL && shdr->sh_type =3D=3D SHT_PROGBITS) >> + if (shdr !=3D NULL && (shdr->sh_type =3D=3D SHT_PROGBITS || shdr->sh= _type =3D=3D SHT_MIPS_DWARF)) >> { >> const char *name =3D elf_strptr (ebl->elf, shstrndx, >> shdr->sh_name); >> @@ -11663,7 +11759,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GEl= f_Ehdr *ehdr) >> GElf_Shdr shdr_mem; >> GElf_Shdr *shdr =3D gelf_getshdr (scn, &shdr_mem); >>=20=20 >> - if (shdr !=3D NULL && shdr->sh_type =3D=3D SHT_PROGBITS) >> + if (shdr !=3D NULL && (shdr->sh_type =3D=3D SHT_PROGBITS || shdr-= >sh_type =3D=3D SHT_MIPS_DWARF)) >> { >> static const struct >> { > OK. There are probably other places in the code where this might be an > issue. Maybe we need an is_debug_section_type macro? > > Cheers, > > Mark =C2=A0=C2=A0=C2=A0 Yes, I think it is good to add a new macro && need to ch= eck carefully. Thanks, Ying= --75f4d0ab47c081a1061ba265dd4b84a3da42ca0caff6ba9f7d75e006f2f4--