/* Support macros for making weak and strong aliases for symbols,
and for using symbol sets and linker warnings with GNU ld.
- Copyright (C) 1995-1998,2000-2006,2008,2009,2011
+ Copyright (C) 1995-1998,2000-2006,2008,2009,2011,2012
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
#ifndef _LIBC_SYMBOLS_H
#define _LIBC_SYMBOLS_H 1
* ASM_GLOBAL_DIRECTIVE with `.globl' or `.global'.
* ASM_TYPE_DIRECTIVE_PREFIX with `@' or `#' or whatever for .type,
or leave it undefined if there is no .type directive.
- * 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'.
#include <config.h>
-/* The symbols in all the user (non-_) macros are C symbols.
- NO HAVE_ELF implies a.out. */
+/* The symbols in all the user (non-_) macros are C symbols. */
-#if defined HAVE_ASM_WEAK_DIRECTIVE || defined HAVE_ASM_WEAKEXT_DIRECTIVE
-# define HAVE_WEAK_SYMBOLS
+#if !defined HAVE_ASM_WEAK_DIRECTIVE && !defined HAVE_ASM_WEAKEXT_DIRECTIVE
+# error "weak symbol support needed"
#endif
#ifndef __SYMBOL_PREFIX
-# ifdef NO_UNDERSCORES
-# define __SYMBOL_PREFIX
-# else
-# define __SYMBOL_PREFIX "_"
-# endif
+# define __SYMBOL_PREFIX
#endif
#ifndef C_SYMBOL_NAME
-# ifdef NO_UNDERSCORES
-# define C_SYMBOL_NAME(name) name
-# else
-# define C_SYMBOL_NAME(name) _##name
-# endif
+# define C_SYMBOL_NAME(name) name
#endif
#ifndef ASM_LINE_SEP
# define weak_function __attribute__ ((weak))
# define weak_const_function __attribute__ ((weak, __const__))
-# ifdef HAVE_WEAK_SYMBOLS
-
/* Define ALIASNAME as a weak alias for NAME.
If weak aliases are not available, this defines a strong alias. */
-# define weak_alias(name, aliasname) _weak_alias (name, aliasname)
-# define _weak_alias(name, aliasname) \
+# define weak_alias(name, aliasname) _weak_alias (name, aliasname)
+# define _weak_alias(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
/* Same as WEAK_ALIAS, but mark symbol as hidden. */
-# define weak_hidden_alias(name, aliasname) \
+# define weak_hidden_alias(name, aliasname) \
_weak_hidden_alias (name, aliasname)
-# define _weak_hidden_alias(name, aliasname) \
+# define _weak_hidden_alias(name, aliasname) \
extern __typeof (name) aliasname \
__attribute__ ((weak, alias (#name), __visibility__ ("hidden")));
/* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
-# define weak_extern(symbol) _weak_extern (weak symbol)
-# define _weak_extern(expr) _Pragma (#expr)
-
-# else
+# define weak_extern(symbol) _weak_extern (weak symbol)
+# define _weak_extern(expr) _Pragma (#expr)
-# define weak_alias(name, aliasname) strong_alias(name, aliasname)
-# define weak_hidden_alias(name, aliasname) strong_alias(name, aliasname)
-# define weak_extern(symbol) /* Nothing. */
-
-# endif
#else /* __ASSEMBLER__ */
# endif
# endif
-# ifdef HAVE_WEAK_SYMBOLS
-# ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
-# ifdef HAVE_ASM_GLOBAL_DOT_NAME
-# define weak_alias(original, alias) \
+# ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
+# ifdef HAVE_ASM_GLOBAL_DOT_NAME
+# define weak_alias(original, alias) \
.weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original) ASM_LINE_SEP \
.weakext C_SYMBOL_DOT_NAME (alias), C_SYMBOL_DOT_NAME (original)
-# else
-# define weak_alias(original, alias) \
+# else
+# define weak_alias(original, alias) \
.weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
-# endif
-# define weak_extern(symbol) \
+# endif
+# define weak_extern(symbol) \
.weakext C_SYMBOL_NAME (symbol)
-# else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
+# else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
-# ifdef HAVE_ASM_GLOBAL_DOT_NAME
-# define weak_alias(original, alias) \
+# ifdef HAVE_ASM_GLOBAL_DOT_NAME
+# define weak_alias(original, alias) \
.weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP \
.weak C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP \
C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
-# else
-# define weak_alias(original, alias) \
+# else
+# define weak_alias(original, alias) \
.weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
-# endif
+# endif
-# define weak_extern(symbol) \
+# define weak_extern(symbol) \
.weak C_SYMBOL_NAME (symbol)
-# endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
-
-# else /* ! HAVE_WEAK_SYMBOLS */
-
-# define weak_alias(original, alias) strong_alias(original, alias)
-# define weak_extern(symbol) /* Nothing */
-# endif /* ! HAVE_WEAK_SYMBOLS */
+# endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
#endif /* __ASSEMBLER__ */
# define internal_function /* empty */
#endif
-/* Prepare for the case that `__builtin_expect' is not available. */
-#ifndef HAVE_BUILTIN_EXPECT
-# define __builtin_expect(expr, val) (expr)
-#endif
-
/* Determine the return address. */
#define RETURN_ADDRESS(nr) \
__builtin_extract_return_addr (__builtin_return_address (nr))
/* When a reference to SYMBOL is encountered, the linker will emit a
warning message MSG. */
-#ifdef HAVE_ELF
-
/* We want the .gnu.warning.SYMBOL section to be unallocated. */
-# ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
-# define __make_section_unallocated(section_string) \
+#ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
+# define __make_section_unallocated(section_string) \
asm (".section " section_string "\n\t.previous");
-# elif defined HAVE_ASM_POPSECTION_DIRECTIVE
-# define __make_section_unallocated(section_string) \
+#elif defined HAVE_ASM_POPSECTION_DIRECTIVE
+# define __make_section_unallocated(section_string) \
asm (".pushsection " section_string "\n\t.popsection");
-# else
-# define __make_section_unallocated(section_string)
-# endif
+#else
+# define __make_section_unallocated(section_string)
+#endif
/* Tacking on "\n\t#" to the section name makes gcc put it's bogus
section attributes on what looks like a comment to the assembler. */
-# ifdef HAVE_SECTION_QUOTES
-# define __sec_comment "\"\n\t#\""
-# else
-# define __sec_comment "\n\t#"
-# endif
-# define link_warning(symbol, msg) \
+#ifdef HAVE_SECTION_QUOTES
+# define __sec_comment "\"\n\t#\""
+#else
+# define __sec_comment "\n\t#"
+#endif
+#define link_warning(symbol, msg) \
__make_section_unallocated (".gnu.warning." #symbol) \
static const char __evoke_link_warning_##symbol[] \
__attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
= msg;
-# define libc_freeres_ptr(decl) \
+#define libc_freeres_ptr(decl) \
__make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \
decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment)))
-# define __libc_freeres_fn_section \
+#define __libc_freeres_fn_section \
__attribute__ ((section ("__libc_freeres_fn")))
-#else /* Not ELF: a.out */
-# ifdef HAVE_XCOFF
-/* XCOFF does not support .stabs.
- The native aix linker will remove the .stab and .stabstr sections
- The gnu linker will have a fatal error if there is a relocation for
- symbol in the .stab section. Silently disable this macro. */
-# define link_warning(symbol, msg)
-# else
-# define link_warning(symbol, msg) \
- asm (".stabs \"" msg "\",30,0,0,0\n\t" \
- ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
-# endif /* XCOFF */
-# define libc_freeres_ptr(decl) decl
-# define __libc_freeres_fn_section
-#endif
+
#define libc_freeres_fn(name) \
static void name (void) __attribute_used__ __libc_freeres_fn_section; \
text_set_element (__libc_subfreeres, name); \
/* 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)
+#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)
+#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)
+#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. */
-# ifdef SHARED
+#ifdef SHARED
/* 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) \
+# define _elf_set_element(set, symbol) \
static const void *__elf_set_##set##_element_##symbol##__ \
__attribute__ ((used, section (#set))) = &(symbol)
-# else
-# define _elf_set_element(set, symbol) \
+#else
+# define _elf_set_element(set, symbol) \
static const void *const __elf_set_##set##_element_##symbol##__ \
__attribute__ ((used, section (#set))) = &(symbol)
-# endif
+#endif
/* 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)
+#define symbol_set_define(set) symbol_set_declare(set)
/* Declare SET for use in this module, if defined in another module.
In a shared library, this is always local to that shared object.
For static linking, the set might be wholly absent and so we use
weak references. */
-# define symbol_set_declare(set) \
+#define symbol_set_declare(set) \
extern char const __start_##set[] __symbol_set_attribute; \
extern char const __stop_##set[] __symbol_set_attribute;
-# ifdef SHARED
-# define __symbol_set_attribute attribute_hidden
-# else
-# define __symbol_set_attribute __attribute__ ((weak))
-# endif
+#ifdef SHARED
+# define __symbol_set_attribute attribute_hidden
+#else
+# define __symbol_set_attribute __attribute__ ((weak))
+#endif
/* Return a pointer (void *const *) to the first element of SET. */
-# define symbol_set_first_element(set) ((void *const *) (&__start_##set))
+#define symbol_set_first_element(set) ((void *const *) (&__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) >= (void *const *) &__stop_##set)
-
-#else /* Not ELF: a.out. */
-
-# ifdef HAVE_XCOFF
-/* XCOFF does not support .stabs.
- The native aix linker will remove the .stab and .stabstr sections
- The gnu linker will have a fatal error if there is a relocation for
- symbol in the .stab section. Silently disable these macros. */
-# define text_set_element(set, symbol)
-# define data_set_element(set, symbol)
-# define bss_set_element(set, symbol)
-# else
-# 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.
-# endif /* XCOFF */
-# 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. */
+#define symbol_set_end_p(set, ptr) ((ptr) >= (void *const *) &__stop_##set)
#if DO_VERSIONING
# define symbol_version(real, name, version) \
# define attribute_hidden
#endif
-#ifdef HAVE_TLS_MODEL_ATTRIBUTE
-# define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
-#else
-# define attribute_tls_model_ie
-#endif
+#define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
#define attribute_relro __attribute__ ((section (".data.rel.ro")))
# define libnss_nisplus_hidden_data_ver(local, name)
#endif
-#ifdef HAVE_BUILTIN_REDIRECTION
-# define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
-# define libc_hidden_builtin_def(name) libc_hidden_def (name)
-# define libc_hidden_builtin_weak(name) libc_hidden_weak (name)
-# define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name)
-# ifdef __ASSEMBLER__
-# define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name)
-# endif
-#else
-# define libc_hidden_builtin_proto(name, attrs...)
-# define libc_hidden_builtin_def(name)
-# define libc_hidden_builtin_weak(name)
-# define libc_hidden_builtin_ver(local, name)
-# ifdef __ASSEMBLER__
-# define HIDDEN_BUILTIN_JUMPTARGET(name) JUMPTARGET(name)
-# endif
+#define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
+#define libc_hidden_builtin_def(name) libc_hidden_def (name)
+#define libc_hidden_builtin_weak(name) libc_hidden_weak (name)
+#define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name)
+#ifdef __ASSEMBLER__
+# define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name)
#endif
#if defined NOT_IN_libc && defined IS_IN_libutil