Fix sparc assembly when compiled as PIC
authorJames Clarke <jrtc27@jrtc27.com>
Wed, 18 Jul 2018 21:30:42 +0000 (22:30 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 6 Jan 2019 19:33:01 +0000 (19:33 +0000)
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.

Gbp-Pq: Name sparc-pie.patch

usr/include/arch/sparc/machine/asm.h
usr/include/arch/sparc64/machine/asm.h [new file with mode: 0644]
usr/include/arch/sparc64/machine/frame.h [new file with mode: 0644]
usr/klibc/arch/sparc/pipe.S
usr/klibc/arch/sparc/syscall.S
usr/klibc/arch/sparc/sysfork.S
usr/klibc/arch/sparc64/pipe.S
usr/klibc/arch/sparc64/syscall.S
usr/klibc/arch/sparc64/sysfork.S

index 04fe9b1b14e8ccd84b4d3191d13bbdea6296659c..fd9ef1ef7a88cfca573689cd24e54f8197316dfb 100644 (file)
@@ -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,
 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
 
 /*
 #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 (file)
index 0000000..394ba86
--- /dev/null
@@ -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 (file)
index 0000000..79beea6
--- /dev/null
@@ -0,0 +1 @@
+#include "../../sparc/machine/frame.h"
index a8abf3c30c22314452007c7c591af243d2ad5d06..e278bda556dd982f08174a679bdcf600c74d0517 100644 (file)
@@ -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
index c0273f77ca11efc94a3e592f103ac3e24c25d4ae..52a8583bb6060a37ea768c110dbc7a633e689e5b 100644 (file)
@@ -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:
index a66c76e9db937a74e4c1f83f7d01b5a2568401e5..3787b9444b732c5bad2107cc5f0a7234dd783ee8 100644 (file)
@@ -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:
index c63b20f7a4ac9b56b4af93a7ac01b8468977afb2..cb5c2c79dc274f483b2936c9418bff317bbe25bb 100644 (file)
@@ -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
index 7ab9d95f110a974dc692854af9f1e45be24e6530..c84c9ae5f1b1ebe66910dbf75735903af0915c74 100644 (file)
@@ -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
index 2eed659e057f4e9425f0ed341d0dcbc89764dd9a..a0c1334092cda3ee5e3909d63824e23257e95caa 100644 (file)
@@ -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