From 823f83263012524b27033e908df86b592ee1a21b Mon Sep 17 00:00:00 2001 From: Joe Soroka Date: Wed, 2 Mar 2011 13:31:09 -0800 Subject: [PATCH] tcc: fix weak attribute handling --- tccgen.c | 8 ++------ tests/tcctest.c | 8 ++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tccgen.c b/tccgen.c index b84e7b6c..3ecfb099 100644 --- a/tccgen.c +++ b/tccgen.c @@ -2927,9 +2927,6 @@ static int parse_btype(CType *type, AttributeDef *ad) case TOK_ATTRIBUTE1: case TOK_ATTRIBUTE2: parse_attribute(ad); - if (ad->weak) { - t |= VT_WEAK; - } if (ad->mode) { u = ad->mode -1; t = (t & ~VT_BTYPE) | u; @@ -3189,9 +3186,6 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td) if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2) parse_attribute(ad); - if (ad->weak) - type->t |= VT_WEAK; - if (!type1.t) return; /* append type at the end of type1 */ @@ -5445,6 +5439,8 @@ ST_FUNC void decl(int l) func_decl_list(sym); } + if (ad.weak) + type.t |= VT_WEAK; #ifdef TCC_TARGET_PE if (ad.func_import) type.t |= VT_IMPORT; diff --git a/tests/tcctest.c b/tests/tcctest.c index 4c720472..5ebc7bb8 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2354,6 +2354,10 @@ extern int __attribute__((weak)) weak_v1; extern int __attribute__((weak)) weak_v2; extern int weak_v3; +extern int (*weak_fpa)() __attribute__((weak)); +extern int __attribute__((weak)) (*weak_fpb)(); +extern __attribute__((weak)) int (*weak_fpc)(); + void __attribute__((weak)) weak_test(void) { printf("weak_f1=%d\n", weak_f1 ? weak_f1() : 123); @@ -2362,6 +2366,10 @@ void __attribute__((weak)) weak_test(void) 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); + + printf("weak_fpa=%d\n",&weak_fpa ? weak_fpa() : 123); + printf("weak_fpb=%d\n",&weak_fpb ? weak_fpb() : 123); + printf("weak_fpc=%d\n",&weak_fpc ? weak_fpc() : 123); } int __attribute__((weak)) weak_f2() { return 222; }