as: add ".type <symbol>,@function" support

This commit is contained in:
Mikael Pettersson
2014-04-10 18:41:25 +00:00
parent aedc489357
commit 18fa204fad
3 changed files with 51 additions and 1 deletions

View File

@@ -90,6 +90,25 @@ static int do_dot_text(struct scan_state *scan_state, struct tunit *tunit, struc
return 0;
}
static int do_dot_type_function(struct scan_state *scan_state, struct tunit *tunit, struct stmt *stmt)
{
struct symbol *symbol;
symbol = tunit_symbol_enter(tunit, stmt->u.symbol.name);
if (!symbol)
return -1;
if (ELF_ST_TYPE(symbol->st_info) != STT_NOTYPE) {
fprintf(stderr, "%s: %s line %u: symbol %s already has non-zero type %u\n",
scan_state->progname, scan_state->filename, scan_state->linenr, stmt->u.symbol.name, ELF_ST_TYPE(symbol->st_info));
return -1;
}
symbol->st_info = ELF_ST_INFO(ELF_ST_BIND(symbol->st_info), STT_FUNC);
return 0;
}
static int do_label(struct scan_state *scan_state, struct tunit *tunit, struct stmt *stmt)
{
struct symbol *symbol;
@@ -135,6 +154,8 @@ static int interpret(struct scan_state *scan_state, struct tunit *tunit, struct
return do_dot_globl(scan_state, tunit, stmt);
case S_DOT_TEXT:
return do_dot_text(scan_state, tunit, stmt);
case S_DOT_TYPE_FUNCTION:
return do_dot_type_function(scan_state, tunit, stmt);
case S_LABEL:
return do_label(scan_state, tunit, stmt);
case S_INSN:

View File

@@ -66,6 +66,33 @@ static int parse_dot_text(struct scan_state *scan_state, struct stmt *stmt)
return error(scan_state, "junk after .text directive", token, &token_attr);
}
static int parse_dot_type(struct scan_state *scan_state, struct stmt *stmt)
{
enum token token;
union token_attribute token_attr;
token = scan_token(scan_state, &token_attr);
if (token == T_SYMBOL) {
stmt->u.symbol.name = token_attr.text;
token = scan_token(scan_state, &token_attr);
if (token == T_COMMA) {
token = scan_token(scan_state, &token_attr);
if (token == T_AT) {
token = scan_token(scan_state, &token_attr);
if (token == T_SYMBOL
&& strcmp(token_attr.text, "function") == 0) {
token = scan_token(scan_state, &token_attr);
if (token == T_NEWLINE) {
stmt->tag = S_DOT_TYPE_FUNCTION;
return 1;
}
}
}
}
}
return error(scan_state, "junk after .type directive", token, &token_attr);
}
/*
* Recognize:
*
@@ -353,6 +380,8 @@ int parse_stmt(struct scan_state *scan_state, struct stmt *stmt)
return parse_dot_globl(scan_state, stmt);
case T_DOT_TEXT:
return parse_dot_text(scan_state, stmt);
case T_DOT_TYPE:
return parse_dot_type(scan_state, stmt);
/*
* other symbols
*/

View File

@@ -8,6 +8,7 @@
TOKEN(T_DOT_FILE, ".file", TAFMT_NONE)
TOKEN(T_DOT_GLOBL, ".globl", TAFMT_NONE)
TOKEN(T_DOT_TEXT, ".text", TAFMT_NONE)
TOKEN(T_DOT_TYPE, ".type", TAFMT_NONE)
/* non-reserved symbols; T_SYMBOL MUST be the first token after the list of reserved symbols */
TOKEN(T_SYMBOL, "<symbol>", TAFMT_SYMBOL)
/* literals */
@@ -52,7 +53,6 @@ TOKEN(T_DOT_SHORT, ".short", TAFMT_NONE)
TOKEN(T_DOT_SIZE, ".size", TAFMT_NONE)
TOKEN(T_DOT_SUBSECTION, ".subsection", TAFMT_NONE)
TOKEN(T_DOT_SYMVER, ".symver", TAFMT_NONE)
TOKEN(T_DOT_TYPE, ".type", TAFMT_NONE)
TOKEN(T_DOT_WEAK, ".weak", TAFMT_NONE)
TOKEN(T_DOT_WEAKREF, ".weakref", TAFMT_NONE)
/* other symbols */