OSDN Git Service

- fixup asm. No object-code changes
[uclinux-h8/uClibc.git] / ldso / ldso / frv / dl-sysdep.h
1 /* Copyright (C) 2003, 2004 Red Hat, Inc.
2  * Contributed by Alexandre Oliva <aoliva@redhat.com>
3  * Based on ../i386/dl-sysdep.h
4  *
5  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6  */
7
8 /*
9  * Various assembly language/system dependent  hacks that are required
10  * so that we can minimize the amount of platform specific code.
11  */
12
13 /*
14  * Define this if the system uses RELOCA.
15  */
16 #undef ELF_USES_RELOCA
17
18 /* JMPREL relocs are inside the DT_RELA table.  */
19 #define ELF_MACHINE_PLTREL_OVERLAP
20
21 #define DL_NO_COPY_RELOCS
22
23 /*
24  * Initialization sequence for a GOT.  Copy the resolver function
25  * descriptor and the pointer to the elf_resolve/link_map data
26  * structure.  Initialize the got_value in the module while at that.
27  */
28 #define INIT_GOT(GOT_BASE,MODULE) \
29 {                               \
30   (MODULE)->loadaddr.got_value = (GOT_BASE); \
31   GOT_BASE[0] = ((unsigned long *)&_dl_linux_resolve)[0]; \
32   GOT_BASE[1] = ((unsigned long *)&_dl_linux_resolve)[1]; \
33   GOT_BASE[2] = (unsigned long) MODULE; \
34 }
35
36 /* Here we define the magic numbers that this dynamic loader should accept */
37 #define MAGIC1 EM_CYGNUS_FRV
38 #undef  MAGIC2
39
40 /* Used for error messages */
41 #define ELF_TARGET "FR-V"
42
43 struct elf_resolve;
44
45 struct funcdesc_value
46 {
47   void *entry_point;
48   void *got_value;
49 } __attribute__((__aligned__(8)));
50
51
52 extern int _dl_linux_resolve(void) __attribute__((__visibility__("hidden")));
53
54 /* 16KiB page alignment.  Should perhaps be made dynamic using
55    getpagesize(), based on AT_PAGESZ from auxvt?  */
56 #define PAGE_ALIGN 0xffffc000
57 #define ADDR_ALIGN 0x3fff
58 #define OFFS_ALIGN 0x7fffc000
59
60 struct funcdesc_ht;
61
62 /* We must force strings used early in the bootstrap into the data
63    segment, such that they are referenced with GOTOFF instead of
64    GPREL, because GPREL needs the GOT to have already been
65    relocated.  */
66 #undef SEND_EARLY_STDERR
67 #define SEND_EARLY_STDERR(S) \
68   do { static char __s[] = (S); SEND_STDERR (__s); } while (0)
69
70 #define DL_LOADADDR_TYPE struct elf32_fdpic_loadaddr
71
72 #define DL_RELOC_ADDR(ADDR, LOADADDR) \
73   (__reloc_pointer ((void*)(ADDR), (LOADADDR).map))
74
75 #define DL_ADDR_TO_FUNC_PTR(ADDR, LOADADDR) \
76   ((void(*)(void)) _dl_funcdesc_for ((void*)(ADDR), (LOADADDR).got_value))
77
78 #define _dl_stabilize_funcdesc(val) \
79   ({ __asm__ ("" : "+m" (*(val))); (val); })
80
81 #define DL_CALL_FUNC_AT_ADDR(ADDR, LOADADDR, SIGNATURE, ...) \
82   ({ struct funcdesc_value fd = { (void*)(ADDR), (LOADADDR).got_value }; \
83      void (*pf)(void) = (void*) _dl_stabilize_funcdesc (&fd); \
84      (* SIGNATURE pf)(__VA_ARGS__); })
85
86 #define DL_INIT_LOADADDR_BOOT(LOADADDR, BASEADDR) \
87   (__dl_init_loadaddr_map (&(LOADADDR), dl_boot_got_pointer, \
88                            dl_boot_ldsomap ?: dl_boot_progmap))
89
90 #define DL_INIT_LOADADDR_PROG(LOADADDR, BASEADDR) \
91   (__dl_init_loadaddr_map (&(LOADADDR), 0, dl_boot_progmap))
92
93 #define DL_INIT_LOADADDR_EXTRA_DECLS \
94   int dl_init_loadaddr_load_count;
95 #define DL_INIT_LOADADDR(LOADADDR, BASEADDR, PHDR, PHDRCNT) \
96   (dl_init_loadaddr_load_count = \
97      __dl_init_loadaddr (&(LOADADDR), (PHDR), (PHDRCNT)))
98 #define DL_INIT_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \
99   (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \
100                            dl_init_loadaddr_load_count))
101 #define DL_LOADADDR_UNMAP(LOADADDR, LEN) \
102   (__dl_loadaddr_unmap ((LOADADDR), (NULL)))
103 #define DL_LIB_UNMAP(LIB, LEN) \
104   (__dl_loadaddr_unmap ((LIB)->loadaddr, (LIB)->funcdesc_ht))
105 #define DL_LOADADDR_BASE(LOADADDR) \
106   ((LOADADDR).got_value)
107
108 /* This is called from dladdr(), such that we map a function
109    descriptor's address to the function's entry point before trying to
110    find in which library it's defined.  */
111 #define DL_LOOKUP_ADDRESS(ADDRESS) (_dl_lookup_address (ADDRESS))
112
113 #define DL_ADDR_IN_LOADADDR(ADDR, TPNT, TFROM) \
114   (! (TFROM) && __dl_addr_in_loadaddr ((void*)(ADDR), (TPNT)->loadaddr))
115
116 /* Make sure we only load libraries that use the same number of
117    general-purpose and floating-point registers the dynamic loader was
118    compiled for.  */
119 #define DL_CHECK_REG_COUNT(flags) \
120   (((flags & EF_FRV_GPR_MASK) == EF_FRV_GPR_32 ? __FRV_GPR__ == 32 : 1) \
121    && ((flags & EF_FRV_GPR_MASK) == EF_FRV_GPR_64 ? __FRV_GPR__ == 64 : 1) \
122    && ((flags & EF_FRV_FPR_MASK) == EF_FRV_FPR_32 ? __FRV_FPR__ == 32 : 1) \
123    && ((flags & EF_FRV_FPR_MASK) == EF_FRV_FPR_64 ? __FRV_FPR__ == 64 : 1) \
124    && ((flags & EF_FRV_FPR_MASK) == EF_FRV_FPR_NONE ? __FRV_FPR__ == 0 : 1))
125
126 /* We only support loading FDPIC independently-relocatable shared
127    libraries.  It probably wouldn't be too hard to support loading
128    shared libraries that require relocation by the same amount, but we
129    don't know that they exist or would be useful, and the dynamic
130    loader code could leak the whole-library map unless we keeping a
131    bit more state for DL_LOADADDR_UNMAP and DL_LIB_UNMAP, so let's
132    keep things simple for now.  */
133 #define DL_CHECK_LIB_TYPE(epnt, piclib, _dl_progname, libname) \
134 do \
135 { \
136   if (((epnt)->e_flags & EF_FRV_FDPIC) && ! ((epnt)->e_flags & EF_FRV_PIC)) \
137     (piclib) = 2; \
138   else \
139     { \
140       _dl_internal_error_number = LD_ERROR_NOTDYN; \
141       _dl_dprintf(2, "%s: '%s' is not an FDPIC shared library" \
142                   "\n", (_dl_progname), (libname)); \
143       _dl_close(infile); \
144       return NULL; \
145     } \
146 \
147   if (! DL_CHECK_REG_COUNT ((epnt)->e_flags)) \
148     { \
149       _dl_internal_error_number = LD_ERROR_NOTDYN; \
150       _dl_dprintf(2, "%s: '%s' assumes different register counts" \
151                   "\n", (_dl_progname), (libname)); \
152       _dl_close(infile); \
153     } \
154 } \
155 while (0)  
156
157 /* We want want to apply all relocations in the interpreter during
158    bootstrap.  Because of this, we have to skip the interpreter
159    relocations in _dl_parse_relocation_information(), see
160    elfinterp.c.  */
161 #define DL_SKIP_BOOTSTRAP_RELOC(SYMTAB, INDEX, STRTAB) 0
162
163 #ifdef __NR_pread
164 #define _DL_PREAD(FD, BUF, SIZE, OFFSET) \
165   (_dl_pread((FD), (BUF), (SIZE), (OFFSET)))
166 #endif
167
168 /* We want to return to dlsym() a function descriptor if the symbol
169    turns out to be a function.  */
170 #define DL_FIND_HASH_VALUE(TPNT, TYPE_CLASS, SYM) \
171   (((TYPE_CLASS) & ELF_RTYPE_CLASS_DLSYM) \
172    && ELF32_ST_TYPE((SYM)->st_info) == STT_FUNC \
173    ? _dl_funcdesc_for (DL_RELOC_ADDR ((SYM)->st_value, (TPNT)->loadaddr),    \
174                        (TPNT)->loadaddr.got_value)                           \
175    : DL_RELOC_ADDR ((SYM)->st_value, (TPNT)->loadaddr))
176
177 #define DL_GET_READY_TO_RUN_EXTRA_PARMS \
178   , struct elf32_fdpic_loadmap *dl_boot_progmap
179 #define DL_GET_READY_TO_RUN_EXTRA_ARGS \
180   , dl_boot_progmap
181
182           
183
184
185 #ifdef __USE_GNU
186 # include <link.h>
187 #else
188 # define __USE_GNU
189 # include <link.h>
190 # undef __USE_GNU
191 #endif