This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug dynamic-link/22638] static binaries are broken on sparc due to use of memcpy(behind IFUNC redirector) in __libc_start_tls()
- From: "slyfox at inbox dot ru" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 20 Dec 2017 23:00:46 +0000
- Subject: [Bug dynamic-link/22638] static binaries are broken on sparc due to use of memcpy(behind IFUNC redirector) in __libc_start_tls()
- Auto-submitted: auto-generated
- References: <bug-22638-131@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=22638
--- Comment #6 from Sergei Trofimovich <slyfox at inbox dot ru> ---
My apologies!
I was looking at the 2 months lod master on sparc all this time.
The bug was in IFUNC selector written in assembly that did not work correctly
when built as 'PIC && !SHARED'. That was fixed recently by switching to C-based
IFUNC selection:
https://sourceware.org/git/?p=glibc.git;a=commit;h=88684de7a68b88e8d7e29b2490bdb62994a5e97e
Now memcpy() works, but not elf/sln yet!
I think I understand why memcpy() broke but I'd like a clarification on
-DSHARED vs. -DPIC.
Here is the snippet of (deleted) code that picks an IFUNC:
#if IS_IN (libc)
.text
ENTRY(memcpy)
.type memcpy, @gnu_indirect_function
# ifdef SHARED
SETUP_PIC_REG_LEAF(o3, o5)
# endif
set HWCAP_SPARC_CRYPTO, %o1
andcc %o0, %o1, %g0
be 1f
andcc %o0, HWCAP_SPARC_N2, %g0
As I understand SHARED here ought to be PIC because for -static case -DSHARED
is not used for startup files. SHARED should mean "for DSO". Is that correct?
Normally it would not be too much of an issue (at worst TEXTREL) but
sparc is very sensitive to -fPIC option even in assembler more:
for a single source line like
sethi %hi(_GLOBAL_OFFSET_TABLE_-8), %l7
Such instruction will generate either
R_SPARC_PC22 (-fno-PIC)
or
R_SPARC_HI22 (-fPIC)
relocation. Those need different rules to compute.
Thus additional care is needed to distinct -fPIC/-fno-PIC.
The change below makes 'elf/sln' binary finish successfully on
qemu-sparc32plus:
diff --git a/sysdeps/sparc/sparc32/start.S b/sysdeps/sparc/sparc32/start.S
index a06568d0e9..b882d1e61f 100644
--- a/sysdeps/sparc/sparc32/start.S
+++ b/sysdeps/sparc/sparc32/start.S
@@ -42,7 +42,7 @@
.global _start
.type _start,#function
_start:
-#ifdef SHARED
+#ifdef PIC
SETUP_PIC_REG(l7)
#endif
@@ -57,7 +57,7 @@ _start:
add %sp, 23*4, %o2
/* Load the addresses of the user entry points. */
-#ifndef SHARED
+#ifndef PIC
sethi %hi(main), %o0
sethi %hi(__libc_csu_init), %o3
sethi %hi(__libc_csu_fini), %o4
Does it make sense?
--
You are receiving this mail because:
You are on the CC list for the bug.