* always generate code which can be used to build dynamically loadable

libraries with

git-svn-id: trunk@2013 -
This commit is contained in:
Jonas Maebe 2005-12-20 19:58:27 +00:00
parent 06d8d7c03c
commit 66ebbbc5c2
4 changed files with 72 additions and 92 deletions

View File

@ -126,14 +126,7 @@ implementation
begin begin
symtabletype:=symtable.symtabletype; symtabletype:=symtable.symtabletype;
hregister:=NR_NO; hregister:=NR_NO;
if (target_info.system=system_powerpc_darwin) and if (vo_is_dll_var in tabstractvarsym(symtableentry).varoptions) then
([vo_is_dll_var,vo_is_external] * tabstractvarsym(symtableentry).varoptions <> []) then
begin
if not(pi_needs_got in current_procinfo.flags) then
internalerror(200403022);
generate_picvaraccess;
end
else if (vo_is_dll_var in tabstractvarsym(symtableentry).varoptions) then
{ DLL variable } { DLL variable }
begin begin
hregister:=cg.getaddressregister(exprasmlist); hregister:=cg.getaddressregister(exprasmlist);
@ -236,24 +229,14 @@ implementation
globalsymtable, globalsymtable,
staticsymtable : staticsymtable :
begin begin
if (target_info.system=system_powerpc_darwin) and if tabstractnormalvarsym(symtableentry).localloc.loc=LOC_INVALID then
(cs_create_pic in aktmoduleswitches) then reference_reset_symbol(location.reference,objectlibrary.newasmsymbol(tglobalvarsym(symtableentry).mangledname,AB_EXTERNAL,AT_DATA),0)
begin
generate_picvaraccess;
if not(pi_needs_got in current_procinfo.flags) then
internalerror(200403023);
end
else else
begin location:=tglobalvarsym(symtableentry).localloc;
if tabstractnormalvarsym(symtableentry).localloc.loc=LOC_INVALID then
reference_reset_symbol(location.reference,objectlibrary.newasmsymbol(tglobalvarsym(symtableentry).mangledname,AB_EXTERNAL,AT_DATA),0)
else
location:=tglobalvarsym(symtableentry).localloc;
{$ifdef segment_threadvars} {$ifdef segment_threadvars}
if (vo_is_thread_var in tabstractvarsym(symtableentry).varoptions) then if (vo_is_thread_var in tabstractvarsym(symtableentry).varoptions) then
location.reference.segment:=NR_GS; location.reference.segment:=NR_GS;
{$endif} {$endif}
end;
end; end;
else else
internalerror(200305102); internalerror(200305102);

View File

@ -1970,9 +1970,7 @@ implementation
staticsymtable : staticsymtable :
begin begin
{ PIC, DLL and Threadvar need extra code and are handled in ncgld } { PIC, DLL and Threadvar need extra code and are handled in ncgld }
if not((target_info.system=system_powerpc_darwin) and if not(vo_is_dll_var in varoptions) {$ifndef segment_threadvars} and
(cs_create_pic in aktmoduleswitches)) and
not(vo_is_dll_var in varoptions) {$ifndef segment_threadvars} and
not(vo_is_thread_var in varoptions) {$endif} then not(vo_is_thread_var in varoptions) {$endif} then
reference_reset_symbol(localloc.reference,objectlibrary.newasmsymbol(mangledname,AB_EXTERNAL,AT_DATA),0); reference_reset_symbol(localloc.reference,objectlibrary.newasmsymbol(mangledname,AB_EXTERNAL,AT_DATA),0);
end; end;

View File

@ -97,6 +97,9 @@ unit cgcpu;
procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel); procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
procedure g_intf_wrapper(list: TAAsmoutput; procdef: tprocdef; const labelname: string; ioffset: longint);override; procedure g_intf_wrapper(list: TAAsmoutput; procdef: tprocdef; const labelname: string; ioffset: longint);override;
function g_darwin_indirect_sym_load(list: taasmoutput; const symname: string): tregister;
private private
(* NOT IN USE: *) (* NOT IN USE: *)
@ -1802,7 +1805,7 @@ const
{ occurs, so now only ref.offset has to be loaded } { occurs, so now only ref.offset has to be loaded }
else else
a_load_const_reg(list,OS_32,ref2.offset,r) a_load_const_reg(list,OS_32,ref2.offset,r)
else if ref.index <> NR_NO Then else if ref2.index <> NR_NO Then
list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index)) list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
else if (ref2.base <> NR_NO) and else if (ref2.base <> NR_NO) and
(r <> ref2.base) then (r <> ref2.base) then
@ -2111,12 +2114,47 @@ const
end; end;
function tcgppc.g_darwin_indirect_sym_load(list: taasmoutput; const symname: string): tregister;
var
l: tasmsymbol;
ref: treference;
begin
l:=objectlibrary.getasmsymbol('L'+symname+'$non_lazy_ptr');
if not(assigned(l)) then
begin
l:=objectlibrary.newasmsymbol('L'+symname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
asmlist[al_picdata].concat(tai_symbol.create(l,0));
asmlist[al_picdata].concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(symname,AB_EXTERNAL,AT_DATA)));
asmlist[al_picdata].concat(tai_const.create_32bit(0));
end;
reference_reset_symbol(ref,l,0);
{ ref.base:=current_procinfo.got;
ref.relsymbol:=current_procinfo.gotlabel;}
result := cg.getaddressregister(exprasmlist);
cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,result);
end;
function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean; function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean;
var var
tmpreg: tregister; tmpreg: tregister;
begin begin
result := false; result := false;
if (target_info.system = system_powerpc_darwin) and
assigned(ref.symbol) and
(ref.symbol.defbind = AB_EXTERNAL) then
begin
tmpreg := g_darwin_indirect_sym_load(list,ref.symbol.name);
if (ref.base = NR_NO) then
ref.base := tmpreg
else if (ref.index = NR_NO) then
ref.index := tmpreg
else
list.concat(taicpu.op_reg_reg_reg(A_ADD,ref.base,ref.base,tmpreg));
ref.symbol := nil;
end;
if (ref.base = NR_NO) then if (ref.base = NR_NO) then
begin begin
ref.base := ref.index; ref.base := ref.index;

