This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
PATCH: Undefined weak symbol bug
- From: "H. J. Lu" <hjl at lucon dot org>
- To: GNU C Library <libc-alpha at sources dot redhat dot com>
- Date: Tue, 25 Mar 2003 16:17:16 -0800
- Subject: PATCH: Undefined weak symbol bug
- References: <20030325135350.A23805@lucon.org>
On Tue, Mar 25, 2003 at 01:53:50PM -0800, H. J. Lu wrote:
> We don't handle undefined weak symbol with non-default visibility
> right:
>
> # make
> cc -O -g -c main.c
> cc -shared -o libfoo.so -O -g shared.c
> cc -o foo -O -g main.o libfoo.so -Wl,-rpath,.
> for f in foo; do echo "Running: $f"; ./$f; \
> if [ $? != 0 ]; then echo Failed; fi; done
> Running: foo
> 0x80496c4
> 0x80495b4
> Failed
>
Here is the patch. We can also do this in _dl_lookup_versioned_symbol
and _dl_lookup_symbol as an alternative. According to gABI, the
undefined symbols with non-default visibility have to be weak. Checking
for STB_WEAK can be skipped. I can submit the alternative if it is
preferred.
BTW, even with this patch, the test will still fail since the current
linker doesn't handle it right.
H.J.
---
2003-03-25 H.J. Lu <hjl at gnu dot org>
* dl-reloc.c (RESOLVE_MAP): Handle undefined symbol with
non-default visibility.
(RESOLVE): Likewise.
--- elf/dl-reloc.c.weak 2003-03-03 09:33:35.000000000 -0800
+++ elf/dl-reloc.c 2003-03-25 15:37:56.000000000 -0800
@@ -154,7 +154,10 @@ _dl_relocate_object (struct link_map *l,
/* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code. */
#define RESOLVE_MAP(ref, version, r_type) \
(ELFW(ST_BIND) ((*ref)->st_info) != STB_LOCAL \
- ? ((__builtin_expect ((*ref) == l->l_lookup_cache.sym, 0) \
+ ? ((__builtin_expect (ELFW(ST_VISIBILITY) ((*ref)->st_other), 0) \
+ && (*ref)->st_shndx == SHN_UNDEF) \
+ ? (*ref = NULL, 0) \
+ : ((__builtin_expect ((*ref) == l->l_lookup_cache.sym, 0) \
&& elf_machine_type_class (r_type) == l->l_lookup_cache.type_class) \
? (bump_num_cache_relocations (), \
(*ref) = l->l_lookup_cache.ret, \
@@ -172,13 +175,16 @@ _dl_relocate_object (struct link_map *l,
(ref), scope, _tc, \
DL_LOOKUP_ADD_DEPENDENCY)); \
l->l_lookup_cache.ret = (*ref); \
- l->l_lookup_cache.value = _lr; })) \
+ l->l_lookup_cache.value = _lr; }))) \
: l)
#define RESOLVE(ref, version, r_type) \
(ELFW(ST_BIND) ((*ref)->st_info) != STB_LOCAL \
- ? ((__builtin_expect ((*ref) == l->l_lookup_cache.sym, 0) \
+ ? ((__builtin_expect (ELFW(ST_VISIBILITY) ((*ref)->st_other), 0) \
+ && (*ref)->st_shndx == SHN_UNDEF) \
+ ? (*ref = NULL, 0) \
+ : ((__builtin_expect ((*ref) == l->l_lookup_cache.sym, 0) \
&& elf_machine_type_class (r_type) == l->l_lookup_cache.type_class) \
- ? (bump_num_cache_relocations (), \
+ ? (bump_num_cache_relocations (), \
(*ref) = l->l_lookup_cache.ret, \
l->l_lookup_cache.value) \
: ({ lookup_t _lr; \
@@ -194,7 +200,7 @@ _dl_relocate_object (struct link_map *l,
(ref), scope, _tc, \
DL_LOOKUP_ADD_DEPENDENCY)); \
l->l_lookup_cache.ret = (*ref); \
- l->l_lookup_cache.value = _lr; })) \
+ l->l_lookup_cache.value = _lr; }))) \
: l->l_addr)
/* This macro is used as a callback from elf_machine_rel{a,} when a