mirror of
https://github.com/frida/tinycc
synced 2024-12-24 22:16:49 +03:00
weak function symbols
This commit is contained in:
parent
d63ec6f20d
commit
95b9a477b6
11
examples/ex_weak.c
Executable file
11
examples/ex_weak.c
Executable 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();
|
||||
}
|
||||
}
|
6
examples/weak_f.c
Normal file
6
examples/weak_f.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include <tcclib.h>
|
||||
|
||||
void weak_f (void)
|
||||
{
|
||||
printf("Weak\n");
|
||||
}
|
8
libtcc.c
8
libtcc.c
@ -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
4
tcc.h
@ -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))
|
||||
|
||||
|
4
tccgen.c
4
tccgen.c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user