Added PIC support to libc -- when compiled as PIC library make
authorPaul Richards <paul@isl.cf.ac.uk>
Thu, 4 Nov 1993 00:01:47 +0000 (00:01 +0000)
committerPaul Richards <paul@isl.cf.ac.uk>
Thu, 4 Nov 1993 00:01:47 +0000 (00:01 +0000)
references to global symbols go via GOT.

lib/libc/i386/SYS.h
lib/libc/i386/gen/fixunsdfsi.s
lib/libc/i386/gen/setjmp.s
lib/libc/i386/gen/sigsetjmp.s
lib/libc/i386/sys/Ovfork.s
lib/libc/i386/sys/brk.s
lib/libc/i386/sys/cerror.s
lib/libc/i386/sys/ptrace.s
lib/libc/i386/sys/sbrk.s
lib/libc/i386/sys/setlogin.s

index b7d8ce4..400bf52 100644 (file)
  *
  *     from: @(#)SYS.h 5.5 (Berkeley) 5/7/91
  *
  *
  *     from: @(#)SYS.h 5.5 (Berkeley) 5/7/91
  *
- *     $Id$
+ *     $Id: SYS.h,v 1.2 1993/10/09 08:30:48 davidg Exp $
  */
 
 #include <syscall.h>
  */
 
 #include <syscall.h>
+#include "DEFS.h"
 
 
-#ifdef PROF
-#define        ENTRY(x)        .globl _/**/x; \
-                       .data; 1:; .long 0; .text; .align 2,0x90; _/**/x: \
-                       movl $1b,%eax; call mcount
+#ifdef PIC
+#define PIC_PROLOGUE    \
+        pushl   %ebx;   \
+        call    1f;     \
+1:                      \
+        popl    %ebx;   \
+        addl    $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
+#define PIC_EPILOGUE    \
+        popl    %ebx
+#define PIC_PLT(x)      x@PLT
+#define PIC_GOT(x)      x@GOT(%ebx)
+#define PIC_GOTOFF(x)   x@GOTOFF(%ebx)
 #else
 #else
-#define        ENTRY(x)        .globl _/**/x; .text; .align 2,0x90; _/**/x: 
-#endif PROF
+#define PIC_PROLOGUE
+#define PIC_EPILOGUE
+#define PIC_PLT(x)      x
+#define PIC_GOT(x)      x
+#define PIC_GOTOFF(x)   x
+#endif
+
 #define        SYSCALL(x)      2: jmp cerror; ENTRY(x); lea SYS_/**/x,%eax; LCALL(7,0); jb 2b
 #define        RSYSCALL(x)     SYSCALL(x); ret
 #define        PSEUDO(x,y)     ENTRY(x); lea SYS_/**/y, %eax; ; LCALL(7,0); ret
 #define        SYSCALL(x)      2: jmp cerror; ENTRY(x); lea SYS_/**/x,%eax; LCALL(7,0); jb 2b
 #define        RSYSCALL(x)     SYSCALL(x); ret
 #define        PSEUDO(x,y)     ENTRY(x); lea SYS_/**/y, %eax; ; LCALL(7,0); ret
index 9f31df3..1e24d95 100644 (file)
@@ -1,50 +1,82 @@
-       .file   "__fixdfsi.s"
-.text
-       .align 2
-.globl ___fixunsdfsi
-___fixunsdfsi:
-       pushl   %ebp
-       movl    %esp,%ebp
-       subl    $12,%esp
-       fstcw   -4(%ebp)  
-       movw    -4(%ebp),%ax
-       orw     $0x0c00,%ax  
-       movw    %ax,-2(%ebp) 
-       fldcw   -2(%ebp)     
-       fldl    8(%ebp)
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     from: @(#)fixunsdfsi.s  5.1     12/17/90
+ *     $Id: fixunsdfsi.s,v 1.4 1993/10/21 02:03:39 jtc Exp $
+ */
 
 
-       fcoml   fbiggestsigned  /* bigger than biggest signed? */
-       fstsw   %ax
-       sahf
-       jnb     1f
-       
-       fistpl  -12(%ebp)    
-       movl    -12(%ebp),%eax
-       jmp     2f
+#if defined(LIBC_SCCS)
+       .text
+       .asciz "$Id: fixunsdfsi.s,v 1.4 1993/10/21 02:03:39 jtc Exp $"
+#endif
 
 
-1:     fsubl   fbiggestsigned  /* reduce for proper conversion */
-       fistpl  -12(%ebp)               /* convert */
-       movl    -12(%ebp),%eax
-       orl     $0x80000000,%eax        /* restore bias */
+#include "DEFS.h"
+#include "SYS.h"
 
 
-2:     fldcw   -4(%ebp)     
-       leave
-       ret
-
-       fcoml   fbiggestsigned  /* bigger than biggest signed? */
+ENTRY(__fixunsdfsi)
+       fldl    4(%esp)         /* argument double to accum stack */
+       frndint                 /* create integer */
+#ifdef PIC
+       PIC_PROLOGUE
+       leal    PIC_GOTOFF(fbiggestsigned),%eax
+       PIC_EPILOGUE
+       fcoml   (%eax)
+#else
+       fcoml   PIC_GOTOFF(fbiggestsigned)      /* bigger than biggest signed? */
+#endif
        fstsw   %ax
        sahf
        jnb     1f
        fstsw   %ax
        sahf
        jnb     1f
-       
+
        fistpl  4(%esp)
        movl    4(%esp),%eax
        ret
 
        fistpl  4(%esp)
        movl    4(%esp),%eax
        ret
 
-1:     fsubl   fbiggestsigned  /* reduce for proper conversion */
+1:
+#ifdef PIC
+       PIC_PROLOGUE
+       leal    PIC_GOTOFF(fbiggestsigned),%eax
+       PIC_EPILOGUE
+       fsubl   (%eax)
+#else
+       fsubl   PIC_GOTOFF(fbiggestsigned)      /* reduce for proper conversion */
+#endif
        fistpl  4(%esp)         /* convert */
        movl    4(%esp),%eax
        orl     $0x80000000,%eax        /* restore bias */
        fistpl  4(%esp)         /* convert */
        movl    4(%esp),%eax
        orl     $0x80000000,%eax        /* restore bias */
+       PIC_EPILOGUE
        ret
 
        ret
 
-       .data
 fbiggestsigned:        .double 0r2147483648.0
 fbiggestsigned:        .double 0r2147483648.0
index 5482caa..d9fc66e 100644 (file)
  */
 
 #include "DEFS.h"
  */
 
 #include "DEFS.h"
+#include "SYS.h"
 
 ENTRY(setjmp)
        pushl   $0
 
 ENTRY(setjmp)
        pushl   $0
-       call    _sigblock
+       call    PIC_PLT(_sigblock)
        popl    %edx
        movl    4(%esp),%ecx 
        movl    0(%esp),%edx
        popl    %edx
        movl    4(%esp),%ecx 
        movl    0(%esp),%edx
@@ -71,7 +72,7 @@ ENTRY(setjmp)
 ENTRY(longjmp)
        movl    4(%esp),%edx
        pushl   24(%edx)
 ENTRY(longjmp)
        movl    4(%esp),%edx
        pushl   24(%edx)
-       call    _sigsetmask     /* XXX this is not reentrant */
+       call    PIC_PLT(_sigsetmask)    /* XXX this is not reentrant */
        popl    %eax
        movl    4(%esp),%edx
        movl    8(%esp),%eax
        popl    %eax
        movl    4(%esp),%edx
        movl    8(%esp),%eax
index 2f54cd1..399a339 100644 (file)
  *
  *
  *     from: @(#)setjmp.s      5.1 (Berkeley) 4/23/90"
  *
  *
  *     from: @(#)setjmp.s      5.1 (Berkeley) 4/23/90"
- *     $Id: sigsetjmp.s,v 1.1 1993/10/19 18:51:21 jtc Exp $
+ *     $Id: sigsetjmp.s,v 1.2 1993/10/20 17:37:41 jtc Exp $
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
        .text
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
        .text
-       .asciz "$Id: sigsetjmp.s,v 1.1 1993/10/19 18:51:21 jtc Exp $"
+       .asciz "$Id: sigsetjmp.s,v 1.2 1993/10/20 17:37:41 jtc Exp $"
 #endif /* LIBC_SCCS and not lint */
 
 #include "DEFS.h"
 #endif /* LIBC_SCCS and not lint */
 
 #include "DEFS.h"
+#include "SYS.h"
 
 ENTRY(sigsetjmp)
        movl    8(%esp),%eax
 
 ENTRY(sigsetjmp)
        movl    8(%esp),%eax
@@ -52,7 +53,7 @@ ENTRY(sigsetjmp)
        testl   %eax,%eax
        jz      1f
        pushl   $0
        testl   %eax,%eax
        jz      1f
        pushl   $0
-       call    _sigblock
+       call    PIC_PLT(_sigblock)
        addl    $4,%esp
        movl    4(%esp),%ecx 
        movl    %eax,28(%ecx)
        addl    $4,%esp
        movl    4(%esp),%ecx 
        movl    %eax,28(%ecx)
@@ -71,7 +72,7 @@ ENTRY(siglongjmp)
        cmpl    $0,24(%edx)
        jz      1f
        pushl   28(%edx)
        cmpl    $0,24(%edx)
        jz      1f
        pushl   28(%edx)
-       call    _sigsetmask
+       call    PIC_PLT(_sigsetmask)
        addl    $4,%esp
 1:     movl    4(%esp),%edx
        movl    8(%esp),%eax
        addl    $4,%esp
 1:     movl    4(%esp),%edx
        movl    8(%esp),%eax
index bb44ee8..f21e93b 100644 (file)
@@ -61,7 +61,14 @@ vforkok:
        jmp     parent 
 .globl _errno
 verror:
        jmp     parent 
 .globl _errno
 verror:
-       movl    %eax,_errno
+#ifdef PIC
+       PIC_PROLOGUE
+       movl    PIC_GOT(_errno), %edx
+       movl    %eax,(%edx)
+       PIC_EPILOGUE
+#else
+       movl    %eax,_errno
+#endif
        movl    $-1,%eax
        jmp     %ecx
 child:
        movl    $-1,%eax
        jmp     %ecx
 child:
index ce47174..8deba39 100644 (file)
@@ -48,6 +48,29 @@ ENTRY(_brk)
        jmp     ok
 
 ENTRY(brk)
        jmp     ok
 
 ENTRY(brk)
+#ifdef PIC
+        movl    4(%esp),%eax
+        PIC_PROLOGUE
+        movl    %edx,PIC_GOT(curbrk)    # set up GOT addressing
+        movl    %ecx,PIC_GOT(minbrk)    #
+        cmpl    %eax,(%ecx)
+        PIC_EPILOGUE
+        jl      ok
+        movl    (%ecx),%eax
+        movl    %eax,4(%esp)
+ok:
+        lea     SYS_brk,%eax
+        LCALL(7,0)
+        jb      err
+        movl    4(%esp),%eax
+        movl    %eax,(%edx)
+        movl    $0,%eax
+        ret
+err:
+        jmp     PIC_PLT(cerror)
+
+#else
+
        movl    4(%esp),%eax
        cmpl    %eax,minbrk
        jl      ok
        movl    4(%esp),%eax
        cmpl    %eax,minbrk
        jl      ok
@@ -63,3 +86,4 @@ ok:
        ret
 err:
        jmp     cerror
        ret
 err:
        jmp     cerror
+#endif
index 6021fe2..d7f67b6 100644 (file)
 
        .globl  _errno
 cerror:
 
        .globl  _errno
 cerror:
+#ifdef PIC
+       PIC_PROLOGUE
+       movl    PIC_GOT(_errno),%ecx
+       movl    %eax,(%ecx)
+       PIC_EPILOGUE
+#else
        movl    %eax,_errno
        movl    %eax,_errno
+#endif
        movl    $-1,%eax
        ret
        movl    $-1,%eax
        ret
index 703c424..8a6db56 100644 (file)
 
 ENTRY(ptrace)
        xorl    %eax,%eax
 
 ENTRY(ptrace)
        xorl    %eax,%eax
-       movl    %eax,_errno
+#ifdef PIC
+        PIC_PROLOGUE
+        movl    PIC_GOT(_errno),%edx
+        movl    %eax,(%edx)
+        PIC_EPILOGUE
+#else
+        movl    %eax,_errno
+#endif
        lea     SYS_ptrace,%eax
        LCALL(7,0)
        jb      err
        lea     SYS_ptrace,%eax
        LCALL(7,0)
        jb      err
index ccafa29..23c452d 100644 (file)
@@ -52,6 +52,27 @@ curbrk:      .long   _end
        .text
 
 ENTRY(sbrk)
        .text
 
 ENTRY(sbrk)
+#ifdef PIC
+       movl    4(%esp),%ecx
+       PIC_PROLOGUE
+       movl    PIC_GOT(curbrk),%edx
+       movl    (%edx),%eax
+       PIC_EPILOGUE
+       addl    %eax,4(%esp)
+       lea     SYS_brk,%eax
+       LCALL(7,0)
+       jb      err
+       PIC_PROLOGUE
+       movl    PIC_GOT(curbrk),%edx
+       movl    (%edx),%eax
+       addl    %ecx,(%edx)
+       PIC_EPILOGUE
+       ret
+err:
+       jmp     PIC_PLT(cerror)
+
+#else
+
        movl    4(%esp),%ecx
        movl    curbrk,%eax
        addl    %eax,4(%esp)
        movl    4(%esp),%ecx
        movl    curbrk,%eax
        addl    %eax,4(%esp)
@@ -63,3 +84,4 @@ ENTRY(sbrk)
        ret
 err:
        jmp     cerror
        ret
 err:
        jmp     cerror
+#endif
index 227e403..71aca8a 100644 (file)
 .globl __logname_valid         /* in getlogin() */
 
 SYSCALL(setlogin)
 .globl __logname_valid         /* in getlogin() */
 
 SYSCALL(setlogin)
-       movl    $0,__logname_valid
+#ifdef PIC
+       PIC_PROLOGUE
+       pushl   %eax
+       movl    PIC_GOT(__logname_valid),%eax
+       movl    $0,(%eax)
+       popl    %eax
+       PIC_EPILOGUE
+#else
+       movl    $0,__logname_valid
+#endif
        ret                             /* setlogin(name) */
        ret                             /* setlogin(name) */