From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29253 invoked by alias); 24 Sep 2003 17:22:40 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 21193 invoked from network); 24 Sep 2003 15:49:18 -0000 Received: from unknown (HELO sunsite.ms.mff.cuni.cz) (195.113.19.66) by sources.redhat.com with SMTP; 24 Sep 2003 15:49:18 -0000 Received: from sunsite.ms.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8) with ESMTP id h8ODl42c016686; Wed, 24 Sep 2003 15:47:04 +0200 Received: (from jakub@localhost) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8/Submit) id h8ODl4lL016680; Wed, 24 Sep 2003 15:47:04 +0200 Date: Wed, 24 Sep 2003 17:22:00 -0000 From: Jakub Jelinek To: Ulrich Drepper , Roland McGrath Cc: Glibc hackers Subject: [PATCH] Set __libc_stack_end earlier on all arches, export back at GLIBC_2.1 Message-ID: <20030924134704.GK12344@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2003-09/txt/msg00083.txt.bz2 Hi! Roland's execstack code needs __libc_stack_end set already during dl_main, not after it. The following patch does that (tested on a bunch of arches). I haven't touched hppa, mips, can maintainers do something about it? Also, for ia64, the __libc_stack_end setting code in RTLD_START should be removed, but removing of that requires rebundling the whole assembly. Any volunteers? 2003-09-24 Jakub Jelinek * elf/Versions (ld): Export __libc_stack_end@GLIBC_2.1 instead of __libc_stack_end@GLIBC_PRIVATE. * sysdeps/generic/dl-sysdep.c (DL_STACK_END): Define if not defined. (_dl_sysdep_start): Set __libc_stack_end here. * sysdeps/alpha/dl-machine.h (RTLD_START): Remove setting of __libc_stack_end. * sysdeps/arm/dl-machine.h (RTLD_START): Likewise. * sysdeps/cris/dl-machine.h (RTLD_START): Likewise. * sysdeps/i386/dl-machine.h (RTLD_START): Likewise. * sysdeps/m68k/dl-machine.h (RTLD_START): Likewise. * sysdeps/s390/s390-32/dl-machine.h (RTLD_START): Likewise. * sysdeps/s390/s390-64/dl-machine.h (RTLD_START): Likewise. * sysdeps/sh/dl-machine.h (RTLD_START): Likewise. * sysdeps/x86_64/dl-machine.h (RTLD_START): Likewise. * sysdeps/ia64/dl-machine.h (DL_STACK_END): Define. * sysdeps/sparc/sparc32/dl-machine.h (DL_STACK_END): Define. (RTLD_START): Remove setting of __libc_stack_end. * sysdeps/sparc/sparc64/dl-machine.h (DL_STACK_END): Define. (RTLD_START): Remove setting of __libc_stack_end. --- libc/elf/Versions.jj 2003-09-23 10:14:05.000000000 -0400 +++ libc/elf/Versions 2003-09-24 05:37:50.000000000 -0400 @@ -36,6 +36,8 @@ ld { GLIBC_2.1 { # functions used in other libraries _dl_mcount; + # historically used by Garbage Collectors + __libc_stack_end; } GLIBC_2.3 { # runtime interface to TLS @@ -43,7 +45,7 @@ ld { } GLIBC_PRIVATE { # Those are in the dynamic linker, but used by libc.so. - __libc_enable_secure; __libc_stack_end; + __libc_enable_secure; _dl_argv; _dl_catch_error; _dl_check_map_versions; _dl_debug_printf; _dl_debug_state; _dl_dst_count; _dl_dst_substitute; _dl_init; _dl_lookup_symbol; _dl_lookup_symbol_skip; --- libc/sysdeps/alpha/dl-machine.h.jj 2003-07-31 04:35:53.000000000 -0400 +++ libc/sysdeps/alpha/dl-machine.h 2003-09-24 04:34:21.000000000 -0400 @@ -319,8 +319,6 @@ _dl_start_user: \n\ .prologue 0 \n\ /* Save the user entry point address in s0. */ \n\ mov $0, $9 \n\ - /* Store the highest stack address. */ \n\ - stq $30, __libc_stack_end \n\ /* See if we were run as a command with the executable \n\ file name as an extra leading argument. */ \n\ ldl $1, _dl_skip_args($gp) !gprel \n\ --- libc/sysdeps/arm/dl-machine.h.jj 2003-09-22 11:35:41.000000000 -0400 +++ libc/sysdeps/arm/dl-machine.h 2003-09-24 04:35:37.000000000 -0400 @@ -265,10 +265,6 @@ _dl_start_user:\n\ ldr sl, .L_GET_GOT\n\ add sl, pc, sl\n\ .L_GOT_GOT:\n\ - @ Store the highest stack address\n\ - ldr r1, .L_STACK_END\n\ - ldr r1, [sl, r1]\n\ - str sp, [r1]\n\ @ See if we were run as a command with the executable file\n\ @ name as an extra leading argument.\n\ ldr r4, .L_SKIP_ARGS\n\ @@ -311,8 +307,6 @@ _dl_start_user:\n\ .word _dl_starting_up(GOT)\n\ .L_FINI_PROC:\n\ .word _dl_fini(GOT)\n\ -.L_STACK_END:\n\ - .word __libc_stack_end(GOT)\n\ .L_LOADED:\n\ .word _rtld_local(GOT)\n\ .previous\n\ --- libc/sysdeps/cris/dl-machine.h.jj 2003-09-17 07:42:32.000000000 -0400 +++ libc/sysdeps/cris/dl-machine.h 2003-09-24 04:36:14.000000000 -0400 @@ -188,9 +188,6 @@ _dl_start_user:\n\ ; Point R0 at the GOT.\n\ move.d $pc,$r0\n\ sub.d .:GOTOFF,$r0\n\ - ; Remember the highest stack address.\n\ - move.d [$r0+__libc_stack_end:GOT16],$r13\n\ - move.d $sp,[$r13]\n\ ; See if we were run as a command with the executable file\n\ ; name as an extra leading argument.\n\ move.d [$r0+_dl_skip_args:GOT16],$r13\n\ --- libc/sysdeps/generic/dl-sysdep.c.jj 2003-07-15 11:14:39.000000000 -0400 +++ libc/sysdeps/generic/dl-sysdep.c 2003-09-24 04:31:10.000000000 -0400 @@ -69,6 +69,9 @@ static ElfW(auxv_t) *_dl_auxv; } while (0) #endif +#ifndef DL_STACK_END +# define DL_STACK_END(cookie) ((void *) (cookie)) +#endif ElfW(Addr) _dl_sysdep_start (void **start_argptr, @@ -98,6 +101,7 @@ _dl_sysdep_start (void **start_argptr, ElfW(Word) new_sysinfo = 0; #endif + __libc_stack_end = DL_STACK_END (start_argptr); DL_FIND_ARG_COMPONENTS (start_argptr, _dl_argc, INTUSE(_dl_argv), _environ, _dl_auxv); --- libc/sysdeps/i386/dl-machine.h.jj 2003-09-23 11:03:03.000000000 -0400 +++ libc/sysdeps/i386/dl-machine.h 2003-09-24 04:38:49.000000000 -0400 @@ -276,17 +276,15 @@ _dl_runtime_profile:\n\ .globl _start\n\ .globl _dl_start_user\n\ _start:\n\ - # Point %ebx at the GOT.\n\ - call 0b\n\ - addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\ # Note that _dl_start gets the parameter in %eax.\n\ movl %esp, %eax\n\ - # Store the highest stack address\n\ - movl %eax, __libc_stack_end@GOTOFF(%ebx)\n\ call _dl_start\n\ _dl_start_user:\n\ # Save the user entry point address in %edi.\n\ movl %eax, %edi\n\ + # Point %ebx at the GOT.\n\ + call 0b\n\ + addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\ # See if we were run as a command with the executable file\n\ # name as an extra leading argument.\n\ movl _dl_skip_args@GOTOFF(%ebx), %eax\n\ --- libc/sysdeps/ia64/dl-machine.h.jj 2003-08-26 17:07:43.000000000 -0400 +++ libc/sysdeps/ia64/dl-machine.h 2003-09-24 04:44:19.000000000 -0400 @@ -267,6 +267,10 @@ elf_machine_runtime_setup (struct link_m strong_alias (_dl_runtime_resolve, _dl_runtime_profile); #endif +/* Undo the adds out0 = 16, sp below to get at the value we want in + __libc_stack_end. */ +#define DL_STACK_END(cookie) \ + ((void *) (((long) (cookie)) - 16)) /* Initial entry point code for the dynamic linker. The C function `_dl_start' is the real entry point; --- libc/sysdeps/m68k/dl-machine.h.jj 2003-07-31 04:35:58.000000000 -0400 +++ libc/sysdeps/m68k/dl-machine.h 2003-09-24 04:54:45.000000000 -0400 @@ -157,9 +157,6 @@ _start:\n\ _dl_start_user:\n\ | Save the user entry point address in %a4.\n\ move.l %d0, %a4\n\ - | Remember the highest stack address.\n\ - move.l __libc_stack_end@GOTPC(%pc), %a0\n\ - move.l %sp, (%a0)\n\ | See if we were run as a command with the executable file\n\ | name as an extra leading argument.\n\ move.l _dl_skip_args(%pc), %d0\n\ --- libc/sysdeps/s390/s390-32/dl-machine.h.jj 2003-08-06 14:36:16.000000000 -0400 +++ libc/sysdeps/s390/s390-32/dl-machine.h 2003-09-24 05:05:21.000000000 -0400 @@ -262,9 +262,6 @@ _dl_start_user:\n\ # Point %r12 at the GOT.\n\ l %r12,.Ladr0-.Llit(%r13)\n\ ar %r12,%r13\n\ - # Store the highest stack address\n\ - l %r1,__libc_stack_end@GOT(%r12)\n\ - st %r15, 0(%r1)\n\ # See if we were run as a command with the executable file\n\ # name as an extra leading argument.\n\ l %r1,_dl_skip_args@GOT12(0,%r12)\n\ --- libc/sysdeps/s390/s390-64/dl-machine.h.jj 2003-08-06 14:36:16.000000000 -0400 +++ libc/sysdeps/s390/s390-64/dl-machine.h 2003-09-24 05:05:55.000000000 -0400 @@ -235,10 +235,6 @@ _dl_start_user:\n\ lgr %r8,%r2\n\ # Point %r12 at the GOT.\n\ larl %r12,_GLOBAL_OFFSET_TABLE_\n\ - # Store the highest stack address\n\ - lghi %r1,__libc_stack_end@GOT\n\ - lg %r1,0(%r1,%r12)\n\ - stg %r15, 0(%r1)\n\ # See if we were run as a command with the executable file\n\ # name as an extra leading argument.\n\ lghi %r1,_dl_skip_args@GOT\n\ --- libc/sysdeps/sh/dl-machine.h.jj 2003-07-31 04:36:01.000000000 -0400 +++ libc/sysdeps/sh/dl-machine.h 2003-09-24 05:07:19.000000000 -0400 @@ -334,11 +334,7 @@ _dl_start_user:\n\ add r0,r12\n\ .align 2\n\ 1: .long _GLOBAL_OFFSET_TABLE_\n\ -2: ! Store the highest stack address\n\ - mov.l .L_stack_end,r0\n\ - mov.l @(r0,r12),r0\n\ - mov.l r15,@r0\n\ - ! See if we were run as a command with the executable file\n\ +2: ! See if we were run as a command with the executable file\n\ ! name as an extra leading argument.\n\ mov.l .L_dl_skip_args,r0\n\ mov.l @(r0,r12),r0\n\ @@ -381,8 +377,6 @@ _dl_start_user:\n\ .align 2\n\ .L_dl_start:\n\ .long _dl_start@PLT\n\ -.L_stack_end:\n\ - .long __libc_stack_end@GOT\n\ .L_dl_skip_args:\n\ .long _dl_skip_args@GOT\n\ .L_dl_init:\n\ --- libc/sysdeps/sparc/sparc32/dl-machine.h.jj 2003-08-26 17:07:46.000000000 -0400 +++ libc/sysdeps/sparc/sparc32/dl-machine.h 2003-09-24 05:11:04.000000000 -0400 @@ -248,6 +248,11 @@ elf_machine_runtime_setup (struct link_m /* The SPARC overlaps DT_RELA and DT_PLTREL. */ #define ELF_MACHINE_PLTREL_OVERLAP 1 +/* Undo the sub %sp, 6*4, %sp; add %sp, 22*4, %o0 below to get at the + value we want in __libc_stack_end. */ +#define DL_STACK_END(cookie) \ + ((void *) (((long) (cookie)) - (22 - 6) * 4)) + /* Initial entry point code for the dynamic linker. The C function `_dl_start' is the real entry point; its return value is the user program's entry point. */ @@ -274,16 +279,10 @@ _dl_start_user:\n\ add %l7, %o7, %l7\n\ /* Save the user entry point address in %l0 */\n\ mov %o0, %l0\n\ - /* Store the highest stack address. */\n\ - sethi %hi(__libc_stack_end), %g2\n\ - or %g2, %lo(__libc_stack_end), %g2\n\ - ld [%l7 + %g2], %l1\n\ - sethi %hi(_dl_skip_args), %g2\n\ - add %sp, 6*4, %l2\n\ - or %g2, %lo(_dl_skip_args), %g2\n\ - st %l2, [%l1]\n\ /* See if we were run as a command with the executable file name as an\n\ extra leading argument. If so, adjust the contents of the stack. */\n\ + sethi %hi(_dl_skip_args), %g2\n\ + or %g2, %lo(_dl_skip_args), %g2\n\ ld [%l7+%g2], %i0\n\ ld [%i0], %i0\n\ tst %i0\n\ --- libc/sysdeps/sparc/sparc64/dl-machine.h.jj 2003-07-31 04:36:02.000000000 -0400 +++ libc/sysdeps/sparc/sparc64/dl-machine.h 2003-09-24 05:14:58.000000000 -0400 @@ -666,6 +666,11 @@ elf_machine_runtime_setup (struct link_m /* The PLT uses Elf64_Rela relocs. */ #define elf_machine_relplt elf_machine_rela +/* Undo the sub %sp, 6*8, %sp; add %sp, STACK_BIAS + 22*8, %o0 below + to get at the value we want in __libc_stack_end. */ +#define DL_STACK_END(cookie) \ + ((void *) (((long) (cookie)) - (22 - 6) * 8 - STACK_BIAS)) + /* Initial entry point code for the dynamic linker. The C function `_dl_start' is the real entry point; its return value is the user program's entry point. */ @@ -694,20 +699,14 @@ elf_machine_runtime_setup (struct link_m "1: call 11f\n" \ " sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n" \ "11: or %l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n" \ -" /* Store the highest stack address. */\n" \ -" sethi %hi(__libc_stack_end), %g5\n" \ +" sethi %hi(_dl_skip_args), %g5\n" \ " add %l7, %o7, %l7\n" \ -" or %g5, %lo(__libc_stack_end), %g5\n" \ +" or %g5, %lo(_dl_skip_args), %g5\n" \ " /* Save the user entry point address in %l0. */\n" \ " mov %o0, %l0\n" \ -" ldx [%l7 + %g5], %l1\n" \ -" sethi %hi(_dl_skip_args), %g5\n" \ -" add %sp, 6*8, %l2\n" \ " /* See if we were run as a command with the executable file name as an\n" \ " extra leading argument. If so, we must shift things around since we\n" \ " must keep the stack doubleword aligned. */\n" \ -" or %g5, %lo(_dl_skip_args), %g5\n" \ -" stx %l2, [%l1]\n" \ " ldx [%l7 + %g5], %i0\n" \ " ld [%i0], %i0\n" \ " brz,pt %i0, 2f\n" \ --- libc/sysdeps/x86_64/dl-machine.h.jj 2003-09-24 04:20:43.000000000 -0400 +++ libc/sysdeps/x86_64/dl-machine.h 2003-09-24 05:16:28.000000000 -0400 @@ -260,8 +260,6 @@ _dl_runtime_profile:\n\ .globl _start\n\ .globl _dl_start_user\n\ _start:\n\ - # Store the highest stack address\n\ - movq %rsp, __libc_stack_end(%rip)\n\ movq %rsp, %rdi\n\ call _dl_start\n\ _dl_start_user:\n\ Jakub