public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nelson Chu <nelson@rivosinc.com>
To: Alan Modra <amodra@gmail.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] RISC-V: Segment fault in riscv_elf_append_rela.
Date: Thu, 9 Mar 2023 19:41:05 +0800	[thread overview]
Message-ID: <CAPpQWtA0R=0dw3J59=SQGatCEhDJCddrB+NGJafyEK15PAemmQ@mail.gmail.com> (raw)
In-Reply-To: <ZAmZ9oWUgUqfWGiC@squeak.grove.modra.org>

Thanks for the suggestion :) Seems like there are two better solution for now,

1.  Add the BFD_ASSERT before calling every riscv_elf_append_rela to
make sure the written section exists, and then just return in the
riscv_elf_append_rela if the section doesn't exist, to avoid the
segment fault.  We will know which section is NULL, and where the
ASSERT code is.  Besides that, since parts of the callers already have
the BFD_ASSERT check before calling riscv_elf_append_rela, so this
seems the right way to do it.

2. Report error and return false if the section doesn't exist in the
riscv_elf_append_rela, and then the callers "goto out" to release the
unused data structures in the riscv_elf_relocate_section, or return
false if the caller is riscv_elf_finish_dynamic_symbol.  But it is
hard to report the more detailed errors in the riscv_elf_append_rela,
it is not easy to know which caller code meets the problem.

I think solution 1 should be better than solution 2?

Thanks
Nelson

On Thu, Mar 9, 2023 at 4:34 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Thu, Mar 09, 2023 at 04:04:46PM +0800, Nelson Chu wrote:
> >     * elfnn-riscv.c (riscv_elf_append_rela): Abort when the dynamic section
> >     doesn't exist.
>
> It would be nicer to handle this more gracefully by returning an error
> to the caller.  An abort isn't much better than a segmentation fault
> if this can be triggered by user input.
>
> --
> Alan Modra
> Australia Development Lab, IBM

  reply	other threads:[~2023-03-09 11:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09  8:04 Nelson Chu
2023-03-09  8:33 ` Alan Modra
2023-03-09 11:41   ` Nelson Chu [this message]
2023-03-09 12:59     ` Alan Modra
2023-03-10 10:06       ` Nelson Chu

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='CAPpQWtA0R=0dw3J59=SQGatCEhDJCddrB+NGJafyEK15PAemmQ@mail.gmail.com' \
    --to=nelson@rivosinc.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /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).