wordexp: Fix the usage of the internal _itoa function
[uclibc-ng.git] / ldso / ldso / fdpic / dl-sysdep.h
blob6ab303b377285ce707cf7ccfe4f08cb3fefd8c88
1 /* Copyright (C) 2003, 2004 Red Hat, Inc.
2 * Contributed by Alexandre Oliva <aoliva@redhat.com>
3 * Copyright (C) 2006-2011 Analog Devices, Inc.
4 * Based on ../i386/dl-sysdep.h
6 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7 */
9 #define HAVE_DL_INLINES_H
12 * Initialization sequence for a GOT. Copy the resolver function
13 * descriptor and the pointer to the elf_resolve/link_map data
14 * structure. Initialize the got_value in the module while at that.
16 #define INIT_GOT(GOT_BASE,MODULE) \
17 { \
18 (MODULE)->loadaddr.got_value = (GOT_BASE); \
19 GOT_BASE[0] = ((unsigned long *)&_dl_linux_resolve)[0]; \
20 GOT_BASE[1] = ((unsigned long *)&_dl_linux_resolve)[1]; \
21 GOT_BASE[2] = (unsigned long) MODULE; \
24 struct elf_resolve;
26 struct funcdesc_value
28 void *entry_point;
29 void *got_value;
30 } __attribute__((__aligned__(8)));
32 struct funcdesc_ht;
34 #define DL_LOADADDR_TYPE struct elf32_fdpic_loadaddr
36 #define DL_RELOC_ADDR(LOADADDR, ADDR) \
37 ((ElfW(Addr))__reloc_pointer ((void*)(ADDR), (LOADADDR).map))
39 #define DL_ADDR_TO_FUNC_PTR(ADDR, LOADADDR) \
40 ((void(*)(void)) _dl_funcdesc_for ((void*)(ADDR), (LOADADDR).got_value))
42 #define _dl_stabilize_funcdesc(val) \
43 ({ __asm__ ("" : "+m" (*(val))); (val); })
45 #define DL_CALL_FUNC_AT_ADDR(ADDR, LOADADDR, SIGNATURE, ...) \
46 ({ struct funcdesc_value fd = { (void*)(ADDR), (LOADADDR).got_value }; \
47 void (*pf)(void) = (void*) _dl_stabilize_funcdesc (&fd); \
48 (* SIGNATURE pf)(__VA_ARGS__); })
50 #define DL_INIT_LOADADDR_BOOT(LOADADDR, BASEADDR) \
51 (__dl_init_loadaddr_map (&(LOADADDR), dl_boot_got_pointer, \
52 dl_boot_ldsomap ?: dl_boot_progmap))
54 #define DL_INIT_LOADADDR_PROG(LOADADDR, BASEADDR) \
55 (__dl_init_loadaddr_map (&(LOADADDR), 0, dl_boot_progmap))
57 #define DL_INIT_LOADADDR_EXTRA_DECLS \
58 int dl_init_loadaddr_load_count;
59 #define DL_INIT_LOADADDR(LOADADDR, BASEADDR, PHDR, PHDRCNT) \
60 (dl_init_loadaddr_load_count = \
61 __dl_init_loadaddr (&(LOADADDR), (PHDR), (PHDRCNT)))
62 #define DL_INIT_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \
63 (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \
64 dl_init_loadaddr_load_count))
65 #define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \
66 (__dl_update_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR)))
67 #define DL_LOADADDR_UNMAP(LOADADDR, LEN) \
68 (__dl_loadaddr_unmap ((LOADADDR), (NULL)))
69 #define DL_LIB_UNMAP(LIB, LEN) \
70 (__dl_loadaddr_unmap ((LIB)->loadaddr, (LIB)->funcdesc_ht))
71 #define DL_LOADADDR_BASE(LOADADDR) \
72 ((LOADADDR).got_value)
74 /* This is called from dladdr(), such that we map a function
75 descriptor's address to the function's entry point before trying to
76 find in which library it's defined. */
77 #define DL_LOOKUP_ADDRESS(ADDRESS) (_dl_lookup_address (ADDRESS))
79 #define DL_ADDR_IN_LOADADDR(ADDR, TPNT, TFROM) \
80 (! (TFROM) && __dl_addr_in_loadaddr ((void*)(ADDR), (TPNT)->loadaddr))
83 * Compute the GOT address. On several platforms, we use assembly
84 * here. on FDPIC, there's no way to compute the GOT address,
85 * since the offset between text and data is not fixed, so we arrange
86 * for the ldso assembly entry point to pass this value as an argument
87 * to _dl_start. */
88 #define DL_BOOT_COMPUTE_GOT(got) ((got) = dl_boot_got_pointer)
90 #define DL_BOOT_COMPUTE_DYN(dpnt, got, load_addr) \
91 ((dpnt) = dl_boot_ldso_dyn_pointer)
93 /* We want want to apply all relocations in the interpreter during
94 bootstrap. Because of this, we have to skip the interpreter
95 relocations in _dl_parse_relocation_information(), see
96 elfinterp.c. */
97 #define DL_SKIP_BOOTSTRAP_RELOC(SYMTAB, INDEX, STRTAB) 0
99 #if defined(__NR_pread) || defined(__NR_pread64)
100 #define _DL_PREAD(FD, BUF, SIZE, OFFSET) \
101 (_dl_pread((FD), (BUF), (SIZE), (OFFSET)))
102 #endif
104 /* We want to return to dlsym() a function descriptor if the symbol
105 turns out to be a function. */
106 #define DL_FIND_HASH_VALUE(TPNT, TYPE_CLASS, SYM) \
107 (((TYPE_CLASS) & ELF_RTYPE_CLASS_DLSYM) \
108 && ELF32_ST_TYPE((SYM)->st_info) == STT_FUNC \
109 ? _dl_funcdesc_for ((void *)DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value), \
110 (TPNT)->loadaddr.got_value) \
111 : DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value))
113 #define DL_GET_READY_TO_RUN_EXTRA_PARMS \
114 , struct elf32_fdpic_loadmap *dl_boot_progmap, Elf32_Addr dl_boot_got_pointer
115 #define DL_GET_READY_TO_RUN_EXTRA_ARGS \
116 , dl_boot_progmap, dl_boot_got_pointer
118 /* Define this to declare the library offset. */
119 #define DL_DEF_LIB_OFFSET
121 /* Define this to get the library offset. */
122 #define DL_GET_LIB_OFFSET() 0
124 /* Define this to set the library offset. */
125 #define DL_SET_LIB_OFFSET(offset)
127 /* Define this to get the real object's runtime address. */
128 #define DL_GET_RUN_ADDR(loadaddr, mapaddr) (loadaddr)
130 #ifdef __USE_GNU
131 # include <link.h>
132 #else
133 # define __USE_GNU
134 # include <link.h>
135 # undef __USE_GNU
136 #endif