weak function symbols

master
Manuel Simoni 2010-02-27 17:37:59 +01:00
parent d63ec6f20d
commit 95b9a477b6
6 changed files with 32 additions and 3 deletions

11
examples/ex_weak.c 100755
View File

@ -0,0 +1,11 @@
#! /usr/local/bin/tcc -run
#include <tcclib.h>
extern void weak_f (void) __attribute__ ((weak));
int main ()
{
if (weak_f) {
weak_f();
}
}

View File

@ -0,0 +1,6 @@
#include <tcclib.h>
void weak_f (void)
{
printf("Weak\n");
}

View File

@ -424,8 +424,12 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section,
if (sym->type.t & VT_STATIC)
sym_bind = STB_LOCAL;
else
sym_bind = STB_GLOBAL;
else {
if (FUNC_WEAK(sym->type.ref->r))
sym_bind = STB_WEAK;
else
sym_bind = STB_GLOBAL;
}
if (!sym->c) {
name = get_tok_str(sym->v, NULL);

4
tcc.h
View File

@ -272,7 +272,8 @@ typedef struct AttributeDef {
func_import : 1,
func_args : 5,
mode : 4,
fill : 12;
weak : 1,
fill : 11;
struct Section *section;
} AttributeDef;
@ -283,6 +284,7 @@ typedef struct AttributeDef {
#define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)
#define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)
#define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)
#define FUNC_WEAK(r) (((AttributeDef*)&(r))->weak)
#define ATTR_MODE(r) (((AttributeDef*)&(r))->mode)
#define INT_ATTR(ad) (*(int*)(ad))

View File

@ -2462,6 +2462,10 @@ static void parse_attribute(AttributeDef *ad)
case TOK_PACKED2:
ad->packed = 1;
break;
case TOK_WEAK1:
case TOK_WEAK2:
ad->weak = 1;
break;
case TOK_UNUSED1:
case TOK_UNUSED2:
/* currently, no need to handle it because tcc does not

View File

@ -93,6 +93,8 @@
DEF(TOK_ALIGNED2, "__aligned__")
DEF(TOK_PACKED1, "packed")
DEF(TOK_PACKED2, "__packed__")
DEF(TOK_WEAK1, "weak")
DEF(TOK_WEAK2, "__weak__")
DEF(TOK_UNUSED1, "unused")
DEF(TOK_UNUSED2, "__unused__")
DEF(TOK_CDECL1, "cdecl")