public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Yangyu Chen <cyy@cyyself.name>
To: Palmer Dabbelt <palmer@rivosinc.com>
Cc: libc-alpha@sourceware.org, kito.cheng@sifive.com,
	vincent.chen@sifive.com, schwab@suse.de,
	Jessica Clarke <jrtc27@jrtc27.com>, Vivian Wang <uwu@dram.page>,
	Andrew Waterman <andrew@sifive.com>,
	Piyou Chen <piyou.chen@sifive.com>
Subject: Re: Re: [PATCH v2] RISC-V: Fix IFUNC resolver cannot access gp pointer
Date: Wed, 13 Nov 2024 18:29:44 +0800	[thread overview]
Message-ID: <tencent_024A10521BD1510057326637C4A5F1850F05@qq.com> (raw)
In-Reply-To: <mhng-b09f06ce-b46f-41d2-8b1a-d2765799ed4a@palmer-ri-x1c9>



On 10/30/24 11:10, Palmer Dabbelt wrote:
>> On 10/16/24 01:01, Yangyu Chen wrote:
>>> In some cases, an IFUNC resolver may need to access the gp pointer to
>>> resolve the function address. Such an object may have l_relocated == 0.
>>> In this case, the GP register will not be set up. Thus, the IFUNC
>>> resolver cannot access the gp pointer. This patch fixes this issue by
>>> relaxing the check of l_relocated in elf_machine_runtime_setup.
>>>
>>> As for the original Bug 31317, since the static-linked executable has
>>> already set up the gp pointer, we don't need to execute the code to set
>>> up the gp pointer again. I have also reproduced and checked Bug 31317,
>>> this patch can fix the issue.
> 
> We had a pretty similar issue with the hwprobe IFUNC stuff, and IIRC the 
> result there was that it's just not safe to look up global symbols from 
> an IFUNC.
> 

Hi Palmer,

I think there is no ABI grey area for dynamically linked executables 
since we have the following statements in the riscv-elf doc [1]:

`__global_pointer$` must be exported in the dynamic symbol table of 
dynamically linked executables if there are any GP-relative accesses in 
the executable.

And after some discussions [2] about adding norelax attribute in the 
riscv-c-api-doc, I think this patch is the right way to go.

How do you think about this explanation?

Thanks,
Yangyu Chen

[1] 
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blame/3799de41be668bc42cad7fac9ccc28d20f3fcb5e/riscv-elf.adoc#L389
[2] https://github.com/riscv-non-isa/riscv-c-api-doc/pull/94

>>> Closes: BZ #32269
>>> Fixes: 96d1b9ac23 ("RISC-V: Fix the static-PIE non-relocated object 
>>> check")
>>> Signed-off-by: Yangyu Chen <cyy@cyyself.name>
>>> ---
>>>   sysdeps/riscv/dl-machine.h | 4 +++-
>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
>>> index b2f28697f7..10a36d6701 100644
>>> --- a/sysdeps/riscv/dl-machine.h
>>> +++ b/sysdeps/riscv/dl-machine.h
>>> @@ -348,7 +348,8 @@ elf_machine_runtime_setup (struct link_map *l, 
>>> struct r_scope_elem *scope[],
>>>         gotplt[1] = (ElfW(Addr)) l;
>>>       }
>>>
>>> -  if (l->l_type == lt_executable && l->l_relocated)
>>> +#ifdef SHARED
>>> +  if (l->l_type == lt_executable)
>>>       {
>>>         /* The __global_pointer$ may not be defined by the linker if the
>>>        $gp register does not be used to access the global variable
>>> @@ -368,6 +369,7 @@ elf_machine_runtime_setup (struct link_map *l, 
>>> struct r_scope_elem *scope[],
>>>             : "r" (ref->st_value)
>>>           );
>>>       }
>>> +#endif
>>>   #endif
>>>     return lazy;
>>>   }
> 



      parent reply	other threads:[~2024-11-13 10:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15 17:01 Yangyu Chen
2024-10-30  2:58 ` Yangyu Chen
2024-10-30  3:10   ` Palmer Dabbelt
2024-10-30  6:50     ` Yangyu Chen
2024-10-30  7:36       ` Kito Cheng
2024-10-30  9:22         ` Florian Weimer
2024-10-30 10:26           ` Kito Cheng
2024-10-30 10:42             ` Florian Weimer
2024-10-30 10:48               ` Kito Cheng
2024-10-30 11:09                 ` Florian Weimer
2024-10-30 18:28                   ` Yangyu Chen
2024-10-31 10:07                     ` Kito Cheng
2024-10-31 10:32                     ` Florian Weimer
2024-10-31 10:35                       ` Yangyu Chen
2024-10-31 10:51                         ` Florian Weimer
2024-11-13 10:29     ` Yangyu Chen [this message]

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=tencent_024A10521BD1510057326637C4A5F1850F05@qq.com \
    --to=cyy@cyyself.name \
    --cc=andrew@sifive.com \
    --cc=jrtc27@jrtc27.com \
    --cc=kito.cheng@sifive.com \
    --cc=libc-alpha@sourceware.org \
    --cc=palmer@rivosinc.com \
    --cc=piyou.chen@sifive.com \
    --cc=schwab@suse.de \
    --cc=uwu@dram.page \
    --cc=vincent.chen@sifive.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).