public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Wang, Yanzhang" <yanzhang.wang@intel.com>
To: Andreas Schwab <schwab@suse.de>
Cc: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>,
	"adhemerval.zanella@linaro.org" <adhemerval.zanella@linaro.org>
Subject: RE: [PATCH v3] RISC-V: Enable static-pie.
Date: Thu, 1 Feb 2024 12:39:58 +0000	[thread overview]
Message-ID: <IA1PR11MB6466D47B714CC8F681FB6873F2432@IA1PR11MB6466.namprd11.prod.outlook.com> (raw)
In-Reply-To: <mvmo7d49uk3.fsf@suse.de>

Hi Andreas,

Sorry for the late response. Thanks your comments! And I don't quite
follow your comments. Could you please give some further information?

> (gdb) ni
> _start () at ../sysdeps/riscv/start.S:74
> 74              lla   gp, __global_pointer$
> 1: x/i $pc
> => 0x3ff7f59ec6 <load_gp>:      auipc   gp,0xa0
> (gdb)
> 0x0000003ff7f59eca      74              lla   gp, __global_pointer$
> 1: x/i $pc
> => 0x3ff7f59eca <_start+38>:    add     gp,gp,706
> (gdb)
> load_gp () at ../sysdeps/riscv/start.S:76
> 76              ret
> 1: x/i $pc
> => 0x3ff7f59ece <load_gp+8>:    ret
> (gdb)
> _start () at ../sysdeps/riscv/start.S:51
> 51              mv    a5, a0  /* rtld_fini.  */
> 1: x/i $pc
> => 0x3ff7f59ea8 <_start+4>:     mv      a5,a0
> (gdb)
> 53              la   a0, main
> 1: x/i $pc
> => 0x3ff7f59eaa <_start+6>:     auipc   a0,0x9e
> (gdb)
> 0x0000003ff7f59eae      53              la   a0, main
> 1: x/i $pc
> => 0x3ff7f59eae <_start+10>:    ld      a0,-74(a0)
> (gdb)
> 54              REG_L a1, 0(sp)      /* argc.  */
> 1: x/i $pc
> => 0x3ff7f59eb2 <_start+14>:    ld      a1,0(sp)
> (gdb) i reg a0
> a0             0x0      0

The first, it seems you have constructed a test case which should fail
this patch. But based on your gdb comment, I'm not sure which step is
not correct. Should the a0 register be non-zero or the gp register be
wrong? 

---

The code in the if will try to lookup the __global_pointer$ and move to the
gp register. It will be failed because l->l_scope is NULL when static-pie.
So I added this checking to avoid this failure.

> > +  if (l->l_type == lt_executable && l->l_scope != NULL)


> This is not the right way to test for static PIE, it tries to access a
> non-relocated non-zero pointer.  The mold linker, when producing relative
> relocations, puts the addend both in the relocation addend and the
> relocated field, which is perfectly valid to do, so this is non-zero here.

The second, do you mean there's a case that l->l_scope is not NULL when built
with static-pie? Or we should not access the members in link_map ?

Thanks,
Yanzhang

> -----Original Message-----
> From: Andreas Schwab <schwab@suse.de>
> Sent: Monday, January 29, 2024 8:46 PM
> To: Wang, Yanzhang <yanzhang.wang@intel.com>
> Cc: libc-alpha@sourceware.org; adhemerval.zanella@linaro.org
> Subject: Re: [PATCH v3] RISC-V: Enable static-pie.
> 
> On Jan 02 2024, yanzhang.wang@intel.com wrote:
> 
> > diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
> > index ffb8c4aaa0..0cbb476c05 100644
> > --- a/sysdeps/riscv/dl-machine.h
> > +++ b/sysdeps/riscv/dl-machine.h
> > @@ -348,7 +348,7 @@ elf_machine_runtime_setup (struct link_map *l,
> struct r_scope_elem *scope[],
> >        gotplt[1] = (ElfW(Addr)) l;
> >      }
> >
> > -  if (l->l_type == lt_executable)
> > +  if (l->l_type == lt_executable && l->l_scope != NULL)
> 
> This is not the right way to test for static PIE, it tries to access a
> non-relocated non-zero pointer.  The mold linker, when producing relative
> relocations, puts the addend both in the relocation addend and the
> relocated field, which is perfectly valid to do, so this is non-zero here.
> 
> --
> Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8
> 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7 "And now for something
> completely different."

  reply	other threads:[~2024-02-01 12:40 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-10 23:33 [PATCH] " yanzhang.wang
2023-08-11  1:57 ` Palmer Dabbelt
2023-08-13 12:20   ` Wang, Yanzhang
2023-08-15 11:46     ` Adhemerval Zanella Netto
2023-09-09  3:17       ` Wang, Yanzhang
2023-09-09  3:30         ` Palmer Dabbelt
2023-09-09  6:54           ` Wang, Yanzhang
2023-09-11 14:14             ` Palmer Dabbelt
2023-09-11 13:34           ` Darius Rad
2023-09-11 17:28             ` DJ Delorie
2023-09-11 16:17           ` Adhemerval Zanella Netto
2023-09-20 13:36             ` Palmer Dabbelt
2023-09-21 13:47               ` Wang, Yanzhang
2023-10-17  8:28                 ` Wang, Yanzhang
2023-10-17 13:42                 ` Adhemerval Zanella Netto
2023-10-24  5:59                   ` Wang, Yanzhang
2023-10-24 11:39                     ` Adhemerval Zanella Netto
2023-10-26  3:30                       ` Wang, Yanzhang
2023-08-14 13:12 ` Carlos O'Donell
2023-08-15  1:48   ` Wang, Yanzhang
2023-08-15  1:44 ` [PATCH v2] " yanzhang.wang
2023-12-17 13:16   ` Wang, Yanzhang
2023-12-19 17:44   ` Adhemerval Zanella Netto
2024-01-02 11:02     ` Wang, Yanzhang
2024-01-02 10:54 ` [PATCH v3] " yanzhang.wang
2024-01-02 18:30   ` Adhemerval Zanella Netto
2024-01-17 12:23   ` Andreas Schwab
2024-01-29 12:46   ` Andreas Schwab
2024-02-01 12:39     ` Wang, Yanzhang [this message]
2024-02-01 12:53       ` Andreas Schwab
2024-05-21 11:13   ` Maciej W. Rozycki

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=IA1PR11MB6466D47B714CC8F681FB6873F2432@IA1PR11MB6466.namprd11.prod.outlook.com \
    --to=yanzhang.wang@intel.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@suse.de \
    /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).