aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Clarke <jrtc27@jrtc27.com>2018-07-18 22:30:42 +0100
committerBen Hutchings <ben@decadent.org.uk>2019-01-18 03:10:14 +0000
commitbbef210c8d82202da8cabdd7a329d8e95db2edcc (patch)
tree5e3c5df966cab571ee8565f7ccf9cf3a37788723
parentf46648e5315f2f8aff74bcd723edc24ea4c6d29e (diff)
downloadklibc-bbef210c8d82202da8cabdd7a329d8e95db2edcc.tar.gz
[klibc] Fix sparc assembly when compiled as PIC
Some distributions default to PIE for their compilers, which on sparc is passed on to the assembler. Since the behaviour of %hi/%lo changes under PIC to become GOT offsets, the current assembly files need adapting to not try to use a GOT offset as an absolute address. References: https://bugs.debian.org/885852 Link: https://www.zytor.com/pipermail/klibc/2018-July/004001.html Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--usr/include/arch/sparc/machine/asm.h15
-rw-r--r--usr/include/arch/sparc64/machine/asm.h1
-rw-r--r--usr/include/arch/sparc64/machine/frame.h1
-rw-r--r--usr/klibc/arch/sparc/pipe.S5
-rw-r--r--usr/klibc/arch/sparc/syscall.S6
-rw-r--r--usr/klibc/arch/sparc/sysfork.S6
-rw-r--r--usr/klibc/arch/sparc64/pipe.S5
-rw-r--r--usr/klibc/arch/sparc64/syscall.S6
-rw-r--r--usr/klibc/arch/sparc64/sysfork.S6
9 files changed, 37 insertions, 14 deletions
diff --git a/usr/include/arch/sparc/machine/asm.h b/usr/include/arch/sparc/machine/asm.h
index 04fe9b1b14e8c..fd9ef1ef7a88c 100644
--- a/usr/include/arch/sparc/machine/asm.h
+++ b/usr/include/arch/sparc/machine/asm.h
@@ -61,7 +61,7 @@
#endif
#define _ASM_LABEL(name) name
-#ifdef PIC
+#ifdef __PIC__
/*
* PIC_PROLOGUE() is akin to the compiler generated function prologue for
* PIC code. It leaves the address of the Global Offset Table in DEST,
@@ -83,12 +83,20 @@
0: \
add dest,%o7,dest; \
mov tmp, %o7
+#define SET(var,base,dest) \
+ sethi %gdop_hix22(var), dest; \
+ xor dest, %gdop_lox10(var), dest; \
+ ldx [base + dest], dest, %gdop(var)
#else
#define PIC_PROLOGUE(dest,tmp) \
mov %o7,tmp; 3: call 4f; nop; 4: \
sethi %hi(_C_LABEL(_GLOBAL_OFFSET_TABLE_)-(3b-.)),dest; \
or dest,%lo(_C_LABEL(_GLOBAL_OFFSET_TABLE_)-(3b-.)),dest; \
add dest,%o7,dest; mov tmp,%o7
+#define SET(var,base,dest) \
+ sethi %gdop_hix22(var), dest; \
+ xor dest, %gdop_lox10(var), dest; \
+ ld [base + dest], dest, %gdop(var)
#endif
/*
@@ -106,7 +114,10 @@
#endif
#else
#define PIC_PROLOGUE(dest,tmp)
-#define PICCY_OFFSET(var,dest,tmp)
+#define SET(var,base,dest) \
+ sethi %hi(var), dest; \
+ or dest, %lo(var), dest
+#define PICCY_SET(var,dest,tmp) SET(var,tmp,dest)
#endif
#define FTYPE(x) .type x,@function
diff --git a/usr/include/arch/sparc64/machine/asm.h b/usr/include/arch/sparc64/machine/asm.h
new file mode 100644
index 0000000000000..394ba86553cf7
--- /dev/null
+++ b/usr/include/arch/sparc64/machine/asm.h
@@ -0,0 +1 @@
+#include "../../sparc/machine/asm.h"
diff --git a/usr/include/arch/sparc64/machine/frame.h b/usr/include/arch/sparc64/machine/frame.h
new file mode 100644
index 0000000000000..79beea6d2f0f1
--- /dev/null
+++ b/usr/include/arch/sparc64/machine/frame.h
@@ -0,0 +1 @@
+#include "../../sparc/machine/frame.h"
diff --git a/usr/klibc/arch/sparc/pipe.S b/usr/klibc/arch/sparc/pipe.S
index a8abf3c30c223..e278bda556dd9 100644
--- a/usr/klibc/arch/sparc/pipe.S
+++ b/usr/klibc/arch/sparc/pipe.S
@@ -5,6 +5,7 @@
* they return the two file descriptors in %o0 and %o1.
*/
+#include <machine/asm.h>
#include <asm/unistd.h>
.globl pipe
@@ -16,8 +17,8 @@ pipe:
t 0x10
bcc 1f
nop
- sethi %hi(errno), %g4
- or %g4, %lo(errno), %g4
+ PIC_PROLOGUE(%g1,%g4)
+ SET(errno,%g1,%g4)
st %o0,[%g4]
retl
mov -1, %o0
diff --git a/usr/klibc/arch/sparc/syscall.S b/usr/klibc/arch/sparc/syscall.S
index c0273f77ca11e..52a8583bb6060 100644
--- a/usr/klibc/arch/sparc/syscall.S
+++ b/usr/klibc/arch/sparc/syscall.S
@@ -4,14 +4,16 @@
* Common system-call stub; %g1 already set to syscall number
*/
+#include <machine/asm.h>
+
.globl __syscall_common
.type __syscall_common,#function
.align 4
__syscall_common:
t 0x10
bcc 1f
- sethi %hi(errno), %g4
- or %g4, %lo(errno), %g4
+ PIC_PROLOGUE(%g1,%g4)
+ SET(errno,%g1,%g4)
st %o0,[%g4]
mov -1, %o0
1:
diff --git a/usr/klibc/arch/sparc/sysfork.S b/usr/klibc/arch/sparc/sysfork.S
index a66c76e9db937..3787b9444b732 100644
--- a/usr/klibc/arch/sparc/sysfork.S
+++ b/usr/klibc/arch/sparc/sysfork.S
@@ -8,6 +8,8 @@
* Common system-call stub; %g1 already set to syscall number
*/
+#include <machine/asm.h>
+
.globl __syscall_forkish
.type __syscall_forkish,#function
.align 4
@@ -16,8 +18,8 @@ __syscall_forkish:
sub %o1, 1, %o1
bcc,a 1f
and %o0, %o1, %o0
- sethi %hi(errno), %g4
- or %g4, %lo(errno), %g4
+ PIC_PROLOGUE(%g1,%g4)
+ SET(errno,%g1,%g4)
st %o0,[%g4]
mov -1, %o0
1:
diff --git a/usr/klibc/arch/sparc64/pipe.S b/usr/klibc/arch/sparc64/pipe.S
index c63b20f7a4ac9..cb5c2c79dc274 100644
--- a/usr/klibc/arch/sparc64/pipe.S
+++ b/usr/klibc/arch/sparc64/pipe.S
@@ -5,6 +5,7 @@
* they return the two file descriptors in %o0 and %o1.
*/
+#include <machine/asm.h>
#include <asm/unistd.h>
.globl pipe
@@ -16,8 +17,8 @@ pipe:
t 0x6d
bcc %xcc, 1f
nop
- sethi %hi(errno), %g4
- or %g4, %lo(errno), %g4
+ PIC_PROLOGUE(%g1,%g4)
+ SET(errno,%g1,%g4)
st %o0,[%g4]
retl
mov -1, %o0
diff --git a/usr/klibc/arch/sparc64/syscall.S b/usr/klibc/arch/sparc64/syscall.S
index 7ab9d95f110a9..c84c9ae5f1b1e 100644
--- a/usr/klibc/arch/sparc64/syscall.S
+++ b/usr/klibc/arch/sparc64/syscall.S
@@ -4,14 +4,16 @@
* Common system-call stub; %g1 already set to syscall number
*/
+#include <machine/asm.h>
+
.globl __syscall_common
.type __syscall_common,#function
.align 4
__syscall_common:
t 0x6d
bcc %xcc, 1f
- sethi %hi(errno), %g4
- or %g4, %lo(errno), %g4
+ PIC_PROLOGUE(%g1,%g4)
+ SET(errno,%g1,%g4)
st %o0,[%g4]
1:
retl
diff --git a/usr/klibc/arch/sparc64/sysfork.S b/usr/klibc/arch/sparc64/sysfork.S
index 2eed659e057f4..a0c1334092cda 100644
--- a/usr/klibc/arch/sparc64/sysfork.S
+++ b/usr/klibc/arch/sparc64/sysfork.S
@@ -8,6 +8,8 @@
* Common system-call stub; %g1 already set to syscall number
*/
+#include <machine/asm.h>
+
.globl __syscall_forkish
.type __syscall_forkish,#function
.align 4
@@ -16,8 +18,8 @@ __syscall_forkish:
sub %o1, 1, %o1
bcc,a %xcc, 1f
and %o0, %o1, %o0
- sethi %hi(errno), %g4
- or %g4, %lo(errno), %g4
+ PIC_PROLOGUE(%g1,%g4)
+ SET(errno,%g1,%g4)
st %o0, [%g4]
retl
mov -1, %o0