1995-02-18 09:27:10 +08:00
|
|
|
|
/* Support macros for making weak and strong aliases for symbols,
|
|
|
|
|
and for using symbol sets and linker warnings with GNU ld.
|
1996-02-27 08:55:03 +08:00
|
|
|
|
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
1995-02-18 09:27:10 +08:00
|
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with the GNU C Library; see the file COPYING.LIB. If
|
|
|
|
|
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
|
|
|
|
Cambridge, MA 02139, USA. */
|
|
|
|
|
|
|
|
|
|
#ifndef _LIBC_SYMBOLS_H
|
|
|
|
|
#define _LIBC_SYMBOLS_H
|
|
|
|
|
|
|
|
|
|
/* This file's macros are included implicitly in the compilation of every
|
|
|
|
|
file in the C library by -imacros.
|
|
|
|
|
|
|
|
|
|
We include config.h which is generated by configure.
|
|
|
|
|
It should define for us the following symbols:
|
|
|
|
|
|
1996-03-20 05:10:11 +08:00
|
|
|
|
* HAVE_ASM_SET_DIRECTIVE if we have `.set B, A' instead of `A = B'.
|
|
|
|
|
* ASM_GLOBAL_DIRECTIVE with `.globl' or `.global'.
|
1995-02-18 09:27:10 +08:00
|
|
|
|
* HAVE_GNU_LD if using GNU ld, with support for weak symbols in a.out,
|
|
|
|
|
and for symbol set and warning messages extensions in a.out and ELF.
|
1996-03-20 05:10:11 +08:00
|
|
|
|
* HAVE_ELF if using ELF, which supports weak symbols using `.weak'.
|
|
|
|
|
* HAVE_ASM_WEAK_DIRECTIVE if we have weak symbols using `.weak'.
|
|
|
|
|
* HAVE_ASM_WEAKEXT_DIRECTIVE if we have weak symbols using `.weakext'.
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
1996-02-27 08:55:03 +08:00
|
|
|
|
/* This is defined for the compilation of all C library code. features.h
|
|
|
|
|
tests this to avoid inclusion of stubs.h while compiling the library,
|
|
|
|
|
before stubs.h has been generated. Some library code that is shared
|
|
|
|
|
with other packages also tests this symbol to see if it is being
|
|
|
|
|
compiled as part of the C library. We must define this before including
|
|
|
|
|
config.h, because it makes some definitions conditional on whether libc
|
|
|
|
|
itself is being compiled, or just some generator program. */
|
1995-09-27 10:50:10 +08:00
|
|
|
|
#define _LIBC 1
|
1996-02-27 08:55:03 +08:00
|
|
|
|
|
1996-03-20 05:59:41 +08:00
|
|
|
|
/* Enable declarations of GNU extensions, since we are compiling them. */
|
|
|
|
|
#define _GNU_SOURCE 1
|
|
|
|
|
|
1996-02-27 08:55:03 +08:00
|
|
|
|
#include <config.h>
|
1995-10-17 10:14:34 +08:00
|
|
|
|
/*
|
|
|
|
|
|
1995-10-17 13:49:48 +08:00
|
|
|
|
*/
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
1995-10-17 13:49:48 +08:00
|
|
|
|
#ifndef ASSEMBLER
|
1995-11-27 01:45:08 +08:00
|
|
|
|
|
|
|
|
|
/* Define the macros `_' and `N_' for conveniently marking translatable
|
|
|
|
|
strings in the libc source code. */
|
|
|
|
|
|
|
|
|
|
#define N_(msgid) msgid
|
|
|
|
|
|
1995-10-17 10:14:34 +08:00
|
|
|
|
#include <libintl.h>
|
|
|
|
|
extern const char _libc_intl_domainname[];
|
1995-11-27 01:45:08 +08:00
|
|
|
|
|
1995-10-17 10:14:34 +08:00
|
|
|
|
#ifdef dgettext
|
|
|
|
|
/* This is defined as an optimizing macro, so use it. */
|
|
|
|
|
#define _(msgid) dgettext (_libc_intl_domainname, (msgid))
|
|
|
|
|
#else
|
|
|
|
|
/* Be sure to use only the __ name when `dgettext' is a plain function
|
|
|
|
|
instead of an optimizing macro. */
|
|
|
|
|
#define _(msgid) __dgettext (_libc_intl_domainname, (msgid))
|
|
|
|
|
#endif
|
1995-11-27 01:45:08 +08:00
|
|
|
|
|
1995-10-17 13:49:48 +08:00
|
|
|
|
#endif
|
1995-10-17 10:14:34 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
*/
|
1996-03-20 05:10:11 +08:00
|
|
|
|
/* The symbols in all the user (non-_) macros are C symbols.
|
|
|
|
|
HAVE_GNU_LD without HAVE_ELF implies a.out. */
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
1996-03-20 05:10:11 +08:00
|
|
|
|
#if defined (HAVE_ASM_WEAK_DIRECTIVE) || defined (HAVE_ASM_WEAKEXT_DIRECTIVE)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#define HAVE_WEAK_SYMBOLS
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef __SYMBOL_PREFIX
|
|
|
|
|
#ifdef NO_UNDERSCORES
|
|
|
|
|
#define __SYMBOL_PREFIX
|
|
|
|
|
#else
|
|
|
|
|
#define __SYMBOL_PREFIX "_"
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef C_SYMBOL_NAME
|
|
|
|
|
#ifdef NO_UNDERSCORES
|
|
|
|
|
#define C_SYMBOL_NAME(name) name
|
|
|
|
|
#else
|
|
|
|
|
#define C_SYMBOL_NAME(name) _##name
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
1995-04-19 05:07:40 +08:00
|
|
|
|
|
1995-02-18 09:27:10 +08:00
|
|
|
|
/* Define ALIAS as a strong alias for ORIGINAL. */
|
1995-04-14 11:27:44 +08:00
|
|
|
|
#ifdef HAVE_ASM_SET_DIRECTIVE
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#define strong_alias_asm(original, alias) \
|
1995-04-19 05:07:40 +08:00
|
|
|
|
ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
|
1995-02-18 09:27:10 +08:00
|
|
|
|
.set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
|
|
|
|
|
#ifdef ASSEMBLER
|
|
|
|
|
#define strong_alias(original, alias) strong_alias_asm (original, alias)
|
|
|
|
|
#else
|
|
|
|
|
#define strong_alias(original, alias) \
|
1995-04-19 05:07:40 +08:00
|
|
|
|
asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
|
|
|
|
|
".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original);
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#endif
|
1995-04-14 11:27:44 +08:00
|
|
|
|
#else
|
|
|
|
|
#define strong_alias_asm(original, alias) \
|
1995-04-19 05:07:40 +08:00
|
|
|
|
ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
|
1995-04-14 11:27:44 +08:00
|
|
|
|
C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
|
|
|
|
|
#ifdef ASSEMBLER
|
|
|
|
|
#define strong_alias(original, alias) strong_alias_asm (original, alias)
|
|
|
|
|
#else
|
|
|
|
|
#define strong_alias(original, alias) \
|
1995-04-19 05:07:40 +08:00
|
|
|
|
asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
|
|
|
|
|
__SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
|
1995-04-14 11:27:44 +08:00
|
|
|
|
#endif
|
|
|
|
|
#endif
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
1995-04-19 05:07:40 +08:00
|
|
|
|
/* Helper macros used above. */
|
|
|
|
|
#define __string_1(x) __string_0(x)
|
|
|
|
|
#define __string_0(x) #x
|
|
|
|
|
|
|
|
|
|
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#ifdef HAVE_WEAK_SYMBOLS
|
1996-03-20 05:10:11 +08:00
|
|
|
|
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#ifdef ASSEMBLER
|
1995-04-19 05:07:40 +08:00
|
|
|
|
|
1996-03-20 05:10:11 +08:00
|
|
|
|
#ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
|
|
|
|
|
|
|
|
|
|
/* Define ALIAS as a weak alias for ORIGINAL.
|
|
|
|
|
If weak aliases are not available, this defines a strong alias. */
|
|
|
|
|
#define weak_alias(original, alias) \
|
|
|
|
|
.weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
|
|
|
|
|
|
|
|
|
|
/* Declare SYMBOL to be weak. */
|
|
|
|
|
#define weak_symbol(symbol) .weakext C_SYMBOL_NAME (symbol)
|
|
|
|
|
|
|
|
|
|
#else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
|
|
|
|
|
|
1995-04-19 05:07:40 +08:00
|
|
|
|
/* Define ALIAS as a weak alias for ORIGINAL.
|
|
|
|
|
If weak aliases are not available, this defines a strong alias. */
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#define weak_alias(original, alias) \
|
|
|
|
|
.weak C_SYMBOL_NAME (alias); \
|
|
|
|
|
C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
|
1995-02-23 07:19:35 +08:00
|
|
|
|
|
|
|
|
|
/* Declare SYMBOL to be weak. */
|
|
|
|
|
#define weak_symbol(symbol) .weak C_SYMBOL_NAME (symbol)
|
1995-04-19 05:07:40 +08:00
|
|
|
|
|
1996-03-20 05:10:11 +08:00
|
|
|
|
#endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
|
|
|
|
|
|
|
|
|
|
#else /* ! ASSEMBLER */
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
|
|
|
|
|
#define weak_symbol(symbol) asm (".weakext " __SYMBOL_PREFIX #symbol);
|
|
|
|
|
#define weak_alias(original, alias) \
|
|
|
|
|
asm (".weakext " __SYMBOL_PREFIX #alias ", " __SYMBOL_PREFIX #original);
|
|
|
|
|
#else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
|
1995-02-23 07:19:35 +08:00
|
|
|
|
#define weak_symbol(symbol) asm (".weak " __SYMBOL_PREFIX #symbol);
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#define weak_alias(original, alias) \
|
|
|
|
|
asm (".weak " __SYMBOL_PREFIX #alias "\n" \
|
|
|
|
|
__SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
|
1996-03-20 05:10:11 +08:00
|
|
|
|
#endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
|
|
|
|
|
#endif /* ! ASSEMBLER */
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#else
|
|
|
|
|
#define weak_alias(original, alias) strong_alias(original, alias)
|
1995-02-23 07:19:35 +08:00
|
|
|
|
#define weak_symbol(symbol) /* Do nothing. */
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
1995-07-26 15:10:58 +08:00
|
|
|
|
#if (!defined (ASSEMBLER) && \
|
1995-11-14 18:00:21 +08:00
|
|
|
|
(__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)))
|
|
|
|
|
/* GCC 2.8 and later has special syntax for weak symbols and aliases.
|
1995-07-26 15:10:58 +08:00
|
|
|
|
Using that is better when possible, because the compiler and assembler
|
|
|
|
|
are better clued in to what we are doing. */
|
|
|
|
|
#undef strong_alias
|
|
|
|
|
#define strong_alias(name, aliasname) \
|
1996-03-02 02:45:35 +08:00
|
|
|
|
__typeof (name) aliasname __attribute__ ((alias (#name)));
|
1995-07-26 15:10:58 +08:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_WEAK_SYMBOLS
|
|
|
|
|
#undef weak_symbol
|
|
|
|
|
#define weak_symbol(name) \
|
1995-08-15 06:49:23 +08:00
|
|
|
|
extern __typeof (name) name __attribute__ ((weak));
|
1995-07-26 15:10:58 +08:00
|
|
|
|
#undef weak_alias
|
|
|
|
|
#define weak_alias(name, aliasname) \
|
1996-03-02 02:45:35 +08:00
|
|
|
|
__typeof (name) aliasname __attribute__ ((weak, alias (#name)));
|
1995-07-26 15:10:58 +08:00
|
|
|
|
#endif /* HAVE_WEAK_SYMBOLS. */
|
1995-11-14 18:00:21 +08:00
|
|
|
|
#endif /* Not ASSEMBLER, and GCC 2.8 or later. */
|
1995-07-26 15:10:58 +08:00
|
|
|
|
|
|
|
|
|
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
1995-09-02 06:25:08 +08:00
|
|
|
|
/* When a reference to SYMBOL is encountered, the linker will emit a
|
|
|
|
|
warning message MSG. */
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#ifdef HAVE_GNU_LD
|
|
|
|
|
#ifdef HAVE_ELF
|
1995-09-02 06:25:08 +08:00
|
|
|
|
#define link_warning(symbol, msg) \
|
|
|
|
|
static const char __evoke_link_warning_##symbol[] \
|
|
|
|
|
__attribute__ ((section (".gnu.warning." #symbol))) = msg;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#else
|
1995-09-02 06:25:08 +08:00
|
|
|
|
#define link_warning(symbol, msg) \
|
1995-02-18 09:27:10 +08:00
|
|
|
|
asm(".stabs \"" msg "\",30,0,0,0\n" \
|
1995-09-02 06:25:08 +08:00
|
|
|
|
".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#endif
|
|
|
|
|
#else
|
|
|
|
|
/* We will never be heard; they will all die horribly. */
|
1995-09-02 06:25:08 +08:00
|
|
|
|
#define link_warning(symbol, msg)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* A canned warning for sysdeps/stub functions. */
|
|
|
|
|
#define stub_warning(name) \
|
1995-09-02 06:25:08 +08:00
|
|
|
|
link_warning (name, \
|
|
|
|
|
"warning: " #name " is not implemented and will always fail")
|
1995-02-20 09:08:14 +08:00
|
|
|
|
|
|
|
|
|
/*
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
1995-02-20 09:08:14 +08:00
|
|
|
|
*/
|
|
|
|
|
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#ifdef HAVE_GNU_LD
|
|
|
|
|
|
|
|
|
|
/* Symbol set support macros. */
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_ELF
|
|
|
|
|
|
|
|
|
|
/* Make SYMBOL, which is in the text segment, an element of SET. */
|
|
|
|
|
#define text_set_element(set, symbol) _elf_set_element(set, symbol)
|
|
|
|
|
/* Make SYMBOL, which is in the data segment, an element of SET. */
|
|
|
|
|
#define data_set_element(set, symbol) _elf_set_element(set, symbol)
|
|
|
|
|
/* Make SYMBOL, which is in the bss segment, an element of SET. */
|
|
|
|
|
#define bss_set_element(set, symbol) _elf_set_element(set, symbol)
|
|
|
|
|
|
|
|
|
|
/* These are all done the same way in ELF.
|
|
|
|
|
There is a new section created for each set. */
|
1995-04-12 09:03:38 +08:00
|
|
|
|
#ifdef PIC
|
|
|
|
|
/* When building a shared library, make the set section writable,
|
|
|
|
|
because it will need to be relocated at run time anyway. */
|
|
|
|
|
#define _elf_set_element(set, symbol) \
|
|
|
|
|
static const void *__elf_set_##set##_element_##symbol##__ \
|
1995-06-15 01:15:57 +08:00
|
|
|
|
__attribute__ ((unused, section (#set))) = &(symbol)
|
1995-04-12 09:03:38 +08:00
|
|
|
|
#else
|
1995-02-18 09:27:10 +08:00
|
|
|
|
#define _elf_set_element(set, symbol) \
|
|
|
|
|
static const void *const __elf_set_##set##_element_##symbol##__ \
|
1995-06-15 01:15:57 +08:00
|
|
|
|
__attribute__ ((unused, section (#set))) = &(symbol)
|
1995-04-12 09:03:38 +08:00
|
|
|
|
#endif
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
|
|
|
|
/* Define SET as a symbol set. This may be required (it is in a.out) to
|
|
|
|
|
be able to use the set's contents. */
|
|
|
|
|
#define symbol_set_define(set) symbol_set_declare(set)
|
|
|
|
|
|
|
|
|
|
/* Declare SET for use in this module, if defined in another module. */
|
|
|
|
|
#define symbol_set_declare(set) \
|
1995-11-16 08:44:18 +08:00
|
|
|
|
extern void *const __start_##set __attribute__ ((__weak__)); \
|
|
|
|
|
extern void *const __stop_##set __attribute__ ((__weak__)); \
|
|
|
|
|
/* Gratuitously repeat weak decl, in case using broken GCC (<2.8). */\
|
|
|
|
|
weak_symbol (__start_##set) weak_symbol (__stop_##set)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
|
|
|
|
/* Return a pointer (void *const *) to the first element of SET. */
|
|
|
|
|
#define symbol_set_first_element(set) (&__start_##set)
|
|
|
|
|
|
|
|
|
|
/* Return true iff PTR (a void *const *) has been incremented
|
|
|
|
|
past the last element in SET. */
|
|
|
|
|
#define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
|
|
|
|
|
|
|
|
|
|
#else /* Not ELF: a.out. */
|
|
|
|
|
|
|
|
|
|
#define text_set_element(set, symbol) \
|
|
|
|
|
asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
|
|
|
|
|
#define data_set_element(set, symbol) \
|
|
|
|
|
asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
|
|
|
|
|
#define bss_set_element(set, symbol) ?error Must use initialized data.
|
|
|
|
|
#define symbol_set_define(set) void *const (set)[1];
|
|
|
|
|
#define symbol_set_declare(set) extern void *const (set)[1];
|
|
|
|
|
|
|
|
|
|
#define symbol_set_first_element(set) &(set)[1]
|
|
|
|
|
#define symbol_set_end_p(set, ptr) (*(ptr) == 0)
|
|
|
|
|
|
|
|
|
|
#endif /* ELF. */
|
|
|
|
|
#endif /* Have GNU ld. */
|
|
|
|
|
|
|
|
|
|
#endif /* libc-symbols.h */
|