(root)/
glibc-2.38/
sysdeps/
x86_64/
x32/
dl-machine.h
       1  /* Machine-dependent ELF dynamic relocation inline functions.  x32 version.
       2     Copyright (C) 2012-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  /* Must allow <sysdeps/x86_64/dl-machine.h> to be included more than once.
      20     See #ifdef RESOLVE_MAP in sysdeps/x86_64/dl-machine.h.  */
      21  #include <sysdeps/x86_64/dl-machine.h>
      22  
      23  #ifndef _X32_DL_MACHINE_H
      24  #define _X32_DL_MACHINE_H
      25  
      26  #undef ARCH_LA_PLTENTER
      27  #undef ARCH_LA_PLTEXIT
      28  #undef RTLD_START
      29  
      30  /* Names of the architecture-specific auditing callback functions.  */
      31  #define ARCH_LA_PLTENTER x32_gnu_pltenter
      32  #define ARCH_LA_PLTEXIT x32_gnu_pltexit
      33  
      34  /* Initial entry point code for the dynamic linker.
      35     The C function `_dl_start' is the real entry point;
      36     its return value is the user program's entry point.  */
      37  #define RTLD_START asm ("\n\
      38  .text\n\
      39  	.p2align 4\n\
      40  .globl _start\n\
      41  .globl _dl_start_user\n\
      42  _start:\n\
      43  	movl %esp, %edi\n\
      44  	call _dl_start\n\
      45  _dl_start_user:\n\
      46  	# Save the user entry point address in %r12.\n\
      47  	movl %eax, %r12d\n\
      48  	# Read the original argument count.\n\
      49  	movl (%rsp), %edx\n\
      50  	# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)\n\
      51  	# argc -> rsi\n\
      52  	movl %edx, %esi\n\
      53  	# Save %rsp value in %r13.\n\
      54  	movl %esp, %r13d\n\
      55  	# And align stack for the _dl_init call.\n\
      56  	and $-16, %esp\n\
      57  	# _dl_loaded -> rdi\n\
      58  	movl _rtld_local(%rip), %edi\n\
      59  	# env -> rcx\n\
      60  	lea 8(%r13,%rdx,4), %ecx\n\
      61  	# argv -> rdx\n\
      62  	lea 4(%r13), %edx\n\
      63  	# Clear %rbp to mark outermost frame obviously even for constructors.\n\
      64  	xorl %ebp, %ebp\n\
      65  	# Call the function to run the initializers.\n\
      66  	call _dl_init\n\
      67  	# Pass our finalizer function to the user in %rdx, as per ELF ABI.\n\
      68  	lea _dl_fini(%rip), %edx\n\
      69  	# And make sure %rsp points to argc stored on the stack.\n\
      70  	movl %r13d, %esp\n\
      71  	# Jump to the user's entry point.\n\
      72  	jmp *%r12\n\
      73  .previous\n\
      74  ");
      75  
      76  #endif /* !_X32_DL_MACHINE_H */