public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: "Ying Huang" <ying.huang@oss.cipunited.com>
To: "Mark Wielaard" <mark@klomp.org>
Cc: <elfutils-devel@sourceware.org>, <yunqiang.su@oss.cipunited.com>
Subject: Re: [PATCH 1/5] strip: Adapt src/strip -o -f on mips
Date: Fri, 26 May 2023 10:48:54 +0800	[thread overview]
Message-ID: <0692e517-f65b-2772-2a6e-10bd92e7408a@oss.cipunited.com> (raw)
In-Reply-To: <20230521211447.GI3420@gnu.wildebeest.org>

[-- Attachment #1: Type: text/plain, Size: 3489 bytes --]

Hi Mark,

在 2023/5/22 05:14, Mark Wielaard 写道:
> Hi Ying,
>
> On Tue, May 16, 2023 at 03:34:01PM +0800, Ying Huang wrote:
>> 在 2023/5/16 14:46, Ying Huang 写道:
>>>>> libelf/elf_getdata.c: Some eu-utils use read-mmap method to map file,
>>>>> so we need to malloc and memcpy raw data to avoid segment fault. After
>>>>> modification, the correct value are saved in the malloced memory not in
>>>>> process address space.
>>>> Where do these segfaults show up?
>>>     The screenshot of the segment error was not uploaded successfully in the last email, upload again.
> Sorry, the mailinglist seems to strip the image attachements.
>
>> huangying@Sleepygon:~/elf/elfutils_4$ src/elflint src/nm.o
>> Segmentation fault
>> huangying@Sleepygon:~/elf/elfutils_4$ src/elflint src/strip.o
>> Segmentation fault
> When running under gdb, what is the backtrace of the crash?
>
> Thanks,
>
> Mark

huangying@Sleepygon:~/elf/elfutils_4$ src/elflint src/nm.o

Segmentation fault (core dumped)

huangying@Sleepygon:~/elf/elfutils_4$ gdb src/elflint

...

(gdb) bt
#0  convert_data (type=ELF_T_RELA, size=24912, data=1, eclass=<optimized out>, scn=0xaad3698f98) at elf_getdata.c:254
#1  __libelf_set_data_list_rdlock (scn=0xaad3698f98, wrlocked=<optimized out>) at elf_getdata.c:515
#2  0x000000fff3862f14 in __elf_getdata_rdlock (scn=0xaad3698f98, data=<optimized out>) at elf_getdata.c:622
#3  0x000000fff3862f54 in elf_getdata (scn=<optimized out>, data=<optimized out>) at elf_getdata.c:640
#4  0x000000aaac571c9c in check_rela (ebl=0xaad369b120, ehdr=0xfffb9451b0, shdr=0xfffb945008, idx=<optimized out>) at elflint.c:1500
#5  0x000000aaac574e40 in check_sections (ebl=0xaad369b120, ehdr=0xfffb9451b0) at elflint.c:4198
#6  0x000000aaac5784ac in process_elf_file (only_one=<optimized out>, size=<optimized out>, fname=<optimized out>, suffix=<optimized out>, prefix=<optimized out>, elf=<optimized out>) at elflint.c:4842
#7  process_file (fd=<optimized out>, elf=<optimized out>, prefix=<optimized out>, suffix=<optimized out>, fname=<optimized out>, size=<optimized out>, only_one=<optimized out>) at elflint.c:241
#8  0x000000aaac5688fc in main (argc=<optimized out>, argv=0xfffb9455d8) at elflint.c:174

...


    If I did not malloc to scn->data_base, would occur Segment fault when we want to operate this space "&scn->data_list.data.d". Because src/elflint use read-mmap method to map file.

    Show 10 lines of code "libelf/elf_getdata.c" starting at line 254:

huangying@Sleepygon:~/elf/elfutils_4$ cat libelf/elf_getdata.c | tail -n +254 | head -n 10
            for (int cnt = 0; cnt < nentries; cnt++)
              {
            Elf_Data_Scn *data_scn = (Elf_Data_Scn *) &scn->data_list.data.d;
                Elf64_Rela *value = &((Elf64_Rela *) data_scn->d.d_buf)[cnt];
                Elf64_Xword info = value->r_info;
                value->r_info = (((info & 0xffffffff) << 32)
                       | ((info >> 56) & 0xff)
                   | ((info >> 40) & 0xff00)
                   | ((info >> 24) & 0xff0000)
                   | ((info >> 8) & 0xff000000));


    Show elflint map method in src/elflint.c:

    /* Create an `Elf' descriptor. */

    Elf *elf = elf_begin (fd, ELF_C_READ_MMAP, NULL);


Thanks,

Ying

  reply	other threads:[~2023-05-26  2:49 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 [this message]
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
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=0692e517-f65b-2772-2a6e-10bd92e7408a@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).