public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: liuzhensong <liuzhensong@loongson.cn>, binutils@sourceware.org
Cc: Lulu Cheng <chenglulu@loongson.cn>, Wang Xuerui <i@xen0n.name>,
	Chenghua Xu <xuchenghua@loongson.cn>
Subject: Re: [PATCH 2/2] LoongArch: Fix R_LARCH_IRELATIVE insertion after elf_link_sort_relocs
Date: Sat, 17 Sep 2022 04:11:06 +0800	[thread overview]
Message-ID: <f262b6b355809d1d6b757f90b792bcab6ab71872.camel@xry111.site> (raw)
In-Reply-To: <939eebd1-365d-72c5-5b2c-43bd6e0f1ff2@loongson.cn>

On Thu, 2022-09-15 at 21:03 +0800, liuzhensong wrote:
> It May be unnecessary find the slot in section of .rela.dyn.
> 
> The slot of R_LARCH_IRELATIVE is within the scope relplt->contents (the 
> space
> 
> is calculated in function local_allocate_ifunc_dyn_relocs).
> 
> We can find the slot just in relplt->contents(Only for dynamic ifunc. I 
> did not test for static ifunc.).

The problem is loongarch_elf_finish_dynamic_symbol runs after
elf_link_sort_relocs.  elf_link_sort_relocs basically does:

(pseudo code)

buffer = []
for section in {input of .rela.dyn}
    buffer += (section.content) as [RELA]

buffer.sort_by(some_comparator)

buffer = buffer as [byte]
for section in {input of .rela.dyn}
    section.content = buffer[..section.content.len()]
    buffer = buffer[section.content.len()..]

So a "slot" in relplt->contents can end up elsewhere.  You can read the
code of elf_link_sort_relocs to see it...

I can try to write a test case for this, but it's 04:00 AM now so I'd do
it after a sleep...
-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2022-09-16 20:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-13 15:44 [PATCH 0/2] LoongArch: Fix two bugs breaking IFUNC in static PIE Xi Ruoyao
2022-09-13 15:44 ` [PATCH 1/2] LoongArch: Avoid heap-buffer-overflow in loongarch_elf_relocate_section Xi Ruoyao
2022-09-14  8:57   ` liuzhensong
2022-09-14 10:15     ` Xi Ruoyao
2022-09-14 11:15       ` Xi Ruoyao
2022-09-15  1:47         ` liuzhensong
2022-09-15  2:56           ` Xi Ruoyao
2022-09-15  3:54             ` liuzhensong
2022-09-15  6:13               ` Xi Ruoyao
2022-09-13 15:44 ` [PATCH 2/2] LoongArch: Fix R_LARCH_IRELATIVE insertion after elf_link_sort_relocs Xi Ruoyao
2022-09-15 13:03   ` liuzhensong
2022-09-16 20:11     ` Xi Ruoyao [this message]
2022-09-18  9:58       ` Xi Ruoyao

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=f262b6b355809d1d6b757f90b792bcab6ab71872.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=binutils@sourceware.org \
    --cc=chenglulu@loongson.cn \
    --cc=i@xen0n.name \
    --cc=liuzhensong@loongson.cn \
    --cc=xuchenghua@loongson.cn \
    /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).