Browse Source

* support of data > 2 GB on x86_64-linux with PIC by picifing the startup code, resolves #17236
* fixed some small issues in the startup files

git-svn-id: trunk@15907 -

florian 15 years ago
parent
commit
ac51f535ae
5 changed files with 112 additions and 47 deletions
  1. 1 0
      .gitattributes
  2. 42 17
      rtl/linux/x86_64/cprt0.as
  3. 44 20
      rtl/linux/x86_64/gprt0.as
  4. 15 10
      rtl/linux/x86_64/prt0.as
  5. 10 0
      tests/webtbs/tw17236.pp

+ 1 - 0
.gitattributes

@@ -10635,6 +10635,7 @@ tests/webtbs/tw1720.pp svneol=native#text/plain
 tests/webtbs/tw17213.pp svneol=native#text/pascal
 tests/webtbs/tw17220.pp svneol=native#text/plain
 tests/webtbs/tw17220a.pp svneol=native#text/plain
+tests/webtbs/tw17236.pp svneol=native#text/pascal
 tests/webtbs/tw1735.pp svneol=native#text/plain
 tests/webtbs/tw1737.pp svneol=native#text/plain
 tests/webtbs/tw1744.pp svneol=native#text/plain

+ 42 - 17
rtl/linux/x86_64/cprt0.as

@@ -44,11 +44,14 @@ _start:
 	popq %rsi		/* Pop the argument count.  */
 	movq %rsp, %rdx		/* argv starts just at the current stack top.  */
 
-        movq     %rsi,operatingsystem_parameter_argc
-	movq     %rsp,operatingsystem_parameter_argv   /* argv starts just at the current stack top.  */
-        leaq     8(,%rsi,8),%rax
-        addq     %rsp,%rax
-        movq     %rax,operatingsystem_parameter_envp
+        movq    operatingsystem_parameter_argc@GOTPCREL(%rip),%rax
+        movq    %rsi,(%rax)
+        movq    operatingsystem_parameter_argv@GOTPCREL(%rip),%rax
+        movq    %rsp,(%rax)   /* argv starts just at the current stack top.  */
+        leaq    8(,%rsi,8),%rax
+        addq    %rsp,%rax
+        movq    operatingsystem_parameter_envp@GOTPCREL(%rip),%rsi
+        movq    %rax,(%rsi)
 
 	/* Align the stack to a 16 byte boundary to follow the ABI.  */
 	andq  $~15, %rsp
@@ -60,18 +63,20 @@ _start:
 	pushq %rsp
 
 	/* Pass address of our own entry points to .fini and .init.  */
-	movq $_init_dummy, %r8
-	movq $_fini_dummy, %rcx
+	movq _init_dummy@GOTPCREL(%rip), %rcx
+	movq _fini_dummy@GOTPCREL(%rip), %r8
 
-	movq $main_stub, %rdi
+	movq main_stub@GOTPCREL(%rip), %rdi
 
 	/* Call the user's main function, and exit with its value.
 	   But let the libc call main.	  */
-	call __libc_start_main
+	call __libc_start_main@PLT
 
 	hlt			/* Crash if somehow `exit' does return.	 */
 
 /* fake main routine which will be run from libc */
+	.globl main_stub
+        .type main_stub,@function
 main_stub:
         /* save return address */
         popq    %rax
@@ -79,29 +84,49 @@ main_stub:
 	// stack alignment
 	pushq	%rax
 
-        movq    %rax,___fpc_ret
-        movq    %rbp,___fpc_ret_rbp
+	movq    ___fpc_ret_rbp@GOTPCREL(%rip),%rcx
+        movq    %rbp,(%rcx)
+	movq    ___fpc_ret@GOTPCREL(%rip),%rcx
+        movq    %rax,(%rcx)
         pushq   %rax
 
         /* Save initial stackpointer */
-        movq    %rsp,__stkptr
+        movq    __stkptr@GOTPCREL(%rip),%rax
+        movq    %rsp,(%rax)
 
         /* start the program */
         xorq    %rbp,%rbp
-        call    PASCALMAIN
+        call    PASCALMAIN@PLT
         hlt
