This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: strong aliases for data do not work properly in shared libs
- From: Mike Frysinger <vapier at gentoo dot org>
- To: libc-alpha at sourceware dot org
- Date: Thu, 13 Apr 2006 12:00:04 -0400
- Subject: Re: strong aliases for data do not work properly in shared libs
- Geoman: IS A RETARD
- References: <200604131129.46260.vapier@gentoo.org>
On Thursday 13 April 2006 11:29, Mike Frysinger wrote:
> the attached testcases shows the issue pretty clearly
sent that e-mail prematurely ... testcase attached
the difference in func addresses is expected as each address refers to a
unique PLT entry and both PLT entries refer back to the proper symbol
what i'm looking at here is the FAIL in prog-dynamic-lib with strong data
-mike
#define asm_strong_alias(name, aliasname) \
asm(".data;.globl " #aliasname ";.set " #aliasname "," #name ";.previous;");
#define asm_weak_alias(name, aliasname) \
asm(".data;.weak " #aliasname ";" #aliasname " = " #name ";.previous;");
#define gcc_strong_alias(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((alias (#name)));
#define gcc_weak_alias(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
#undef USE_ASM
#ifdef USE_ASM
# define strong_alias(name, aliasname) asm_strong_alias(name, aliasname)
# define weak_alias(name, aliasname) asm_weak_alias(name, aliasname)
#else
# define strong_alias(name, aliasname) gcc_strong_alias(name, aliasname)
# define weak_alias(name, aliasname) gcc_weak_alias(name, aliasname)
#endif
int strong_data = 0;
strong_alias(strong_data, strong_data_alias)
int weak_data = 0;
weak_alias(weak_data, weak_data_alias)
int strong_func(void) { return 123; }
strong_alias(strong_func, strong_func_alias)
int weak_func(void) { return 321; }
weak_alias(weak_func, weak_func_alias)
CFLAGS = -g -Wall -O0
STA_LDFLAGS = $(LDFLAGS) -static
DYN_LDFLAGS = $(LDFLAGS) -Wl,-rpath,. -L. -lsyms
LIB_LDFLAGS = $(LDFLAGS) -shared
all: run
%.os: %.c
$(CC) $(CFLAGS) -fPIC -c $^ -o $@
libsyms.so: lib.os
$(CC) $(CFLAGS) $(LIB_LDFLAGS) $^ -o $@
prog-dynamic-lib: libsyms.so
prog-dynamic-lib: main.o
$(CC) $(CFLAGS) $(DYN_LDFLAGS) $^ -o $@
prog-dynamic: main.o lib.o
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
prog-static: main.o lib.o
$(CC) $(CFLAGS) $(STA_LDFLAGS) $^ -o $@
run: prog-dynamic-lib prog-dynamic prog-static libsyms.so
@echo ""
@echo "Running dynamic program (w/lib):"
-./prog-dynamic-lib
@echo ""
@echo "Running dynamic program:"
-./prog-dynamic
@echo ""
@echo "Running static program:"
-./prog-static
@echo ""
clean:
rm -f prog-static prog-dynamic prog-dynamic-lib *.os *.o *.so
#include <stdio.h>
extern int strong_data, strong_data_alias;
extern int weak_data, weak_data_alias;
extern int strong_func(void);
extern int strong_func_alias(void);
extern int weak_func(void);
extern int weak_func_alias(void);
#define OP(x) (x ? "==" : "!=")
#define RES(x) (x ? "PASS" : "FAIL")
int check_data(const char *sym_type, int *sym, int *alias)
{
*sym = 1;
*alias = 2;
printf("%8s data address: %s (%p %s %p)\n", sym_type,
RES(sym == alias), sym, OP(sym == alias), alias);
printf("%8s data value : %s (%i %s %i)\n", sym_type,
RES(*sym == *alias), *sym, OP(*sym == *alias), *alias);
return ((sym == alias && *sym == *alias) ? 0 : 1);
}
int check_func(const char *sym_type, int (*sym)(void), int (*alias)(void))
{
printf("%8s func address: %s (%p %s %p)\n", sym_type,
RES(sym == alias), sym, OP(sym == alias), alias);
printf("%8s func value : %s (%i %s %i)\n", sym_type,
RES(sym() == alias()), sym(), OP(sym() == alias()), alias());
return ((sym == alias && sym() == alias()) ? 0 : 1);
}
int main(void)
{
return
check_data("strong", &strong_data, &strong_data_alias) +
check_data("weak", &weak_data, &weak_data_alias) +
check_func("strong", &strong_func, &strong_func_alias) +
check_func("weak", &weak_func, &weak_func_alias);
}