From: "Ying Huang" <ying.huang@oss.cipunited.com>
To: "Mark Wielaard" <mark@klomp.org>, <elfutils-devel@sourceware.org>
Cc: <yunqiang.su@oss.cipunited.com>
Subject: Re: [PATCH 3/5] elflint: Fix invalid type of relocation info and other issues on mips
Date: Wed, 17 May 2023 17:14:36 +0800 [thread overview]
Message-ID: <344cdd8f-cb0f-e705-5f10-024045b14f17@oss.cipunited.com> (raw)
In-Reply-To: <66059a3000132413a3d7ebede540309256c85cfd.camel@klomp.org>
[-- Attachment #1: Type: text/plain, Size: 8226 bytes --]
Hi,
在 2023/5/11 23:59, Mark Wielaard 写道:
> Hi,
>
> On Tue, 2023-04-11 at 16:12 +0800, Ying Huang wrote:
>> From: Ying Huang <ying.huang@oss.cipunited.com>
>>
>> add some check related functions
>> ---
>> backends/mips_init.c | 3 +++
>> backends/mips_symbol.c | 33 +++++++++++++++++++++++++++++++++
>> libebl/eblrelocvaliduse.c | 8 ++++++--
>> src/elflint.c | 23 ++++++++++++++++++++---
>> 4 files changed, 62 insertions(+), 5 deletions(-)
>>
>> diff --git a/backends/mips_init.c b/backends/mips_init.c
>> index 5bba822b..4c2f21b9 100644
>> --- a/backends/mips_init.c
>> +++ b/backends/mips_init.c
>> @@ -51,6 +51,9 @@ mips_init (Elf *elf __attribute__ ((unused)),
>> HOOK (eh, segment_type_name);
>> HOOK (eh, dynamic_tag_check);
>> HOOK (eh, dynamic_tag_name);
>> + HOOK (eh, machine_section_flag_check);
>> HOOK (eh, check_object_attribute);
>> + HOOK (eh, check_special_symbol);
>> + HOOK (eh, check_reloc_target_type);
>> return eh;
>> }
> OK. But see below for hooking reloc_valid_use
OK, I would add hook reloc_valid_use.
>> +/* Check whether given symbol's st_value and st_size are OK despite failing
>> + normal checks. */
>> +bool
>> +mips_check_special_symbol (Elf *elf,
>> + const GElf_Sym *sym __attribute__ ((unused)),
>> + const char *name __attribute__ ((unused)),
>> + const GElf_Shdr *destshdr)
>> +{
>> + size_t shstrndx;
>> + if (elf_getshdrstrndx (elf, &shstrndx) != 0)
>> + return false;
>> + const char *sname = elf_strptr (elf, shstrndx, destshdr->sh_name);
>> + if (sname == NULL)
>> + return false;
>> + return (strcmp (sname, ".got") == 0 || strcmp (sname, ".bss") == 0);
>> +}
> Could you add a comment why .got and .bss are special in this case?
raw code:
huangying@Sleepygon:~/elf/elfutils_4$ src/elflint src/nm
section [38] '.symtab': symbol 781 (_gp): st_value out of bounds
section [38] '.symtab': _DYNAMIC symbol size 0 does not match dynamic segment size 624
section [38] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol size 0 does not match .got section size 3736
huangying@Sleepygon:~/elf/elfutils_4$ src/elflint --gnu src/nm
section [38] '.symtab': symbol 781 (_gp): st_value out of bounds
After add '.got':
huangying@Sleepygon:~/elf/elfutils_4$ src/elflint src/nm
section [38] '.symtab': _DYNAMIC symbol size 0 does not match dynamic segment size 624
section [38] '.symtab': symbol 912 (_fbss): st_value out of bounds
section [38] '.symtab': symbol 1160 (__bss_start): st_value out of bounds
huangying@Sleepygon:~/elf/elfutils_4$ src/elflint --gnu src/nm
section [38] '.symtab': symbol 912 (_fbss): st_value out of bounds
After add '.bss':
huangying@Sleepygon:~/elf/elfutils_4$ src/elflint src/nm
section [38] '.symtab': _DYNAMIC symbol size 0 does not match dynamic segment size 624
huangying@Sleepygon:~/elf/elfutils_4$ src/elflint --gnu src/nm
No errors
And also has error , but make check is OK.
>
>> +/* Check whether SHF_MASKPROC flags are valid. */
>> +bool
>> +mips_machine_section_flag_check (GElf_Xword sh_flags)
>> +{
>> + return ((sh_flags &~ (SHF_MIPS_GPREL |
>> + SHF_MIPS_MERGE |
>> + SHF_MIPS_ADDR |
>> + SHF_MIPS_STRINGS)) == 0);
>> +}
> OK. But see below for checking other SHF_MIPS flags.
OK, add it:
diff --git a/backends/mips_symbol.c b/backends/mips_symbol.c
index 8787fcee..f4dee731 100644
--- a/backends/mips_symbol.c
+++ b/backends/mips_symbol.c
@@ -188,7 +188,11 @@ mips_machine_section_flag_check (GElf_Xword sh_flags)
return ((sh_flags &~ (SHF_MIPS_GPREL |
SHF_MIPS_MERGE |
SHF_MIPS_ADDR |
- SHF_MIPS_STRINGS)) == 0);
+ SHF_MIPS_STRINGS |
+ SHF_MIPS_NOSTRIP |
+ SHF_MIPS_LOCAL |
+ SHF_MIPS_NAMES |
+ SHF_MIPS_NODUPE)) == 0);
}
>
>> diff --git a/src/elflint.c b/src/elflint.c
>> index dd42dcb4..04f1ee92 100644
>> --- a/src/elflint.c
>> +++ b/src/elflint.c
>> @@ -935,7 +935,10 @@ section [%2d] '%s': symbol %zu (%s): non-local symbol outside range described in
>> }
>>
>> if (GELF_ST_TYPE (sym->st_info) == STT_SECTION
>> - && GELF_ST_BIND (sym->st_info) != STB_LOCAL)
>> + && GELF_ST_BIND (sym->st_info) != STB_LOCAL
>> + && ehdr->e_machine != EM_MIPS
>> + && strcmp (name, "_DYNAMIC_LINK") != 0
>> + && strcmp (name, "_DYNAMIC_LINKING") != 0)
> Could you add a comment here about both symbols not being local on
> MIPS?
raw code:
huangying@Sleepygon:~/elf/elfutils_4$ src/elflint --gnu src/nm
section [ 7] '.dynsym': symbol 166 (_DYNAMIC_LINKING): non-local section symbol
section [38] '.symtab': symbol 1052 (_DYNAMIC_LINKING): non-local section symbol
>
>> ERROR (_("\
>> section [%2d] '%s': symbol %zu (%s): non-local section symbol\n"),
>> idx, section_name (ebl, idx), cnt, name);
>> @@ -3789,6 +3792,12 @@ cannot get section header for section [%2zu] '%s': %s\n"),
>> && ebl_bss_plt_p (ebl))
>> good_type = SHT_NOBITS;
>>
>> + if (ehdr->e_machine == EM_MIPS
>> + && (strstr(special_sections[s].name, ".debug") != NULL))
>> + {
>> + good_type = SHT_MIPS_DWARF;
>> + }
> OK. You don't need explicit brackets here
OK
>
>> /* In a debuginfo file, any normal section can be SHT_NOBITS.
>> This is only invalid for DWARF sections and .shstrtab. */
>> if (shdr->sh_type != good_type
>> @@ -3953,8 +3962,16 @@ section [%2zu] '%s': size not multiple of entry size\n"),
>> sh_flags &= ~(GElf_Xword) SHF_MASKPROC;
>> }
>> if (sh_flags & SHF_MASKOS)
>> - if (gnuld)
>> - sh_flags &= ~(GElf_Xword) SHF_GNU_RETAIN;
>> + {
>> + if (gnuld)
>> + sh_flags &= ~(GElf_Xword) SHF_GNU_RETAIN;
>> + if (ehdr->e_machine == EM_MIPS)
>> + {
>> + if(sh_flags == SHF_MIPS_NOSTRIP || sh_flags == SHF_MIPS_LOCAL
>> + || sh_flags == SHF_MIPS_NAMES || sh_flags == SHF_MIPS_NODUPE)
>> + sh_flags &= ~shdr->sh_flags;
>> + }
>> + }
>> if (sh_flags != 0)
>> ERROR (_("section [%2zu] '%s' contains unknown flag(s)"
>> " %#" PRIx64 "\n"),
> Can this be checked with the machine_section_flag_check hook?
>
> Thanks,
>
> Mark
OK, add it:
diff --git a/src/elflint.c b/src/elflint.c
index 04f1ee92..56244051 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -3965,12 +3965,13 @@ section [%2zu] '%s': size not multiple of entry size\n"),
{
if (gnuld)
sh_flags &= ~(GElf_Xword) SHF_GNU_RETAIN;
- if (ehdr->e_machine == EM_MIPS)
- {
- if(sh_flags == SHF_MIPS_NOSTRIP || sh_flags == SHF_MIPS_LOCAL
- || sh_flags == SHF_MIPS_NAMES || sh_flags == SHF_MIPS_NODUPE)
- sh_flags &= ~shdr->sh_flags;
- }
+ if (!ebl_machine_section_flag_check (ebl,
+ sh_flags & SHF_MASKOS))
+ ERROR (_("section [%2zu] '%s'"
+ " contains invalid os-specific flag(s)"
+ " %#" PRIx64 "\n"),
+ cnt, section_name (ebl, cnt), sh_flags & SHF_MASKOS);
+ sh_flags &= ~(GElf_Xword) SHF_MASKOS;
Thanks,
Ying
next prev parent reply other threads:[~2023-05-17 9:14 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-11 8:12 [PATCH 0/5] Add support for MIPS Ying Huang
2023-04-11 8:12 ` [PATCH 1/5] strip: Adapt src/strip -o -f on mips Ying Huang
2023-05-09 15:15 ` Mark Wielaard
2023-05-16 6:38 ` Ying Huang
2023-05-21 21:13 ` Mark Wielaard
2023-05-24 6:21 ` Ying Huang
2023-05-16 6:46 ` Ying Huang
2023-05-16 7:34 ` Ying Huang
2023-05-21 21:14 ` Mark Wielaard
2023-05-26 2:48 ` Ying Huang
2023-05-16 8:05 ` [EXTERNAL] " Luke Diamand
2023-04-11 8:12 ` [PATCH 2/5] readelf: Adapt src/readelf -h/-S/-r/-w/-l/-d/-a " Ying Huang
2023-05-11 14:31 ` Mark Wielaard
2023-05-16 8:01 ` Ying Huang
2023-07-24 8:35 ` Ying Huang
2023-07-25 8:15 ` Ying Huang
2023-07-27 6:08 ` Ying Huang
2023-08-01 21:43 ` Mark Wielaard
2023-08-01 13:14 ` Mark Wielaard
2023-08-01 9:25 ` Mark Wielaard
2023-04-11 8:12 ` [PATCH 3/5] elflint: Fix invalid type of relocation info and other issues " Ying Huang
2023-05-11 15:59 ` Mark Wielaard
2023-05-17 9:14 ` Ying Huang [this message]
2023-04-11 8:12 ` [PATCH 4/5] stack: Fix stack unwind failure " Ying Huang
2023-05-11 16:07 ` Mark Wielaard
2023-05-18 6:14 ` Ying Huang
2023-04-11 8:12 ` [PATCH 5/5] backends: Fix run-native-test.sh and run-funcretval++11.sh run fail " Ying Huang
2023-05-11 16:38 ` Mark Wielaard
2023-05-18 9:06 ` Ying Huang
2023-05-04 2:24 ` [PATCH 0/5] Add support for MIPS 黄莺
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=344cdd8f-cb0f-e705-5f10-024045b14f17@oss.cipunited.com \
--to=ying.huang@oss.cipunited.com \
--cc=elfutils-devel@sourceware.org \
--cc=mark@klomp.org \
--cc=yunqiang.su@oss.cipunited.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).