* emit a weak symbol for the exception tag, since that's what the LLVM linker

wants to treat them as shared between .o files
This commit is contained in:
Nikolay Nikolov 2021-09-28 02:52:40 +03:00
parent f701d2f294
commit cdf1ceca76
7 changed files with 23 additions and 6 deletions

View File

@ -47,7 +47,8 @@ interface
AB_TEMP,
{ a global symbol that points to another global symbol and is only used
to allow indirect loading in case of packages and indirect imports }
AB_INDIRECT,AB_EXTERNAL_INDIRECT);
AB_INDIRECT,AB_EXTERNAL_INDIRECT,
AB_WEAK);
TAsmsymtype=(
AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL,
@ -89,7 +90,7 @@ interface
asmlabeltypeprefix : array[TAsmLabeltype] of string[2] = ('j','a','d','l','f','t','c','eb','ee');
asmsymbindname : array[TAsmsymbind] of string[23] = ('none', 'external','common',
'local','global','weak external','private external','lazy','import','internal temp',
'indirect','external indirect');
'indirect','external indirect','weak');
asmsymbindindirect = [AB_INDIRECT,AB_EXTERNAL_INDIRECT];
type

View File

@ -607,6 +607,7 @@ interface
has_value : boolean;
constructor Create(_sym:tasmsymbol;siz:longint);
constructor Create_Global(_sym:tasmsymbol;siz:longint);
constructor Create_Weak(_sym:tasmsymbol;siz:longint);
constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
constructor Createname_hidden(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
@ -1449,6 +1450,19 @@ implementation
end;
constructor tai_symbol.Create_Weak(_sym:tasmsymbol;siz:longint);
begin
inherited Create;
typ:=ait_symbol;
sym:=_sym;
size:=siz;
if not(sym.bind in [AB_NONE,AB_WEAK_EXTERNAL]) then
internalerror(2021092801);
sym.bind:=AB_WEAK;
is_global:=false;
end;
constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
begin
inherited Create;

View File

@ -842,7 +842,7 @@ implementation
procedure TObjSymbol.SetAddress(apass:byte;aobjsec:TObjSection;abind:TAsmsymbind;atyp:Tasmsymtype);
begin
if not(abind in [AB_GLOBAL,AB_PRIVATE_EXTERN,AB_LOCAL,AB_COMMON,AB_IMPORT]) then
if not(abind in [AB_GLOBAL,AB_PRIVATE_EXTERN,AB_LOCAL,AB_COMMON,AB_IMPORT,AB_WEAK]) then
internalerror(200603016);
if not assigned(aobjsec) then
internalerror(200603017);

View File

@ -1497,6 +1497,8 @@ implementation
WriteUleb(FWasmSymbolTable,WASM_SYM_BINDING_LOCAL)
else if objsym.bind=AB_EXTERNAL then
WriteUleb(FWasmSymbolTable,WASM_SYM_UNDEFINED)
else if objsym.bind=AB_WEAK then
WriteUleb(FWasmSymbolTable,WASM_SYM_BINDING_WEAK)
else
internalerror(2021092715);
WriteUleb(FWasmSymbolTable,objsym.TagIndex);

View File

@ -691,7 +691,7 @@ implementation
hlcg.g_exception_reason_save_const(current_asmdata.CurrAsmList,exceptionreasontype,0,excepttemps.reasonbuf);
current_asmdata.CurrAsmList.concat(taicpu.op_const(a_br,4)); // jump to the 'finally' section
current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.RefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
thlcgwasm(hlcg).decblock;
{ exceptionreason:=1 (exception) }
hlcg.g_exception_reason_save_const(current_asmdata.CurrAsmList,exceptionreasontype,1,excepttemps.reasonbuf);

View File

@ -159,7 +159,7 @@ implementation
procedure twasminlinenode.second_throw_fpcexception;
begin
location_reset(location,LOC_VOID,OS_NO);
current_asmdata.CurrAsmList.Concat(taicpu.op_sym(a_throw,current_asmdata.RefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
current_asmdata.CurrAsmList.Concat(taicpu.op_sym(a_throw,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
end;

View File

@ -74,7 +74,7 @@ implementation
if ts_wasm_native_exceptions in current_settings.targetswitches then
begin
list.Concat(tai_tagtype.create(FPC_EXCEPTION_TAG_SYM, []));
list.Concat(tai_symbol.Create(current_asmdata.DefineAsmSymbol(FPC_EXCEPTION_TAG_SYM,AB_LOCAL,AT_WASM_EXCEPTION_TAG,nil),0));
list.Concat(tai_symbol.Create_Weak(current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG),0));
end;
for i:=0 to current_module.deflist.Count-1 do