weak definitions overrule non-weak prototypes
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
TESTS = libtest test3
|
||||
|
||||
# these should work too
|
||||
# TESTS += test1 test2 speedtest btest
|
||||
# TESTS += test1 test2 speedtest btest weaktest
|
||||
|
||||
# these don't work as they should
|
||||
# TESTS += test4 asmtest
|
||||
@ -26,7 +26,7 @@ DISAS=objdump -d
|
||||
all test : $(TESTS)
|
||||
|
||||
# make sure that tcc exists
|
||||
test1 test2 test3 test4 btest speedtest asmtest : ../tcc
|
||||
test1 test2 test3 test4 btest speedtest asmtest weaktest : ../tcc
|
||||
../%:
|
||||
$(MAKE) -C .. $*
|
||||
|
||||
@ -116,6 +116,13 @@ speedtest: ex2 ex3
|
||||
time ./ex3 35
|
||||
time $(TCC) -run ../examples/ex3.c 35
|
||||
|
||||
weaktest: test.ref
|
||||
$(TCC) -c tcctest.c -o weaktest.tcc.o
|
||||
$(CC) -c tcctest.c -o weaktest.gcc.o -I. -w $(CFLAGS)
|
||||
objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
|
||||
objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
|
||||
diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
|
||||
|
||||
ex%: ../examples/ex%.c
|
||||
$(CC) -o $@ $< $(CFLAGS)
|
||||
|
||||
|
||||
@ -2231,19 +2231,25 @@ void builtin_test(void)
|
||||
}
|
||||
|
||||
|
||||
extern int __attribute__((weak)) weak_f1(void);
|
||||
extern int __attribute__((weak)) weak_f2(void);
|
||||
extern int weak_f3(void);
|
||||
extern int __attribute__((weak)) weak_v1;
|
||||
extern int __attribute__((weak)) weak_v2;
|
||||
extern int weak_v3;
|
||||
|
||||
void __attribute__((weak)) weak_test(void)
|
||||
{
|
||||
printf("weak_f1=%d\n", weak_f1 ? weak_f1() : 123);
|
||||
printf("weak_f2=%d\n", weak_f2 ? weak_f2() : 123);
|
||||
printf("weak_f3=%d\n", weak_f3 ? weak_f3() : 123);
|
||||
printf("weak_v1=%d\n",&weak_v1 ? weak_v1 : 123);
|
||||
printf("weak_v2=%d\n",&weak_v2 ? weak_v2 : 123);
|
||||
printf("weak_v3=%d\n",&weak_v3 ? weak_v3 : 123);
|
||||
}
|
||||
|
||||
int __attribute__((weak)) weak_f2() { return 222; }
|
||||
int __attribute__((weak)) weak_f3() { return 333; }
|
||||
int __attribute__((weak)) weak_v2 = 222;
|
||||
int __attribute__((weak)) weak_v3 = 333;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user