glibc/sysdeps/powerpc/powerpc32/dl-start.S

104 lines
3.4 KiB
ArmAsm
Raw Normal View History

/* Machine-dependent ELF startup code. PowerPC version.
Copyright (C) 1995-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
/* 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. */
ENTRY(_start)
/* We start with the following on the stack, from top:
argc (4 bytes);
arguments for program (terminated by NULL);
environment variables (terminated by NULL);
arguments for the program loader. */
/* Call _dl_start with one parameter pointing at argc */
mr r3,r1
/* (we have to frob the stack pointer a bit to allow room for
_dl_start to save the link register). */
li r4,0
addi r1,r1,-16
stw r4,0(r1)
bl _dl_start@local
/* FALLTHRU */
_dl_start_user:
/* Now, we do our main work of calling initialisation procedures.
The ELF ABI doesn't say anything about parameters for these,
so we just pass argc, argv, and the environment.
Changing these is strongly discouraged (not least because argc is
passed by value!). */
/* Put our GOT pointer in r31, */
SETUP_GOT_ACCESS(r31,got_label)
addis r31,r31,_GLOBAL_OFFSET_TABLE_-got_label@ha
addi r31,r31,_GLOBAL_OFFSET_TABLE_-got_label@l
/* the address of _start in r30, */
mr r30,r3
/* &_dl_argc in 29, &_dl_argv in 27, and _dl_loaded in 28. */
lwz r28,_rtld_local@got(r31)
lwz r29,_dl_argc@got(r31)
Don't use INTDEF/INTUSE with _dl_argv (bug 14132). Continuing the removal of the obsolete INTDEF / INTUSE mechanism, this patch replaces its use for _dl_argv with rtld_hidden_data_def and rtld_hidden_proto. Some places in .S files that previously used _dl_argv_internal or INTUSE(_dl_argv) now use __GI__dl_argv directly (there are plenty of existing examples of such direct use of __GI_*). A single place in rtld.c previously used _dl_argv without INTUSE, apparently accidentally, while the rtld_hidden_proto mechanism avoids such accidential omissions. As a consequence, this patch *does* change the contents of stripped ld.so. However, the installed stripped shared libraries are identical to those you get if instead of this patch you change that single _dl_argv use to use INTUSE, without any other changes. Tested for x86_64 (testsuite as well as comparison of installed stripped shared libraries as described above). [BZ #14132] * sysdeps/generic/ldsodefs.h (_dl_argv): Use rtld_hidden_proto. [IS_IN_rtld] (_dl_argv_internal): Do not declare. (rtld_progname): Make macro definition unconditional. * elf/rtld.c (_dl_argv): Use rtld_hidden_data_def instead of INTDEF. (dlmopen_doit): Do not use INTUSE with _dl_argv. (dl_main): Likewise. * elf/dl-sysdep.c (_dl_sysdep_start): Likewise. * sysdeps/alpha/dl-machine.h (RTLD_START): Use __GI__dl_argv instead of _dl_argv_internal. * sysdeps/powerpc/powerpc32/dl-start.S (_dl_start_user): Use __GI__dl_argv instead of INTUSE(_dl_argv). * sysdeps/powerpc/powerpc64/dl-machine.h (RTLD_START): Use __GI__dl_argv instead of _dl_argv_internal.
2014-11-04 17:39:39 +00:00
lwz r27,__GI__dl_argv@got(r31)
/* Call _dl_init (_dl_loaded, _dl_argc, _dl_argv, _dl_argv+_dl_argc+1). */
lwz r3,0(r28)
lwz r4,0(r29)
lwz r5,0(r27)
slwi r6,r4,2
add r6,r5,r6
addi r6,r6,4
Don't use INTDEF/INTUSE with _dl_init (bug 14132). Continuing the removal of the obsolete INTDEF / INTUSE mechanism, this patch eliminates its use for _dl_init. Since _dl_init was already declared with hidden visibility, creating a second hidden alias for it was completely pointless, so this patch replaces all uses of _dl_init_internal with plain _dl_init instead of using hidden_proto / hidden_def (which are only needed when you want a hidden alias for a non-hidden symbol; it's quite possible there are cases where they are used but don't need to be because the symbol in question is not part of the public ABI and is only used within a single library, so using attributes_hidden instead would suffice). Tested for x86_64 that installed stripped shared libraries are unchanged by the patch. [BZ #14132] * elf/dl-init.c (_dl_init): Don't use INTDEF. * sysdeps/aarch64/dl-machine.h (RTLD_START): Use _dl_init instead of _dl_init_internal. * sysdeps/alpha/dl-machine.h (RTLD_START): Likewise. * sysdeps/arm/dl-machine.h (RTLD_START): Likewise. * sysdeps/hppa/dl-machine.h (RTLD_START): Likewise. * sysdeps/i386/dl-machine.h (RTLD_START): Likewise. * sysdeps/ia64/dl-machine.h (RTLD_START): Likewise. * sysdeps/m68k/dl-machine.h (RTLD_START): Likewise. * sysdeps/microblaze/dl-machine.h (RTLD_START): Likewise. * sysdeps/mips/dl-machine.h (RTLD_START): Likewise. * sysdeps/powerpc/powerpc32/dl-start.S (_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/sparc/sparc32/dl-machine.h (RTLD_START): Likewise. * sysdeps/sparc/sparc64/dl-machine.h (RTLD_START): Likewise. * sysdeps/tile/dl-start.S (_start): Likewise. * sysdeps/x86_64/dl-machine.h (RTLD_START): Likewise. * sysdeps/x86_64/x32/dl-machine.h (RTLD_START): Likewise.
2014-11-04 23:26:39 +00:00
bl _dl_init@local
/* Now, to conform to the ELF ABI, we have to: */
/* Pass argc (actually _dl_argc) in r3; */
lwz r3,0(r29)
/* pass argv (actually _dl_argv) in r4; */
lwz r4,0(r27)
/* pass envp (actually _dl_argv+_dl_argc+1) in r5; */
slwi r5,r3,2
add r6,r4,r5
addi r5,r6,4
/* pass the auxiliary vector in r6. This is passed to us just after _envp. */
2: lwzu r0,4(r6)
cmpwi r0,0
bne 2b
addi r6,r6,4
/* Pass a termination function pointer (in this case _dl_fini) in r7. */
lwz r7,_dl_fini@got(r31)
/* Now, call the start function in r30... */
mtctr r30
/* Pass the stack pointer in r1 (so far so good), pointing to a NULL value.
(This lets our startup code distinguish between a program linked statically,
which linux will call with argc on top of the stack which will hopefully
never be zero, and a dynamically linked program which will always have
a NULL on the top of the stack).
Take the opportunity to clear LR, so anyone who accidentally returns
from _start gets SEGV. Also clear the next few words of the stack. */
_dl_main_dispatch:
li r31,0
stw r31,0(r1)
mtlr r31
stw r31,4(r1)
stw r31,8(r1)
stw r31,12(r1)
/* Go do it! */
bctr
END(_start)