master
  1/* Assembler macros for i386.
  2   Copyright (C) 1991-2025 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#include <sysdeps/x86/sysdep.h>
 20
 21#define CET_ENABLED     0
 22
 23/* It is desirable that the names of PIC thunks match those used by
 24   GCC so that multiple copies are eliminated by the linker.  Because
 25   GCC 4.6 and earlier use __i686 in the names, it is necessary to
 26   override that predefined macro.  */
 27#if defined __i686 && defined __ASSEMBLER__
 28#undef __i686
 29#define __i686 __i686
 30#endif
 31
 32#ifdef	__ASSEMBLER__
 33# define GET_PC_THUNK(reg) __x86.get_pc_thunk.reg
 34#else
 35# define GET_PC_THUNK_STR(reg) "__x86.get_pc_thunk." #reg
 36#endif
 37
 38#ifdef	__ASSEMBLER__
 39
 40/* Syntactic details of assembler.  */
 41
 42/* Define an entry point visible from C.  */
 43#define	ENTRY_P2ALIGN(name, alignment)					      \
 44  .globl C_SYMBOL_NAME(name);						      \
 45  .type C_SYMBOL_NAME(name),@function;					      \
 46  .align ALIGNARG(alignment);						      \
 47  C_LABEL(name)								      \
 48  cfi_startproc;							      \
 49  CALL_MCOUNT
 50
 51/* If compiled for profiling, call `mcount' at the start of each function.  */
 52#ifdef	PROF
 53/* The mcount code relies on a normal frame pointer being on the stack
 54   to locate our caller, so push one just for its benefit.  */
 55#define CALL_MCOUNT \
 56  pushl %ebp; cfi_adjust_cfa_offset (4); movl %esp, %ebp; \
 57  cfi_def_cfa_register (ebp); call JUMPTARGET(mcount); \
 58  popl %ebp; cfi_def_cfa (esp, 4);
 59#else
 60#define CALL_MCOUNT		/* Do nothing.  */
 61#endif
 62
 63#define	PSEUDO(name, syscall_name, args)				      \
 64  .globl syscall_error;							      \
 65lose: SYSCALL_PIC_SETUP							      \
 66  jmp JUMPTARGET(syscall_error);					      \
 67  ENTRY (name)								      \
 68  DO_CALL (syscall_name, args);						      \
 69  jb lose
 70
 71# define SETUP_PIC_REG(reg) \
 72  .ifndef GET_PC_THUNK(reg);						      \
 73  .section .text.GET_PC_THUNK(reg),"axG",@progbits,GET_PC_THUNK(reg),comdat;  \
 74  .globl GET_PC_THUNK(reg);						      \
 75  .hidden GET_PC_THUNK(reg);						      \
 76  .p2align 4;								      \
 77  .type GET_PC_THUNK(reg),@function;					      \
 78GET_PC_THUNK(reg):							      \
 79  movl (%esp), %e##reg;							      \
 80  ret;									      \
 81  .size GET_PC_THUNK(reg), . - GET_PC_THUNK(reg);			      \
 82  .previous;								      \
 83  .endif;								      \
 84  call GET_PC_THUNK(reg)
 85
 86# define LOAD_PIC_REG(reg) \
 87  SETUP_PIC_REG(reg); addl $_GLOBAL_OFFSET_TABLE_, %e##reg
 88
 89#undef JUMPTARGET
 90#ifdef PIC
 91#define JUMPTARGET(name)	name##@PLT
 92#define SYSCALL_PIC_SETUP \
 93    pushl %ebx;								      \
 94    cfi_adjust_cfa_offset (4);						      \
 95    call 0f;								      \
 960:  popl %ebx;								      \
 97    cfi_adjust_cfa_offset (-4);						      \
 98    addl $_GLOBAL_OFFSET_TABLE_+[.-0b], %ebx;
 99
100#else
101#define JUMPTARGET(name)	name
102#define SYSCALL_PIC_SETUP	/* Nothing.  */
103#endif
104
105#else /* __ASSEMBLER__ */
106
107# define SETUP_PIC_REG_STR(reg)						\
108  ".ifndef " GET_PC_THUNK_STR (reg) "\n"				\
109  ".section .text." GET_PC_THUNK_STR (reg) ",\"axG\",@progbits,"	\
110    GET_PC_THUNK_STR (reg) ",comdat\n"					\
111  ".globl " GET_PC_THUNK_STR (reg) "\n"					\
112  ".hidden " GET_PC_THUNK_STR (reg) "\n"				\
113  ".p2align 4\n"							\
114  ".type " GET_PC_THUNK_STR (reg) ",@function\n"			\
115GET_PC_THUNK_STR (reg) ":"						\
116  "movl (%%esp), %%e" #reg "\n"						\
117  "ret\n"								\
118  ".size " GET_PC_THUNK_STR (reg) ", . - " GET_PC_THUNK_STR (reg) "\n"	\
119  ".previous\n"								\
120  ".endif\n"								\
121  "call " GET_PC_THUNK_STR (reg)
122
123# define LOAD_PIC_REG_STR(reg) \
124  SETUP_PIC_REG_STR (reg) "\naddl $_GLOBAL_OFFSET_TABLE_, %%e" #reg
125
126#endif	/* __ASSEMBLER__ */