+	.size   main_stub,.-main_stub
+
 
         .globl _haltproc
         .type _haltproc,@function
 _haltproc:
-        movzwq    operatingsystem_result,%rax /* load and save exitcode */
-
-        movq    ___fpc_ret,%rdx         /* return to libc */
-        movq    ___fpc_ret_rbp,%rbp
+        movq    operatingsystem_result@GOTPCREL(%rip),%rax
+        movzwl  (%rax),%eax
+
+        /* return to libc */
+	movq    ___fpc_ret_rbp@GOTPCREL(%rip),%rcx
+        movq    (%rcx),%rbp
+	movq    ___fpc_ret@GOTPCREL(%rip),%rcx
+        movq    (%rcx),%rdx
         pushq    %rdx
+	ret
+	.size   _haltproc,.-_haltproc
+
+	.globl _init_dummy
+        .type   _init_dummy, @function
 _init_dummy:
+        ret
+	.size   _init_dummy,.-_init_dummy
+
+	.globl  _fini_dummy
+        .type   _fini_dummy, @function
 _fini_dummy:
         ret
+	.size   _fini_dummy,.-_fini_dummy
 
 /* Define a symbol for the first piece of initialized data.  */
 	.data

+ 44 - 20
rtl/linux/x86_64/gprt0.as

@@ -44,11 +44,14 @@ _start:
 	popq %rsi		/* Pop the argument count.  */
 	movq %rsp, %rdx		/* argv starts just at the current stack top.  */
 
-        movq     %rsi,operatingsystem_parameter_argc
-	movq     %rsp,operatingsystem_parameter_argv   /* argv starts just at the current stack top.  */
+        movq    operatingsystem_parameter_argc@GOTPCREL(%rip),%rax
+        movq    %rsi,(%rax)
+        movq    operatingsystem_parameter_argv@GOTPCREL(%rip),%rax
+        movq    %rsp,(%rax)   /* argv starts just at the current stack top.  */
         leaq     8(,%rsi,8),%rax
         addq     %rsp,%rax
-        movq     %rax,operatingsystem_parameter_envp
+        movq    operatingsystem_parameter_envp@GOTPCREL(%rip),%rsi
+        movq    %rax,(%rsi)
 
 	/* Align the stack to a 16 byte boundary to follow the ABI.  */
 	andq  $~15, %rsp
@@ -60,18 +63,20 @@ _start:
 	pushq %rsp
 
 	/* Pass address of our own entry points to .fini and .init.  */
-	movq $_init_dummy, %r8
-	movq $_fini_dummy, %rcx
+        movq _init_dummy@GOTPCREL(%rip), %r8
+        movq _fini_dummy@GOTPCREL(%rip), %rcx
 
-	movq $main_stub, %rdi
+        movq main_stub@GOTPCREL(%rip), %rdi
 
 	/* Call the user's main function, and exit with its value.
 	   But let the libc call main.	  */
-	call __libc_start_main
+	call __libc_start_main@PLT
 
 	hlt			/* Crash if somehow `exit' does return.	 */
 
 /* fake main routine which will be run from libc */
+        .globl main_stub
+        .type main_stub,@function
 main_stub:
         /* save return address */
         popq    %rax
@@ -79,37 +84,56 @@ main_stub:
 	// stack alignment
         pushq   %rax
 
-        movq    %rax,___fpc_ret
-        movq    %rbp,___fpc_ret_rbp
+        movq    ___fpc_ret_rbp@GOTPCREL(%rip),%rcx
+        movq    %rbp,(%rcx)
+        movq    ___fpc_ret@GOTPCREL(%rip),%rcx
+        movq    %rax,(%rcx)
         pushq   %rax
 
 	/* Initialize gmon */
-        movq    $_etext,%rsi
-        movq    $_start,%rdi
-        call    monstartup
+        movq    _etext@GOTPCREL(%rip),%rsi
+        movq    _start@GOTPCREL(%rip),%rdi
+        call    monstartup@PLT
 
-        movq    $_mcleanup,%rdi
-        call    atexit
+        movq    _mcleanup@GOTPCREL(%rip),%rdi
+        call    atexit@PLT
 
         /* Save initial stackpointer */
