Rewrite the hppa assembly code to avoid reads from .text, by using the
authorkettenis <kettenis@openbsd.org>
Mon, 9 Jan 2023 13:52:42 +0000 (13:52 +0000)
committerkettenis <kettenis@openbsd.org>
Mon, 9 Jan 2023 13:52:42 +0000 (13:52 +0000)
standard PIC magic.  This makes the code similar to what we already use
for rcrt0.o.  This makes it ready for execute-only.

Build C code using -fno-jump-tables to make it ready for execute-only.

ok deraadt@, miod@

libexec/ld.so/hppa/Makefile.inc
libexec/ld.so/hppa/ldasm.S

index 9b81691..2797f45 100644 (file)
@@ -1,6 +1,6 @@
-#      $OpenBSD: Makefile.inc,v 1.7 2022/12/05 07:49:07 kettenis Exp $
+#      $OpenBSD: Makefile.inc,v 1.8 2023/01/09 13:52:42 kettenis Exp $
 
-CFLAGS += -fpic
+CFLAGS += -fpic -fno-jump-tables
 AFLAGS += -fpic
 LD_SCRIPT = ${.CURDIR}/${MACHINE_CPU}/ld.script
 
index 4d19f9b..6f52548 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ldasm.S,v 1.25 2023/01/09 13:45:55 kettenis Exp $     */
+/*     $OpenBSD: ldasm.S,v 1.26 2023/01/09 13:52:42 kettenis Exp $     */
 
 /*
  * Copyright (c) 2004 Michael Shalayeff
 #include <machine/vmparam.h>
 #undef _LOCORE
 
+       .import $global$, data
+
 ENTRY(_dl_start,32)
        copy    r3, r1
        copy    sp, r3
        stwm    r1, HPPA_FRAME_SIZE+16*4(sp)
 
-       stw     %arg0, HPPA_FRAME_ARG(0)(r3)    /* ps_strings */
-
-#define        ADDR(s,r) \
-       bl      4, t1                                                   !\
-       depi    0, 31, 2, t1    /* kill pl bits */                      !\
-       b       s               /* cold brunch -- never done */         !\
-       ldw     0(t1), t2       /* cat(w,w1,w2{10},w2{0..9}) << 2 */    !\
-       extru   t2, 28, 10, t3  /* w2{0..9} */                          !\
-       extru   t2, 26, 16, r   /* w1 */                                !\
-       dep     t3, 31, 11, r                                           !\
-       extru,= t2, 31, 1, r0   /* w */                                 !\
-       depi    1, 15, 1, r                                             !\
-       extru,= t2, 29, 1, r0   /* w2{10} */                            !\
-       depi    1, 21, 1, r                                             !\
-       sh2add  r, t1, r        /* plus the base */                     !\
-       addi    8, r, r         /* bl target is -8 */
-
-       ADDR(_GLOBAL_OFFSET_TABLE_, r19)
-       ADDR(_DYNAMIC, arg2)
+       stw     arg0, HPPA_FRAME_ARG(0)(r3)     /* ps_strings */
+
+       bl      1f, r19
+       depi    0, 31, 2, r19
+1:     addil   L'$global$ - ($PIC_pcrel$0 - 8), r19
+       ldo     R'$global$ - ($PIC_pcrel$0 - 12)(r1), r19
+       bl      1f, arg2
+       depi    0, 31, 2, arg2
+1:     addil   L'_DYNAMIC - ($PIC_pcrel$0 - 8), arg2
+       ldo     R'_DYNAMIC - ($PIC_pcrel$0 - 12)(r1), arg2
        stw     arg2, HPPA_FRAME_ARG(1)(r3)
 
        /* make sure to get a fault until it's set proper */
-       ldi     -1, %dp
+       ldi     -1, dp
 
        ldw     0(arg0), arg0
        ldo     4(r3), arg1                     /* dl_data */
@@ -79,7 +72,8 @@ ENTRY(_dl_start,32)
        ldo     4(r3), arg3                     /* dl_data */
 
        ldw     HPPA_FRAME_ARG(0)(r3), arg0     /* ps_strings */
-       ADDR(_hppa_dl_dtors_plabel, arg1)
+       addil   LT'_dl_dtors_plabel, r19
+       ldw     RT'_dl_dtors_plabel(r1), arg1
        ldw     0(arg1), arg1                   /* cleanup */
 
        ldo     HPPA_FRAME_SIZE(r3), sp
@@ -88,19 +82,10 @@ ENTRY(_dl_start,32)
        ldwm    -HPPA_FRAME_SIZE(sp), r3
 EXIT(_dl_start)
 
-/*
- * void _hppa_dl_dtors(void);
- */
-ENTRY(_hppa_dl_dtors,0)
-       ADDR(_GLOBAL_OFFSET_TABLE_, r19)
-       b       _dl_dtors
-       nop
-EXIT(_hppa_dl_dtors)
-
        .section .data
        .align 4
-_hppa_dl_dtors_plabel:
-       .word P%_hppa_dl_dtors
+_dl_dtors_plabel:
+       .word P%_dl_dtors
        .previous
 
 LEAF_ENTRY(_hppa_dl_set_dp)