View File

@ -31,7 +31,6 @@ unit nppcld;
type type
tppcloadnode = class(tcgloadnode) tppcloadnode = class(tcgloadnode)
procedure pass_2; override; procedure pass_2; override;
procedure generate_picvaraccess;override;
end; end;
@ -40,10 +39,9 @@ unit nppcld;
uses uses
verbose, verbose,
systems, systems,
globtype,globals, globtype,globals,defutil,
cpubase, cpubase, aasmbase, aasmtai,
cgutils,cgobj, cgutils,cgbase,cgobj,cgcpu,
aasmbase,aasmtai,
symconst,symsym, symconst,symsym,
procinfo, procinfo,
nld; nld;
@ -53,73 +51,36 @@ unit nppcld;
var var
l : tasmsymbol; l : tasmsymbol;
ref : treference; ref : treference;
symname: string;
begin begin
symname := '';
case target_info.system of case target_info.system of
system_powerpc_darwin: system_powerpc_darwin:
begin begin
if (symtableentry.typ = procsym) and case symtableentry.typ of
(tprocsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and procsym:
( begin
(not tprocsym(symtableentry).owner.iscurrentunit) or if (po_external in tprocsym(symtableentry).procdef[1].procoptions) then
(po_external in tprocsym(symtableentry).procdef[1].procoptions) symname := tprocsym(symtableentry).procdef[1].mangledname;
) then end;
begin globalvarsym:
l:=objectlibrary.getasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr'); begin
if not(assigned(l)) then if ([vo_is_dll_var,vo_is_external] * tglobalvarsym(symtableentry).varoptions <> []) then
begin symname := tglobalvarsym(symtableentry).mangledname;
l:=objectlibrary.newasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA); end;
asmlist[al_picdata].concat(tai_symbol.create(l,0)); end;
asmlist[al_picdata].concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tprocsym(symtableentry).procdef[1].mangledname,AB_EXTERNAL,AT_DATA)));
asmlist[al_picdata].concat(tai_const.create_32bit(0));
end;
reference_reset_symbol(ref,l,0);
reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
end
else
inherited pass_2;
end; end;
else
inherited pass_2;
end; end;
if (symname = '') then
inherited pass_2
else
begin
location_reset(location,LOC_REFERENCE,def_cgsize(resulttype.def));
reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
location.reference.base := tcgppc(cg).g_darwin_indirect_sym_load(exprasmlist,symname);
end;
end; end;
procedure tppcloadnode.generate_picvaraccess;
var
l : tasmsymbol;
ref : treference;
begin
case target_info.system of
system_powerpc_darwin:
begin
if ([vo_is_dll_var,vo_is_external] * tglobalvarsym(symtableentry).varoptions <> []) or
((tglobalvarsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and
(not(tglobalvarsym(symtableentry).owner.iscurrentunit) or
(cs_create_pic in aktmoduleswitches))) then
begin
l:=objectlibrary.getasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr');
if not(assigned(l)) then
begin
l:=objectlibrary.newasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
asmlist[al_picdata].concat(tai_symbol.create(l,0));
asmlist[al_picdata].concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tglobalvarsym(symtableentry).mangledname,AB_EXTERNAL,AT_DATA)));
asmlist[al_picdata].concat(tai_const.create_32bit(0));
end;
reference_reset_symbol(ref,l,0);
{ ref.base:=current_procinfo.got;
ref.relsymbol:=current_procinfo.gotlabel;}
reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
end
else
internalerror(200403021);
end
else
internalerror(200402291);
end;
end;
begin begin
cloadnode:=tppcloadnode; cloadnode:=tppcloadnode;