-        movq    %rsp,__stkptr
+        movq    __stkptr@GOTPCREL(%rip),%rax
+        movq    %rsp,(%rax)
 
         /* start the program */
         xorq    %rbp,%rbp
-        call    PASCALMAIN
+        call    PASCALMAIN@PLT
         hlt
+        .size   main_stub,.-main_stub
 
         .globl _haltproc
         .type _haltproc,@function
 _haltproc:
-        movzwq    operatingsystem_result,%rax /* load and save exitcode */
-
-        movq    ___fpc_ret,%rdx         /* return to libc */
-        movq    ___fpc_ret_rbp,%rbp
+        movq    operatingsystem_result@GOTPCREL(%rip),%rax
+        movzwl  (%rax),%eax
+
+       /* return to libc */
+        movq    ___fpc_ret_rbp@GOTPCREL(%rip),%rcx
+        movq    (%rcx),%rbp
+        movq    ___fpc_ret@GOTPCREL(%rip),%rcx
+        movq    (%rcx),%rdx
         pushq    %rdx
+        ret
+        .size   _haltproc,.-_haltproc
+
+        .globl _init_dummy
+        .type   _init_dummy, @function
 _init_dummy:
+        ret
+        .size   _init_dummy,.-_init_dummy
+
+        .globl  _fini_dummy
+        .type   _fini_dummy, @function
 _fini_dummy:
         ret
+        .size   _fini_dummy,.-_fini_dummy
 
 /* Define a symbol for the first piece of initialized data.  */
 	.data

+ 15 - 10
rtl/linux/x86_64/prt0.as

@@ -38,18 +38,22 @@
 	.globl _start
 	.type _start,@function
 _start:
-#       movq %rdx,%r9                 /* Address of the shared library termination
+#       movq    %rdx,%r9                 /* Address of the shared library termination
 #               	                 function.  */
-	popq     %rsi		      /* Pop the argument count.  */
-        movq     %rsi,operatingsystem_parameter_argc
-	movq     %rsp,operatingsystem_parameter_argv   /* argv starts just at the current stack top.  */
-        leaq     8(,%rsi,8),%rax
-        addq     %rsp,%rax
-        movq     %rax,operatingsystem_parameter_envp
-        andq     $~15,%rsp            /* Align the stack to a 16 byte boundary to follow the ABI.  */
+	popq    %rsi		      /* Pop the argument count.  */
+        movq 	operatingsystem_parameter_argc@GOTPCREL(%rip),%rax
+        movq    %rsi,(%rax)
+        movq 	operatingsystem_parameter_argv@GOTPCREL(%rip),%rax
+	movq    %rsp,(%rax)   /* argv starts just at the current stack top.  */
+        leaq    8(,%rsi,8),%rax
+        addq    %rsp,%rax
+        movq 	operatingsystem_parameter_envp@GOTPCREL(%rip),%rcx
+        movq    %rax,(%rcx)
+        andq    $~15,%rsp            /* Align the stack to a 16 byte boundary to follow the ABI.  */
 
         /* Save initial stackpointer */
-        movq    %rsp,__stkptr
+        movq 	__stkptr@GOTPCREL(%rip),%rax
+        movq    %rsp,(%rax)
 
         xorq    %rbp, %rbp
         call    PASCALMAIN
@@ -58,8 +62,9 @@ _start:
         .globl  _haltproc
         .type   _haltproc,@function
 _haltproc:
+        movq 	operatingsystem_result@GOTPCREL(%rip),%rax
+        movzwl  (%rax),%edi
         movl    $231,%eax                 /* exit_group call */
-        movzwl    operatingsystem_result,%edi
         syscall
         jmp     _haltproc
 

+ 10 - 0
tests/webtbs/tw17236.pp

@@ -0,0 +1,10 @@
+{ %target=linux,darwin,freebsd,netbsd,openbsd,sunos,beos,haiku }
+{ %cpu=x86_64,powerpc64,mips64,sparc64,ia64,alpha }
+
+{ windows does not support statics > 2GB }
+var
+  i : longint;
+  a : array[0..1500000000] of longint;
+begin
+  writeln(a[i]);
+end.