aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/powerpc/powerpc64/sysdep.h
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-01-22 11:48:50 +1030
committerAlan Modra <amodra@gmail.com>2022-04-10 08:33:06 +0930
commitd6efcc118e406a1cfeb309f835d7118df53419bb (patch)
tree31bbfdb82f662a47fece23a2e7f1324ea0c3ce6e /sysdeps/powerpc/powerpc64/sysdep.h
parent30afd8c44d6a0a8b0eddbadecb02c9b9dad3facf (diff)
downloadglibc-d6efcc118e406a1cfeb309f835d7118df53419bb.tar
glibc-d6efcc118e406a1cfeb309f835d7118df53419bb.tar.gz
glibc-d6efcc118e406a1cfeb309f835d7118df53419bb.tar.bz2
glibc-d6efcc118e406a1cfeb309f835d7118df53419bb.zip
powerpc64: Use medium model toc accesses throughout
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 in isolation 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. A followup patch will fix that. Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
Diffstat (limited to 'sysdeps/powerpc/powerpc64/sysdep.h')
-rw-r--r--sysdeps/powerpc/powerpc64/sysdep.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/sysdeps/powerpc/powerpc64/sysdep.h b/sysdeps/powerpc/powerpc64/sysdep.h
index 3fec06e0df..011068b290 100644
--- a/sysdeps/powerpc/powerpc64/sysdep.h
+++ b/sysdeps/powerpc/powerpc64/sysdep.h
@@ -469,14 +469,16 @@ LT_LABELSUFFIX(name,_name_end): ; \
.tc _rtld_global_ro[TC],_rtld_global_ro
# endif
# define __GLRO(rOUT, var, offset) \
- ld rOUT,.LC__ ## var@toc(r2); \
+ addis rOUT,r2,.LC__ ## var@toc@ha; \
+ ld rOUT,.LC__ ## var@toc@l(rOUT); \
lwz rOUT,offset(rOUT)
#else
# define __GLRO_DEF(var) \
.LC__ ## var: \
.tc _ ## var[TC],_ ## var
# define __GLRO(rOUT, var, offset) \
- ld rOUT,.LC__ ## var@toc(r2); \
+ addis rOUT,r2,.LC__ ## var@toc@ha; \
+ ld rOUT,.LC__ ## var@toc@l(rOUT); \
lwz rOUT,0(rOUT)
#endif