OSDN Git Service

Get rid of hidden_def
[uclinux-h8/uClibc.git] / include / libc-internal.h
1 /* Copyright (C) 1991,92,93,95,96,97,98,99,2000,2001 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #ifndef _LIBC_INTERNAL_H
20 #define _LIBC_INTERNAL_H 1
21
22 #include <features.h>
23
24 #ifndef __ASSEMBLER__
25 /* GCC understands weak symbols and aliases; use its interface where
26    possible, instead of embedded assembly language.  */
27
28 /* Define ALIASNAME as a strong alias for NAME.  */
29 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
30 # define _strong_alias(name, aliasname) \
31   extern __typeof (name) aliasname __attribute__ ((alias (#name)));
32
33 /* This comes between the return type and function name in
34    a function definition to make that definition weak.  */
35 # define weak_function __attribute__ ((weak))
36 # define weak_const_function __attribute__ ((weak, __const__))
37
38 /* Define ALIASNAME as a weak alias for NAME.
39    If weak aliases are not available, this defines a strong alias.  */
40 # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
41 # define _weak_alias(name, aliasname) \
42   extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
43
44 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined).  */
45 # define weak_extern(symbol) _weak_extern (weak symbol)
46 # define _weak_extern(expr) _Pragma (#expr)
47
48 #else /* __ASSEMBLER__ */
49
50 #ifdef __SYMBOL_PREFIX
51 # define C_SYMBOL_NAME(name) _##name
52 #else
53 # define C_SYMBOL_NAME(name) name
54 #endif
55
56 # define strong_alias(name, aliasname)                                  \
57   .global C_SYMBOL_NAME (aliasname) ;                                   \
58   .set C_SYMBOL_NAME(aliasname),C_SYMBOL_NAME(name)
59
60 # define weak_alias(name, aliasname)                                    \
61   .weak C_SYMBOL_NAME(aliasname) ;                                      \
62   C_SYMBOL_NAME(aliasname) = C_SYMBOL_NAME(name)
63
64 # define weak_extern(symbol)                                            \
65   .weak C_SYMBOL_NAME(symbol)
66
67 #endif /* __ASSEMBLER__ */
68
69 /* When a reference to SYMBOL is encountered, the linker will emit a
70    warning message MSG.  */
71 #ifdef __HAVE_ELF__
72
73 /* We want the .gnu.warning.SYMBOL section to be unallocated.  */
74 # define __make_section_unallocated(section_string)     \
75   asm (".section " section_string "\n\t.previous");
76
77 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
78    section attributes on what looks like a comment to the assembler.  */
79 # define __sec_comment "\n\t#"
80 # ifdef __cris__
81 #  define link_warning(symbol, msg)
82 # else
83 #  define link_warning(symbol, msg) \
84   __make_section_unallocated (".gnu.warning." #symbol) \
85   static const char __evoke_link_warning_##symbol[]     \
86     __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
87     = msg;
88 # endif
89 #else /* __HAVE_ELF__ */
90 # define link_warning(symbol, msg)              \
91      asm (".stabs \"" msg "\",30,0,0,0\n\t"     \
92           ".stabs \"" __C_SYMBOL_PREFIX__ #symbol "\",1,0,0,0\n");
93 #endif /* __HAVE_ELF__ */
94
95 #ifndef weak_function
96 /* If we do not have the __attribute__ ((weak)) syntax, there is no way we
97    can define functions as weak symbols.  The compiler will emit a `.globl'
98    directive for the function symbol, and a `.weak' directive in addition
99    will produce an error from the assembler.  */ 
100 # define weak_function          /* empty */
101 # define weak_const_function    /* empty */
102 #endif
103
104 /* On some platforms we can make internal function calls (i.e., calls of
105    functions not exported) a bit faster by using a different calling
106    convention.  */
107 #if 0 /*def __i386__*/
108 # define internal_function __attribute__ ((regparm (3), stdcall))
109 #endif
110 #ifndef internal_function
111 # define internal_function      /* empty */
112 #endif
113
114 #ifndef NOT_IN_libc
115 # define IS_IN_libc 1
116 #endif
117
118 /* Prepare for the case that `__builtin_expect' is not available.  */
119 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
120 # define __builtin_expect(x, expected_value) (x)
121 #endif
122 #ifndef likely
123 # define likely(x)      __builtin_expect((!!(x)),1)
124 #endif
125 #ifndef unlikely
126 # define unlikely(x)    __builtin_expect((!!(x)),0)
127 #endif
128 #ifndef __LINUX_COMPILER_H
129 # define __LINUX_COMPILER_H
130 #endif
131 #ifndef __cast__
132 # define __cast__(_to)
133 #endif
134
135 #define attribute_unused __attribute__ ((unused))
136
137 /* Arrange to hide uClibc internals */
138 #if __GNUC_PREREQ (3, 3)
139 # define attribute_hidden __attribute__ ((visibility ("hidden")))
140 #else
141 # define attribute_hidden
142 #endif
143
144 #ifndef __ASSEMBLER__
145 # define hidden_strong_alias(name, aliasname) _hidden_strong_alias(name, aliasname)
146 # define _hidden_strong_alias(name, aliasname) \
147   extern __typeof (name) aliasname __attribute__ ((alias (#name))) attribute_hidden;
148
149 # define hidden_weak_alias(name, aliasname) _hidden_weak_alias (name, aliasname)
150 # define _hidden_weak_alias(name, aliasname) \
151   extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) attribute_hidden;
152 #else /* __ASSEMBLER__ */
153 # define hidden_strong_alias(name, aliasname)                           \
154   .global C_SYMBOL_NAME (aliasname) ;                                   \
155   .hidden C_SYMBOL_NAME (aliasname) ;                                   \
156   .set C_SYMBOL_NAME(aliasname),C_SYMBOL_NAME(name)
157
158 # define hidden_weak_alias(name, aliasname)                             \
159   .weak C_SYMBOL_NAME(aliasname) ;                                      \
160   .hidden C_SYMBOL_NAME(aliasname) ;                                    \
161   C_SYMBOL_NAME(aliasname) = C_SYMBOL_NAME(name)
162 #endif /* __ASSEMBLER__ */
163
164 #ifdef __UCLIBC_BUILD_RELRO__
165 # define attribute_relro __attribute__ ((section (".data.rel.ro")))
166 #else
167 # define attribute_relro
168 #endif
169
170 #ifdef __GNUC__
171 # define attribute_noreturn __attribute__ ((__noreturn__))
172 #else
173 # define attribute_noreturn
174 #endif
175
176 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
177 # define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
178 #endif
179
180 /* Pull in things like __attribute_used__ */
181 #include <sys/cdefs.h>
182
183 /* --- this is added to integrate linuxthreads */
184 #define __USE_UNIX98            1
185
186 #ifndef __ASSEMBLER__
187 # ifdef IS_IN_libc
188
189 #  define __UC(N) __ ## N
190 #  define __UC_ALIAS(N) strong_alias( __ ## N , N )
191 #  if defined __UCLIBC_HAS_XLOCALE__ && defined __UCLIBC_DO_XLOCALE
192 #   define __UCXL(N) __ ## N ## _l
193 #   define __UCXL_ALIAS(N) strong_alias ( __ ## N ## _l , N ## _l )
194 #  else
195 #   define __UCXL(N) __UC(N)
196 #   define __UCXL_ALIAS(N) __UC_ALIAS(N)
197 #  endif
198
199 #  define __need_size_t
200 #  ifdef __UCLIBC_HAS_WCHAR__
201 #   define __need_wchar_t
202 #   define __need_wint_t
203 #  endif
204 #  include <stddef.h>
205
206 #  include <bits/types.h>
207
208 #  ifndef __ssize_t_defined
209 typedef __ssize_t ssize_t;
210 #   define __ssize_t_defined
211 #  endif
212
213 #  include <bits/sigset.h>
214
215 /* prototypes for internal use, please keep these in sync w/ updated headers */
216 /* #include <fcntl.h> */
217 #ifndef __USE_FILE_OFFSET64
218 extern int __open (__const char *__file, int __oflag, ...) __nonnull ((1)) attribute_hidden;
219 extern int __fcntl (int __fd, int __cmd, ...) attribute_hidden;
220 #else
221 # ifdef __REDIRECT
222 extern int __REDIRECT (__open, (__const char *__file, int __oflag, ...), __open64)
223      __nonnull ((1)) attribute_hidden;
224 extern int __REDIRECT (__fcntl, (int __fd, int __cmd, ...), __fcntl64) attribute_hidden;
225 # else
226 #  define __open __open64
227 #  define __fcntl __fcntl64
228 # endif
229 #endif
230 #ifdef __USE_LARGEFILE64
231 extern int __open64 (__const char *__file, int __oflag, ...) __nonnull ((1)) attribute_hidden;
232 extern int __fcntl64 (int __fd, int __cmd, ...) attribute_hidden;
233 #endif
234
235 /* #include <string.h> */
236 extern int __memcmp (__const void *__s1, __const void *__s2, size_t __n) attribute_hidden;
237 extern void *__memcpy (void *__restrict __dest,
238                      __const void *__restrict __src, size_t __n) attribute_hidden;
239 extern void *__memmove (void *__dest, __const void *__src, size_t __n) attribute_hidden;
240 extern void *__memset (void *__s, int __c, size_t __n) attribute_hidden;
241 extern char *__strcpy (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
242 extern size_t __strlen (__const char *__s) attribute_hidden;
243 extern int __strcmp (__const char *__s1, __const char *__s2) attribute_hidden;
244 extern char *__strcat (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
245 extern char *__strncpy (char *__restrict __dest,
246                       __const char *__restrict __src, size_t __n) attribute_hidden;
247 extern char *__strchr (__const char *__s, int __c) attribute_hidden;
248 extern char *__strrchr (__const char *__s, int __c) attribute_hidden;
249 extern int __strncmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
250 extern char *__strdup (__const char *__s) attribute_hidden;
251 extern int __strcasecmp (__const char *__s1, __const char *__s2) attribute_hidden;
252 extern int __strncasecmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
253 extern void *__rawmemchr (__const void *__s, int __c) __THROW __attribute_pure__ __nonnull ((1)) attribute_hidden;
254 extern size_t __strspn (__const char *__s, __const char *__accept)
255      __THROW __attribute_pure__ __nonnull ((1, 2)) attribute_hidden;
256 extern char *__strpbrk (__const char *__s, __const char *__accept)
257      __THROW __attribute_pure__ __nonnull ((1, 2)) attribute_hidden;
258 extern size_t __strnlen (__const char *__string, size_t __maxlen)
259      __THROW __attribute_pure__ __nonnull ((1)) attribute_hidden;
260 extern char *__strtok_r (char *__restrict __s, __const char *__restrict __delim,
261                        char **__restrict __save_ptr) __THROW __nonnull ((2, 3)) attribute_hidden;
262
263 /* sources are built w/ _GNU_SOURCE, this gets undefined */
264 extern int __xpg_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
265 extern char *__glibc_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
266
267 /* ctype.h */
268 extern int __tolower (int __c) __THROW attribute_hidden;
269 extern int __toupper (int __c) __THROW attribute_hidden;
270
271 #ifdef __UCLIBC_HAS_WCHAR__
272 /* wchar.h */
273 extern size_t __wcslen (__const wchar_t *__s) __THROW __attribute_pure__ attribute_hidden;
274 extern wchar_t *__wcscpy (wchar_t *__restrict __dest, __const wchar_t *__restrict __src) __THROW attribute_hidden;
275 extern size_t __wcsspn (__const wchar_t *__wcs, __const wchar_t *__accept)
276      __THROW __attribute_pure__ attribute_hidden;
277 extern wchar_t *__wcspbrk (__const wchar_t *__wcs, __const wchar_t *__accept)
278      __THROW __attribute_pure__ attribute_hidden;
279 /* wctype.h */
280 extern wint_t __towlower (wint_t __wc) __THROW attribute_hidden;
281 #endif
282
283 /* #include <unistd.h> */
284 extern ssize_t __read(int __fd, void *__buf, size_t __nbytes) attribute_hidden;
285 extern ssize_t __write(int __fd, __const void *__buf, size_t __n) attribute_hidden;
286 extern int __close(int __fd) attribute_hidden;
287 extern __pid_t __getpid (void) attribute_hidden;
288 extern void _exit_internal (int __status) __attribute__ ((__noreturn__)) attribute_hidden;
289 #ifndef __USE_FILE_OFFSET64
290 extern int __lockf (int __fd, int __cmd, __off_t __len) attribute_hidden;
291 extern __off_t __lseek (int __fd, __off_t __offset, int __whence) __THROW attribute_hidden;
292 #else
293 # ifdef __REDIRECT
294 extern int __REDIRECT (__lockf, (int __fd, int __cmd, __off64_t __len),
295                        __lockf64) attribute_hidden;
296 extern __off64_t __REDIRECT (__lseek,
297                                  (int __fd, __off64_t __offset, int __whence),
298                                  __lseek64) attribute_hidden;
299 # else
300 #  define __lockf __lockf64
301 #  define __lseek __lseek64
302 # endif
303 #endif
304 #ifdef __USE_LARGEFILE64
305 extern int __lockf64 (int __fd, int __cmd, __off64_t __len) attribute_hidden;
306 extern __off64_t __lseek64 (int __fd, __off64_t __offset, int __whence) __THROW attribute_hidden;
307 #endif
308
309 /* #include <stdio.h> */
310 extern void __perror (__const char *__s) attribute_hidden;
311 extern int __printf (__const char *__restrict __format, ...) attribute_hidden;
312 extern int __sprintf (char *__restrict __s,
313                     __const char *__restrict __format, ...) attribute_hidden;
314
315 /* hack */
316 #define abort __abort
317 #define fprintf __fprintf
318 #define fclose __fclose
319 #ifndef __USE_FILE_OFFSET64
320 #define fopen __fopen
321 #else
322 #define fopen __fopen64
323 #endif
324 #ifdef __USE_LARGEFILE64
325 #define fopen64 __fopen64
326 #endif
327
328 /* #include <stdlib.h> */
329 extern char *__getenv (__const char *__name) attribute_hidden;
330 extern void __exit (int __status) __THROW __attribute__ ((__noreturn__)) attribute_hidden;
331
332 /* #include <signal.h> */
333 extern int __sigprocmask (int __how, __const __sigset_t *__restrict __set,
334                         __sigset_t *__restrict __oset) attribute_hidden;
335
336 /* #include <sys/ioctl.h> */
337 extern int __ioctl (int __fd, unsigned long int __request, ...) attribute_hidden;
338
339 /* #include <sys/socket.h> */
340 extern int __socket (int __domain, int __type, int __protocol) attribute_hidden;
341
342 /* #include <sys/stat.h> */
343 #ifndef __USE_FILE_OFFSET64
344 struct stat;
345 extern int __stat (__const char *__restrict __file,
346                  struct stat *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
347 extern int __fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2)) attribute_hidden;
348 extern int __lstat (__const char *__restrict __file,
349                   struct stat *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
350 #else
351 # ifdef __REDIRECT_NTH
352 extern int __REDIRECT_NTH (__stat, (__const char *__restrict __file,
353                                   struct stat *__restrict __buf), __stat64)
354      __nonnull ((1, 2)) attribute_hidden;
355 extern int __REDIRECT_NTH (__fstat, (int __fd, struct stat *__buf), __fstat64)
356      __nonnull ((2)) attribute_hidden;
357 extern int __REDIRECT_NTH (__lstat,
358                            (__const char *__restrict __file,
359                             struct stat *__restrict __buf), __lstat64)
360      __nonnull ((1, 2)) attribute_hidden;
361 # else
362 #  define __stat __stat64
363 #  define __fstat __fstat64
364 #   define __lstat __lstat64
365 # endif
366 #endif
367 #ifdef __USE_LARGEFILE64
368 struct stat64;
369 extern int __stat64 (__const char *__restrict __file,
370                    struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
371 extern int __fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2)) attribute_hidden;
372 extern int __lstat64 (__const char *__restrict __file,
373                     struct stat64 *__restrict __buf)
374      __THROW __nonnull ((1, 2)) attribute_hidden;
375 #endif
376
377 /* #include <sys/statfs.h> */
378 #ifndef __USE_FILE_OFFSET64
379 struct statfs;
380 extern int __statfs (__const char *__file, struct statfs *__buf)
381      __THROW __nonnull ((1, 2)) attribute_hidden;
382 extern int __fstatfs (int __fildes, struct statfs *__buf)
383      __THROW __nonnull ((2)) attribute_hidden;
384 #else
385 # ifdef __REDIRECT
386 extern int __REDIRECT (__statfs,
387                            (__const char *__file, struct statfs *__buf),
388                            __statfs64) __nonnull ((1, 2)) attribute_hidden;
389 extern int __REDIRECT (__fstatfs, (int __fildes, struct statfs *__buf),
390                            __fstatfs64) __nonnull ((2)) attribute_hidden;
391 # else
392 #  define __statfs __statfs64
393 # endif
394 #endif
395 #ifdef __USE_LARGEFILE64
396 struct statfs64;
397 extern int __statfs64 (__const char *__file, struct statfs64 *__buf)
398      __THROW __nonnull ((1, 2)) attribute_hidden;
399 extern int __fstatfs64 (int __fildes, struct statfs64 *__buf)
400      __THROW __nonnull ((2)) attribute_hidden;
401 #endif
402
403 #  if 0 /* undoable here */
404 /* #include <dirent.h> */
405 typedef struct __dirstream DIR;
406 extern DIR *__opendir (__const char *__name) attribute_hidden;
407 extern int __closedir (DIR *__dirp) attribute_hidden;
408
409 /* #include <stdio.h> */
410 extern int __vfprintf (FILE *__restrict __s, __const char *__restrict __format,
411                      __gnuc_va_list __arg) attribute_hidden;
412 extern int __fprintf (FILE *__restrict __stream,
413                     __const char *__restrict __format, ...) attribute_hidden;
414 extern int __fclose (FILE *__stream) attribute_hidden;
415
416 #ifndef __USE_FILE_OFFSET64
417 extern FILE *__fopen (__const char *__restrict __filename,
418                     __const char *__restrict __modes) attribute_hidden;
419 #else
420 # ifdef __REDIRECT
421 extern FILE *__REDIRECT (__fopen, (__const char *__restrict __filename,
422                                  __const char *__restrict __modes), __fopen64) attribute_hidden;
423 # else
424 #  define __fopen __fopen64
425 # endif
426 #endif
427 #ifdef __USE_LARGEFILE64
428 extern FILE *__fopen64 (__const char *__restrict __filename,
429                       __const char *__restrict __modes) attribute_hidden;
430 #endif
431
432 /* #include <sys/time.h> */
433 #   define __need_timeval
434 #   include <bits/time.h>
435 extern int __gettimeofday(struct timeval *__restrict __tv, *__restrict __timezone__ptr_t __tz) attribute_hidden;
436 #  endif
437
438 /* #include <pthread.h> */
439 #  ifndef __UCLIBC_HAS_THREADS__
440 #   define __pthread_mutex_init(mutex, mutexattr)         ((void)0)
441 #   define __pthread_mutex_lock(mutex)                    ((void)0)
442 #   define __pthread_mutex_trylock(mutex)                 ((void)0)
443 #   define __pthread_mutex_unlock(mutex)                  ((void)0)
444 #  endif
445
446 /* internal access to program name */
447 extern const char *__uclibc_progname attribute_hidden;
448
449 # endif /* IS_IN_libc */
450
451 /* #include <alloca.h> */
452 #include <bits/stackinfo.h>
453 #if _STACK_GROWS_DOWN
454 # define extend_alloca(buf, len, newlen) \
455   (__typeof (buf)) ({ size_t __newlen = (newlen);                             \
456                       char *__newbuf = alloca (__newlen);                     \
457                       if (__newbuf + __newlen == (char *) buf)                \
458                         len += __newlen;                                      \
459                       else                                                    \
460                         len = __newlen;                                       \
461                       __newbuf; })
462 #elif _STACK_GROWS_UP
463 # define extend_alloca(buf, len, newlen) \
464   (__typeof (buf)) ({ size_t __newlen = (newlen);                             \
465                       char *__newbuf = alloca (__newlen);                     \
466                       char *__buf = (buf);                                    \
467                       if (__buf + __newlen == __newbuf)                       \
468                         {                                                     \
469                           len += __newlen;                                    \
470                           __newbuf = __buf;                                   \
471                         }                                                     \
472                       else                                                    \
473                         len = __newlen;                                       \
474                       __newbuf; })
475 #else
476 # warning unknown stack
477 # define extend_alloca(buf, len, newlen) \
478   alloca (((len) = (newlen)))
479 #endif
480
481 #endif /* __ASSEMBLER__ */
482
483 #endif /* _LIBC_INTERNAL_H */