public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Paul E Murphy <murphyp@linux.ibm.com>
To: Alan Modra <amodra@gmail.com>, libc-alpha@sourceware.org
Cc: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
Subject: Re: [PowerPC64] Use medium model toc accesses throughout
Date: Fri, 28 Jan 2022 11:48:44 -0600	[thread overview]
Message-ID: <5a44c0d1-9cbd-aac8-e60a-3627e58b023b@linux.ibm.com> (raw)
In-Reply-To: <Ye1NJQwEpe7AyNYD@squeak.grove.modra.org>



On 1/23/22 6:42 AM, Alan Modra via Libc-alpha wrote:
> The PowerPC64 linker edits medium model toc-indirect code to toc-pointer
> relative:
> 	addis r9,r2,tc_entry_for_var@toc@ha
> 	ld r9,tc_entry_for_var@toc@l(r9)
> becomes
> 	addis r9,r2,(var-.TOC.)@ha
> 	addi r9,r9,(var-.TOC.)@l
> when "var" is known to be local to the binary.  This isn't done for
> small-model toc-indirect code, because "var" is almost guaranteed to
> be too far away from .TOC. for a 16-bit signed offset.  And, because
> the analysis of which .toc entry can be removed becomes much more
> complicated in objects that mix code models, they aren't removed if
> any small-model toc sequence appears in an object file.
> 
> Unfortunately glibc's build of ld.so smashes the needed objects
> together in a ld -r linking stage.  This means the GOT/TOC is left
> with a whole lot of relative relocations which is untidy, but in
> itself is not a serious problem.  However, static-pie on powerpc64
> bombs due to a segfault caused by one of the small-model accesses
> before _dl_relocate_static_pie.  (The very first one in rcrt1.o
> passing start_addresses in r8 to __libc_start_main.)
> 
> So this patch makes all the toc/got accesses in assembly medium code
> model, and a couple of functions hidden.  By itself this is *not*
> enough to give us working static-pie, but it is useful anyway to
> enable better linker optimisation.
> 
> There's a serious problem in libgcc too.  libgcc ifuncs access the
> AT_HWCAP words stored in the tcb with an offset from the thread
> pointer (r13), but r13 isn't set at the time _dl_relocate_static_pie
> runs, and I'm loathe to try calling init_tls early.  A better approach
> that might work is to fake r13 so that _dl_hwcap is at the expected
> offset where we'd normally find the tcb hwcap words.
> 
> Tested for regressions with a powerpc64le-linux build and test run.
> OK to apply?
> 

> diff --git a/sysdeps/powerpc/powerpc64/dl-trampoline.S b/sysdeps/powerpc/powerpc64/dl-trampoline.S
> index 23debc2faf..45b821607b 100644
> --- a/sysdeps/powerpc/powerpc64/dl-trampoline.S
> +++ b/sysdeps/powerpc/powerpc64/dl-trampoline.S
> @@ -32,6 +32,7 @@
>      because gcc as of 2010/05 doesn't allocate a proper stack frame for
>      a function that makes no calls except for __tls_get_addr and we
>      might be here resolving the __tls_get_addr call.  */
> +	.hidden _dl_runtime_resolve
>   #define INT_PARMS FRAME_MIN_SIZE
>   ENTRY (_dl_runtime_resolve, 4)
>   	stdu	r1,-FRAME_SIZE(r1)
> @@ -195,6 +196,7 @@ END(_dl_runtime_resolve)
>      parm1 (r3) and the index (r0) needs to be converted to an offset
>      (index * 24) in parm2 (r4).  */
>   #ifndef PROF
> +	.hidden _dl_profile_resolve
>   ENTRY (_dl_profile_resolve, 4)
>   /* Spill r30, r31 to preserve the link_map* and reloc_addr, in case we
>      need to call _dl_audit_pltexit.  */

LGTM (this should wait until after the freeze), though these two changes 
seem orthogonal to the commit title.

For my education, why are are small model accesses used in these files?

  parent reply	other threads:[~2022-01-28 17:48 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-23 12:42 Alan Modra
2022-01-24  3:47 ` [PATCH 2/5] [PowerPC64] Set up thread register for _dl_relocate_static_pie Alan Modra
2022-02-16 23:02   ` Paul E Murphy
2022-02-19  0:49     ` Alan Modra
2022-01-24  3:50 ` [PATCH 3/5] [PowerPC] Relocate stinfo->main Alan Modra
2022-01-24  4:48   ` H.J. Lu
2022-01-24  6:51     ` Alan Modra
2022-01-24  3:52 ` [PATCH 4/5] Constify a variable in dl_vdso_vsym Alan Modra
2022-01-24  4:06 ` [PATCH 5/5] Enable static-pie on powerpc64 Alan Modra
2022-01-27 18:39   ` Florian Weimer
2022-01-28  8:45     ` Alan Modra
2022-01-28 17:48 ` Paul E Murphy [this message]
2022-01-29  1:24   ` [PowerPC64] Use medium model toc accesses throughout Alan Modra
2022-02-28  6:40 ` [PATCH v2 0/4] PowerPC64 static-pie Alan Modra
2022-02-28  6:40   ` [PATCH v2 1/4] powerpc64: Use medium model toc accesses throughout Alan Modra
2022-04-08 22:28     ` Tulio Magno Quites Machado Filho
2022-02-28  6:40   ` [PATCH v2 2/4] powerpc64: Set up thread register for _dl_relocate_static_pie Alan Modra
2022-04-08 22:28     ` Tulio Magno Quites Machado Filho
2022-02-28  6:40   ` [PATCH v2 3/4] powerpc: Relocate stinfo->main Alan Modra
2022-04-08 22:32     ` Tulio Magno Quites Machado Filho
2022-02-28  6:40   ` [PATCH v2 4/4] powerpc64: Enable static-pie Alan Modra
2022-04-08 22:49     ` Tulio Magno Quites Machado Filho
2022-04-14  1:16       ` Alan Modra
2022-04-14  3:42         ` Fangrui Song
2022-04-20  7:21         ` [PATCH v3] " Alan Modra
2022-03-04 12:48   ` [PATCH v2 0/4] PowerPC64 static-pie Alan Modra
2022-04-08  8:06     ` Alan Modra
2022-04-09  0:14       ` Fangrui Song
2022-04-14  0:33         ` Alan Modra
2022-04-14  1:54           ` DT_RELR without libc.so dependency H.J. Lu
2022-04-14  3:43             ` Fangrui Song
2022-04-14  5:18             ` Alan Modra
2022-04-14 17:55               ` H.J. Lu
2022-04-08 22:27   ` [PATCH v2 0/4] PowerPC64 static-pie Tulio Magno Quites Machado Filho
2022-04-11  1:38     ` Alan Modra

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=5a44c0d1-9cbd-aac8-e60a-3627e58b023b@linux.ibm.com \
    --to=murphyp@linux.ibm.com \
    --cc=amodra@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=tuliom@linux.ibm.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).