as: handle .type <sym>,@object

This commit is contained in:
Mikael Pettersson
2023-10-13 20:27:30 +02:00
parent 1455bfc2e2
commit 3ff0f8f203
3 changed files with 23 additions and 13 deletions

View File

@@ -560,7 +560,12 @@ dot_size(Location, Tunit, #s_dot_size{name = Name}) ->
fmterr(Location, "symbol ~s not defined", [Name])
end.
dot_type(Location, Tunit, #s_dot_type{name = Name}) ->
dot_type(Location, Tunit, #s_dot_type{name = Name, type = Type}) ->
StType =
case Type of
function -> ?STT_FUNC;
object -> ?STT_OBJECT
end,
case tunit:get_symbol(Tunit, Name) of
false ->
Symbol =
@@ -568,19 +573,19 @@ dot_type(Location, Tunit, #s_dot_type{name = Name}) ->
, section = false
, st_value = false
, st_size = false
, st_info = ?ELF_ST_INFO(?STB_LOCAL, ?STT_FUNC)
, st_info = ?ELF_ST_INFO(?STB_LOCAL, StType)
, st_name = 0
, st_shndx = 0
},
{ok, tunit:put_symbol(Tunit, Symbol)};
#symbol{st_info = StInfo} = OldSymbol ->
case ?ELF_ST_TYPE(StInfo) of
?STT_FUNC -> {ok, Tunit};
StType -> {ok, Tunit};
?STT_NOTYPE ->
Symbol = OldSymbol#symbol{st_info = ?ELF_ST_INFO(?ELF_ST_BIND(StInfo), ?STT_FUNC)},
Symbol = OldSymbol#symbol{st_info = ?ELF_ST_INFO(?ELF_ST_BIND(StInfo), StType)},
{ok, tunit:put_symbol(Tunit, Symbol)};
Type ->
fmterr(Location, "symbol ~s has previous incompatible type ~p", [Name, Type])
Other ->
fmterr(Location, "symbol ~s has previous incompatible type ~p", [Name, Other])
end
end.

View File

@@ -413,7 +413,7 @@ dot_text(ScanState, Location) ->
ScanRes -> badtok("junk after .text", ScanRes)
end.
%% For now only accepts ".type <sym>,@function". TODO: extend
%% For now only accepts ".type <sym>,(@function|@object)". TODO: extend
dot_type(ScanState, Location) ->
case scan:token(ScanState) of
{ok, {_Location1, {?T_SYMBOL, Name}}} ->
@@ -423,10 +423,9 @@ dot_type(ScanState, Location) ->
{ok, {_Location3, ?T_AT}} ->
case scan:token(ScanState) of
{ok, {_Location4, {?T_SYMBOL, "function"}}} ->
case scan:token(ScanState) of
{ok, {_Location5, ?T_NEWLINE}} -> {ok, {Location, #s_dot_type{name = Name}}};
ScanRes -> badtok("junk after .type", ScanRes)
end;
dot_type(ScanState, Location, Name, function);
{ok, {_Location4, {?T_SYMBOL, "object"}}} ->
dot_type(ScanState, Location, Name, object);
ScanRes -> badtok("junk after .type", ScanRes)
end;
ScanRes -> badtok("junk after .type", ScanRes)
@@ -436,6 +435,12 @@ dot_type(ScanState, Location) ->
ScanRes -> badtok("junk after .type", ScanRes)
end.
dot_type(ScanState, Location, Name, Type) ->
case scan:token(ScanState) of
{ok, {_Location5, ?T_NEWLINE}} -> {ok, {Location, #s_dot_type{name = Name, type = Type}}};
ScanRes -> badtok("junk after .type", ScanRes)
end.
dot_word(ScanState, Location) ->
dot_long(ScanState, Location).

View File

@@ -90,8 +90,8 @@
%% .text [nr]
-record(s_dot_text, {nr :: non_neg_integer()}).
%% .type foo,@function (TODO: extend)
-record(s_dot_type, {name :: string()}).
%% .type foo,(@function|@object) (TODO: extend)
-record(s_dot_type, {name :: string(), type :: function | object}).
%% .2byte [expr (, expr)*]
-record(s_dot_2byte, {exprs :: [expr()]}).