diff options
author | Roland McGrath <roland@gnu.org> | 1996-07-08 06:18:25 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1996-07-08 06:18:25 +0000 |
commit | af5b3bc33bbaf9151c34a351bdb257b90d407d5b (patch) | |
tree | 7a9d35a2cea2549dad8c3c9276208962732e4954 | |
parent | 0676b5fdca8d4f2a8dd442db4d50dc2c1ee8729f (diff) | |
download | glibc-af5b3bc33bbaf9151c34a351bdb257b90d407d5b.zip glibc-af5b3bc33bbaf9151c34a351bdb257b90d407d5b.tar.gz glibc-af5b3bc33bbaf9151c34a351bdb257b90d407d5b.tar.bz2 |
Mon Jul 8 02:14:25 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>cvs/libc-960708
* libc-symbols.h [GCC >= 2.7] (strong_alias, weak_alias): Use extern
storage class. GCC gives an error for non-extern data defns with the
alias attribute.
Mon Jul 8 00:11:15 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* libc-symbols.h (weak_function): New macro.
For GCC 2.7+ define as __attribute__ ((weak)).
* elf/dl-minimal.c: Use weak_function as keyword in function defns
instead of weak_symbol (NAME) after the defn.
* stdlib/strtol.c: Likewise.
* sysdeps/mach/hurd/dl-sysdep.c: Likewise.
* sysdeps/alpha/dl-machine.h (elf_machine_rela) [RTLD_BOOTSTRAP]:
If this is defined, don't declare _dl_rtld_map as weak, and
don't check for MAP pointing to it. RESOLVE is always null in this
case, so test with #ifdef instead of if.
* libc-symbols.h (symbol_set_declare): Use weak_extern instead of
weak_symbol.
* csu/initfini.c (_init): Likewise.
* locale/setlocale.c (DEFINE_CATEGORY): Likewise.
* misc/efgcvt_r.c: Likewise.
* sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/i386/dl-machine.h (elf_machine_rel): Likewise.
* libc-symbols.h [ASSEMBLER] (weak_symbol): Macro removed.
It was not used in any assembler code.
(weak_symbol_asm): Renamed to weak_extern_asm.
(weak_extern): New macro replaces weak_symbol for weak extern refs;
define to weak_extern_asm for [!ASSEMBLER].
* libc-symbols.h [! ASSEMBLER] [HAVE_WEAK_SYMBOLS] (weak_symbol_asm,
weak_alias_asm): New macros, renamed from weak_symbol/weak_alias;
define those now as aliases.
Change conditional to use __attribute__ syntax for GCC 2.7+, not 2.8+
[GCC >= 2.7] [HAVE_WEAK_SYMBOLS] (weak_symbol): Do weak_symbol_asm
after GCC weak attribute decl.
-rw-r--r-- | ChangeLog | 42 | ||||
-rw-r--r-- | elf/dl-minimal.c | 26 | ||||
-rw-r--r-- | libc-symbols.h | 54 | ||||
-rw-r--r-- | stdlib/strtol.c | 10 | ||||
-rw-r--r-- | sysdeps/alpha/dl-machine.h | 39 | ||||
-rw-r--r-- | sysdeps/mach/hurd/dl-sysdep.c | 16 |
6 files changed, 116 insertions, 71 deletions
@@ -1,10 +1,51 @@ +Mon Jul 8 02:14:25 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu> + + * libc-symbols.h [GCC >= 2.7] (strong_alias, weak_alias): Use extern + storage class. GCC gives an error for non-extern data defns with the + alias attribute. + Mon Jul 8 01:37:34 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> * string/argz-insert.c (__argz_insert): (__argz_insert): Use memmove instead of memcpy for possible overlapping strings. +Mon Jul 8 00:11:15 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu> + + * libc-symbols.h (weak_function): New macro. + For GCC 2.7+ define as __attribute__ ((weak)). + * elf/dl-minimal.c: Use weak_function as keyword in function defns + instead of weak_symbol (NAME) after the defn. + * stdlib/strtol.c: Likewise. + * sysdeps/mach/hurd/dl-sysdep.c: Likewise. + + * sysdeps/alpha/dl-machine.h (elf_machine_rela) [RTLD_BOOTSTRAP]: + If this is defined, don't declare _dl_rtld_map as weak, and + don't check for MAP pointing to it. RESOLVE is always null in this + case, so test with #ifdef instead of if. + + * libc-symbols.h (symbol_set_declare): Use weak_extern instead of + weak_symbol. + * csu/initfini.c (_init): Likewise. + * locale/setlocale.c (DEFINE_CATEGORY): Likewise. + * misc/efgcvt_r.c: Likewise. + * sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise. + * sysdeps/i386/dl-machine.h (elf_machine_rel): Likewise. + + * libc-symbols.h [ASSEMBLER] (weak_symbol): Macro removed. + It was not used in any assembler code. + (weak_symbol_asm): Renamed to weak_extern_asm. + (weak_extern): New macro replaces weak_symbol for weak extern refs; + define to weak_extern_asm for [!ASSEMBLER]. + Sun Jul 7 18:42:06 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu> + * libc-symbols.h [! ASSEMBLER] [HAVE_WEAK_SYMBOLS] (weak_symbol_asm, + weak_alias_asm): New macros, renamed from weak_symbol/weak_alias; + define those now as aliases. + Change conditional to use __attribute__ syntax for GCC 2.7+, not 2.8+ + [GCC >= 2.7] [HAVE_WEAK_SYMBOLS] (weak_symbol): Do weak_symbol_asm + after GCC weak attribute decl. + * sysdeps/gnu/errlist.awk (BEGIN): Initialize associative array ALIAS, map EWOULDBLOCK->EAGAIN, EDEADLOCK->EDEADLK. (element printer): Check for elt in ALIAS, instead of special case @@ -34,7 +75,6 @@ Fri May 31 11:48:46 1996 Miles Bader <miles@gnu.ai.mit.edu> (line_wrap_set_lmargin, line_wrap_set_rmargin, line_wrap_set_wmargin, line_wrap_point): Use __line_wrap_update. - * stdio/linewrap.h (struct line_wrap_data): Rename POINT field to POINT_COL. Add POINT_OFFS field. (__line_wrap_update): New decl. diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index bf19fee..fd7bf05 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -30,7 +30,7 @@ Cambridge, MA 02139, USA. */ static void *alloc_ptr, *alloc_end, *alloc_last_block; -void * +void * weak_function malloc (size_t n) { extern int _dl_zerofd; @@ -71,20 +71,18 @@ malloc (size_t n) alloc_ptr += n; return alloc_last_block; } -weak_symbol (malloc) /* This will rarely be called. */ -void +void weak_function free (void *ptr) { /* We can free only the last block allocated. */ if (ptr == alloc_last_block) alloc_ptr = alloc_last_block; } -weak_symbol (free) /* This is only called with the most recent block returned by malloc. */ -void * +void * weak_function realloc (void *ptr, size_t n) { void *new; @@ -94,31 +92,27 @@ realloc (void *ptr, size_t n) assert (new == ptr); return new; } -weak_symbol (realloc) /* Avoid signal frobnication in setjmp/longjmp. Keeps things smaller. */ #include <setjmp.h> -int __sigjmp_save (sigjmp_buf env, int savemask) +int weak_function +__sigjmp_save (sigjmp_buf env, int savemask) { env[0].__mask_was_saved = savemask; return 0; } -weak_symbol (__sigjmp_save) -void +void weak_function longjmp (jmp_buf env, int val) { __longjmp (env[0].__jmpbuf, val); } -weak_symbol (longjmp) - /* Define our own stub for the localization function used by strerror. English-only in the dynamic linker keeps it smaller. */ -char * +char * weak_function __dgettext (const char *domainname, const char *msgid) { assert (domainname == _libc_intl_domainname); return (char *) msgid; } -weak_symbol (__dgettext) weak_alias (__dgettext, dgettext) #ifndef NDEBUG @@ -127,7 +121,7 @@ weak_alias (__dgettext, dgettext) If we are linked into the user program (-ldl), the normal __assert_fail defn can override this one. */ -void +void weak_function __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function) { @@ -140,9 +134,8 @@ __assert_fail (const char *assertion, NULL); } -weak_symbol (__assert_fail) -void +void weak_function __assert_perror_fail (int errnum, const char *file, unsigned int line, const char *function) @@ -155,6 +148,5 @@ __assert_perror_fail (int errnum, "Unexpected error: ", strerror (errnum), "\n", NULL); } -weak_symbol (__assert_perror_fail) #endif diff --git a/libc-symbols.h b/libc-symbols.h index aaf9f2a..2f72d5f 100644 --- a/libc-symbols.h +++ b/libc-symbols.h @@ -143,8 +143,9 @@ extern const char _libc_intl_domainname[]; #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) +/* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */ +#define weak_extern(symbol) \ + .weakext C_SYMBOL_NAME (symbol) #else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ @@ -154,49 +155,65 @@ extern const char _libc_intl_domainname[]; .weak C_SYMBOL_NAME (alias); \ C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) -/* Declare SYMBOL to be weak. */ -#define weak_symbol(symbol) .weak C_SYMBOL_NAME (symbol) + +/* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */ +#define weak_extern(symbol) \ + .weak C_SYMBOL_NAME (symbol) #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) \ +#define weak_extern_asm(symbol) asm (".weakext " __SYMBOL_PREFIX #symbol); +#define weak_alias_asm(original, alias) \ asm (".weakext " __SYMBOL_PREFIX #alias ", " __SYMBOL_PREFIX #original); #else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ -#define weak_symbol(symbol) asm (".weak " __SYMBOL_PREFIX #symbol); -#define weak_alias(original, alias) \ +#define weak_extern_asm(symbol) asm (".weak " __SYMBOL_PREFIX #symbol); +#define weak_alias_asm(original, alias) \ asm (".weak " __SYMBOL_PREFIX #alias "\n" \ __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original); #endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ + +#define weak_alias(o, a) weak_alias_asm (o, a) +#define weak_extern(symbol) weak_extern_asm (symbol) + #endif /* ! ASSEMBLER */ #else #define weak_alias(original, alias) strong_alias(original, alias) -#define weak_symbol(symbol) /* Do nothing. */ +#define weak_extern(symbol) /* Do nothing; the ref will be strong. */ #endif #if (!defined (ASSEMBLER) && \ - (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))) -/* GCC 2.8 and later has special syntax for weak symbols and aliases. + (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))) +/* GCC 2.7 and later has special syntax for weak symbols and aliases. 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) \ - __typeof (name) aliasname __attribute__ ((alias (#name))); + extern __typeof (name) aliasname __attribute__ ((alias (#name))); #ifdef HAVE_WEAK_SYMBOLS -#undef weak_symbol -#define weak_symbol(name) \ - extern __typeof (name) name __attribute__ ((weak)); #undef weak_alias #define weak_alias(name, aliasname) \ - __typeof (name) aliasname __attribute__ ((weak, alias (#name))); + extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); + +/* This comes between the return type and function name in + a function definition to make that definition weak. */ +#define weak_function __attribute__ ((weak)) + #endif /* HAVE_WEAK_SYMBOLS. */ -#endif /* Not ASSEMBLER, and GCC 2.8 or later. */ +#endif /* Not ASSEMBLER, and GCC 2.7 or later. */ + +#ifndef weak_function +/* If we do not have the __attribute__ ((weak)) syntax, there is no way we + can define functions as weak symbols. The compiler will emit a `.globl' + directive for the function symbol, and a `.weak' directive in addition + will produce an error from the assembler. */ +#define weak_function /* empty */ +#endif /* When a reference to SYMBOL is encountered, the linker will emit a @@ -260,8 +277,7 @@ extern const char _libc_intl_domainname[]; #define symbol_set_declare(set) \ 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) + weak_extern (__start_##set) weak_extern (__stop_##set) /* Return a pointer (void *const *) to the first element of SET. */ #define symbol_set_first_element(set) (&__start_##set) diff --git a/stdlib/strtol.c b/stdlib/strtol.c index 3f34e39..1481d33 100644 --- a/stdlib/strtol.c +++ b/stdlib/strtol.c @@ -338,6 +338,9 @@ noconv: /* External user entry point. */ INT +#ifdef weak_function +weak_function +#endif strtol (nptr, endptr, base) const STRING_TYPE *nptr; STRING_TYPE **endptr; @@ -345,10 +348,3 @@ strtol (nptr, endptr, base) { return INTERNAL (strtol) (nptr, endptr, base, 0); } -#ifdef weak_symbol -/* We need to weaken this symbol because some the the defined - functions do not come from ANSI. The indirection is necessary - because `strtol' might be a macro. */ -#define weak_this(x) weak_symbol (x) -weak_this (strtol) -#endif diff --git a/sysdeps/alpha/dl-machine.h b/sysdeps/alpha/dl-machine.h index bfde666..8986ed7 100644 --- a/sysdeps/alpha/dl-machine.h +++ b/sysdeps/alpha/dl-machine.h @@ -161,7 +161,14 @@ elf_machine_rela (struct link_map *map, { Elf64_Addr *const reloc_addr = (void *)(map->l_addr + reloc->r_offset); unsigned long r_info = ELF64_R_TYPE (reloc->r_info); - weak_symbol (_dl_rtld_map); /* Defined in rtld.c, but not in libc.a. */ +#ifndef RTLD_BOOTSTRAP + /* This is defined in rtld.c, but nowhere in the static libc.a; make the + reference weak so static programs can still link. This declaration + cannot be done when compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP) + because rtld.c contains the common defn for _dl_rtld_map, which is + incompatible with a weak decl in the same file. */ + weak_extern (_dl_rtld_map); +#endif /* We cannot use a switch here because we cannot locate the switch jump table until we've self-relocated. */ @@ -169,38 +176,37 @@ elf_machine_rela (struct link_map *map, if (r_info == R_ALPHA_RELATIVE) { /* Already done in dynamic linker. */ - if (!resolve || map != &_dl_rtld_map) +#ifndef RTLD_BOOTSTRAP + if (map != &_dl_rtld_map) +#endif *reloc_addr += map->l_addr; } else if (r_info == R_ALPHA_NONE) - ; + return; else { Elf64_Addr loadbase, sym_value; - if (resolve) - { - loadbase = (*resolve)(&sym, (Elf64_Addr)reloc_addr, - r_info == R_ALPHA_JMP_SLOT); - } - else - loadbase = map->l_addr; - +#ifndef RTLD_BOOTSTRAP + loadbase = (*resolve)(&sym, (Elf64_Addr)reloc_addr, + r_info == R_ALPHA_JMP_SLOT); +#else + loadbase = map->l_addr; +#endif sym_value = sym ? loadbase + sym->st_value : 0; if (r_info == R_ALPHA_GLOB_DAT) - { - *reloc_addr = sym_value; - } + *reloc_addr = sym_value; else if (r_info == R_ALPHA_JMP_SLOT) { *reloc_addr = sym_value; - elf_alpha_fix_plt(map, reloc, (Elf64_Addr)reloc_addr, sym_value); + elf_alpha_fix_plt (map, reloc, (Elf64_Addr) reloc_addr, sym_value); } else if (r_info == R_ALPHA_REFQUAD) { sym_value += *reloc_addr; - if (resolve && map == &_dl_rtld_map) +#ifndef RTLD_BOOTSTRAP + if (map == &_dl_rtld_map) { /* Undo the relocation done here during bootstrapping. Now we will relocate anew, possibly using a binding @@ -213,6 +219,7 @@ elf_machine_rela (struct link_map *map, sym_value -= dlsymtab[ELF64_R_SYM(reloc->r_info)].st_value; } else +#endif sym_value += reloc->r_addend; *reloc_addr = sym_value; } diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index ec53e2f..cffc51e 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -271,7 +271,7 @@ _dl_sysdep_message (const char *msg, ...) dynamic linker re-relocates itself to be user-visible (for -ldl), it will get the user's definition (i.e. usually libc's). */ -int +int weak_function __open (const char *file_name, int mode, ...) { enum retry_type doretry; @@ -496,7 +496,7 @@ __open (const char *file_name, int mode, ...) } } -int +int weak_function __close (int fd) { if (fd != (int) MACH_PORT_NULL) @@ -504,7 +504,7 @@ __close (int fd) return 0; } -caddr_t +caddr_t weak_function __mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset) { error_t err; @@ -546,7 +546,7 @@ __mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset) return err ? (caddr_t) __hurd_fail (err) : (caddr_t) mapaddr; } -void +void weak_function _exit (int status) { __proc_mark_exit (_dl_hurd_data->portarray[INIT_PORT_PROC], @@ -554,11 +554,6 @@ _exit (int status) while (__task_terminate (__mach_task_self ())) __mach_task_self_ = (__mach_task_self) (); } - -weak_symbol (_exit) -weak_symbol (__open) -weak_symbol (__close) -weak_symbol (__mmap) /* This function is called by interruptible RPC stubs. For initial @@ -566,7 +561,7 @@ weak_symbol (__mmap) weak, the real defn in libc.so will override it if we are linked into the user program (-ldl). */ -error_t +error_t weak_function _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg, mach_msg_option_t option, mach_msg_size_t send_size, @@ -578,4 +573,3 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg, return __mach_msg (msg, option, send_size, rcv_size, rcv_name, timeout, notify); } -weak_symbol (_hurd_intr_rpc_mach_msg) |