This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strong aliases for data do not work properly in shared libs

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
#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)
# define strong_alias(name, aliasname) gcc_strong_alias(name, aliasname)
# define weak_alias(name, aliasname) gcc_weak_alias(name, aliasname)

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
DYN_LDFLAGS = $(LDFLAGS) -Wl,-rpath,. -L. -lsyms

all: run

%.os: %.c
	$(CC) $(CFLAGS) -fPIC -c $^ -o $@ lib.os
	$(CC) $(CFLAGS) $(LIB_LDFLAGS) $^ -o $@

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
	@echo ""
	@echo "Running dynamic program (w/lib):"
	@echo ""
	@echo "Running dynamic program:"
	@echo ""
	@echo "Running static program:"
	@echo ""

	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)
		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);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]