* fixed creating shared libraries under Darwin/Mac OS X

git-svn-id: trunk@727 -
This commit is contained in:
Jonas Maebe 2005-07-22 10:09:52 +00:00
parent c15f720867
commit 6171499d15
6 changed files with 92 additions and 41 deletions

View File

@ -290,9 +290,6 @@ var
'.debug_frame' '.debug_frame'
); );
begin begin
if (target_info.system = system_powerpc_darwin) and
(atype = sec_bss) then
atype := sec_code;
if use_smartlink_section and if use_smartlink_section and
(atype<>sec_bss) and (atype<>sec_bss) and
(aname<>'') then (aname<>'') then
@ -516,16 +513,31 @@ var
ait_datablock : ait_datablock :
begin begin
if tai_datablock(hp).is_global then if (target_info.system <> system_powerpc_darwin) or
AsmWrite(#9'.comm'#9) not tai_datablock(hp).is_global then
begin
if tai_datablock(hp).is_global then
AsmWrite(#9'.comm'#9)
else
AsmWrite(#9'.lcomm'#9);
AsmWrite(tai_datablock(hp).sym.name);
AsmWrite(','+tostr(tai_datablock(hp).size));
if (target_info.system = system_powerpc_darwin) { and
not(tai_datablock(hp).is_global)} then
AsmWrite(','+tostr(last_align));
AsmWriteln('');
end
else else
AsmWrite(#9'.lcomm'#9); begin
AsmWrite(tai_datablock(hp).sym.name); AsmWrite('.globl ');
AsmWrite(','+tostr(tai_datablock(hp).size)); AsmWriteln(tai_datablock(hp).sym.name);
if (target_info.system = system_powerpc_darwin) and AsmWriteln('.data');
not(tai_datablock(hp).is_global) then AsmWrite('.zerofill __DATA, __common, ');
AsmWrite(','+tostr(last_align)); AsmWrite(tai_datablock(hp).sym.name);
AsmWriteln(''); AsmWriteln(', '+tostr(tai_datablock(hp).size)+','+tostr(last_align));
if not(lasTSectype in [sec_data,sec_none]) then
WriteSection(lasTSectype,'');
end;
end; end;
{$ifndef cpu64bit} {$ifndef cpu64bit}

View File

@ -126,22 +126,20 @@ implementation
begin begin
symtabletype:=symtable.symtabletype; symtabletype:=symtable.symtabletype;
hregister:=NR_NO; hregister:=NR_NO;
{ DLL variable } 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 begin
if target_info.system=system_powerpc_darwin then if not(pi_needs_got in current_procinfo.flags) then
begin internalerror(200403022);
generate_picvaraccess; generate_picvaraccess;
if not(pi_needs_got in current_procinfo.flags) then end
internalerror(200403022); else if (vo_is_dll_var in tabstractvarsym(symtableentry).varoptions) then
end { DLL variable }
else begin
begin hregister:=cg.getaddressregister(exprasmlist);
hregister:=cg.getaddressregister(exprasmlist); location.reference.symbol:=objectlibrary.newasmsymbol(tglobalvarsym(symtableentry).mangledname,AB_EXTERNAL,AT_DATA);
location.reference.symbol:=objectlibrary.newasmsymbol(tglobalvarsym(symtableentry).mangledname,AB_EXTERNAL,AT_DATA); cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,location.reference,hregister);
cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,location.reference,hregister); reference_reset_base(location.reference,hregister,0);
reference_reset_base(location.reference,hregister,0);
end;
end end
{ Thread variable } { Thread variable }
else if (vo_is_thread_var in tabstractvarsym(symtableentry).varoptions) then else if (vo_is_thread_var in tabstractvarsym(symtableentry).varoptions) then

View File

@ -391,7 +391,8 @@ implementation
registersint:=1; registersint:=1;
if ([vo_is_thread_var,vo_is_dll_var]*tabstractvarsym(symtableentry).varoptions)<>[] then if ([vo_is_thread_var,vo_is_dll_var]*tabstractvarsym(symtableentry).varoptions)<>[] then
registersint:=1; registersint:=1;
if (target_info.system=system_powerpc_darwin) and (vo_is_dll_var in tabstractvarsym(symtableentry).varoptions) then if (target_info.system=system_powerpc_darwin) and
([vo_is_dll_var,vo_is_external] * tabstractvarsym(symtableentry).varoptions <> []) then
include(current_procinfo.flags,pi_needs_got); include(current_procinfo.flags,pi_needs_got);
{ call to get address of threadvar } { call to get address of threadvar }
if (vo_is_thread_var in tabstractvarsym(symtableentry).varoptions) then if (vo_is_thread_var in tabstractvarsym(symtableentry).varoptions) then

View File

@ -29,6 +29,7 @@ unit agppcgas;
interface interface
uses uses
aasmbase,
aasmtai, aasmtai,
aggas, aggas,
cpubase; cpubase;
@ -36,6 +37,7 @@ unit agppcgas;
type type
PPPCGNUAssembler=^TPPCGNUAssembler; PPPCGNUAssembler=^TPPCGNUAssembler;
TPPCGNUAssembler=class(TGNUassembler) TPPCGNUAssembler=class(TGNUassembler)
function sectionname(atype:tasmsectiontype;const aname:string):string;override;
procedure WriteExtraHeader;override; procedure WriteExtraHeader;override;
procedure WriteInstruction(hp : tai);override; procedure WriteInstruction(hp : tai);override;
end; end;
@ -44,7 +46,7 @@ unit agppcgas;
implementation implementation
uses uses
cutils,globals,verbose, cutils,globals,verbose,globtype,
cgbase,cgutils,systems, cgbase,cgutils,systems,
assemble, assemble,
itcpugas, itcpugas,
@ -96,6 +98,16 @@ unit agppcgas;
refaddr2str_darwin: array[trefaddr] of string[4] = ('','','ha16','lo16',''); refaddr2str_darwin: array[trefaddr] of string[4] = ('','','ha16','lo16','');
function TPPCGNUAssembler.sectionname(atype:tasmsectiontype;const aname:string):string;
begin
if (target_info.system = system_powerpc_darwin) and
(atype = sec_bss) then
atype := sec_code;
result := inherited sectionname(atype,aname);
end;
function getreferencestring(var ref : treference) : string; function getreferencestring(var ref : treference) : string;
var var
s : string; s : string;

View File

@ -91,7 +91,7 @@ unit nppcld;
case target_info.system of case target_info.system of
system_powerpc_darwin: system_powerpc_darwin:
begin begin
if (vo_is_dll_var in tglobalvarsym(symtableentry).varoptions) or if ([vo_is_dll_var,vo_is_external] * tglobalvarsym(symtableentry).varoptions <> []) or
((tglobalvarsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and ((tglobalvarsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and
not(tglobalvarsym(symtableentry).owner.iscurrentunit)) then not(tglobalvarsym(symtableentry).owner.iscurrentunit)) then
begin begin

View File

@ -167,7 +167,7 @@ begin
{ first test the index value } { first test the index value }
if (hp.options and eo_index)<>0 then if (hp.options and eo_index)<>0 then
begin begin
Message1(parser_e_no_export_with_index_for_target,'freebsd'); Message1(parser_e_no_export_with_index_for_target,'*bsd/darwin');
exit; exit;
end; end;
{ now place in correct order } { now place in correct order }
@ -225,10 +225,16 @@ begin
codeSegment.concat(Taicpu.Op_sym(A_JMP,S_NO,objectlibrary.newasmsymbol(tprocsym(hp2.sym).first_procdef.mangledname,AB_EXTERNAL,AT_FUNCTION))); codeSegment.concat(Taicpu.Op_sym(A_JMP,S_NO,objectlibrary.newasmsymbol(tprocsym(hp2.sym).first_procdef.mangledname,AB_EXTERNAL,AT_FUNCTION)));
codeSegment.concat(Tai_symbol_end.Createname(hp2.name^)); codeSegment.concat(Tai_symbol_end.Createname(hp2.name^));
{$endif i386} {$endif i386}
{$ifdef powerpc}
codesegment.concat(Tai_align.create(16));
codesegment.concat(Tai_symbol.Createname_global(hp2.name^,AT_FUNCTION,0));
codeSegment.concat(Taicpu.Op_sym(A_B,objectlibrary.newasmsymbol(tprocsym(hp2.sym).first_procdef.mangledname,AB_EXTERNAL,AT_FUNCTION)));
codeSegment.concat(Tai_symbol_end.Createname(hp2.name^));
{$endif powerpc}
end; end;
end end
else else
Message1(parser_e_no_export_of_variables_for_target,'freebsd'); Message1(parser_e_no_export_of_variables_for_target,'*bsd/darwin');
hp2:=texported_item(hp2.next); hp2:=texported_item(hp2.next);
end; end;
end; end;
@ -261,12 +267,26 @@ begin
begin begin
if LdSupportsNoResponseFile then if LdSupportsNoResponseFile then
begin begin
ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE `cat $RES`'; if (target_info.system <> system_powerpc_darwin) then
begin
ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE `cat $RES`';
DllCmd[1]:='ld $OPT -shared -L. -o $EXE `cat $RES`'
end
else
begin
ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE `cat $RES`';
DllCmd[1]:='libtool $OPT -dynamic -init PASCALMAIN -multiply_defined suppress -L. -o $EXE `cat $RES`'
end
end end
else else
ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE $RES'; begin
DllCmd[1]:='ld $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES'; ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE $RES';
DllCmd[2]:='strip --strip-unneeded $EXE'; DllCmd[1]:='ld $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
end;
if (target_info.system <> system_powerpc_darwin) then
DllCmd[2]:='strip --strip-unneeded $EXE'
else
DllCmd[2]:='strip -x $EXE';
{ first try glibc2 } { first try glibc2 }
{$ifdef GLIBC2} {Keep linux code in place. FBSD might go to a different {$ifdef GLIBC2} {Keep linux code in place. FBSD might go to a different
glibc too once} glibc too once}
@ -338,12 +358,15 @@ begin
end end
else else
begin begin
{ for darwin: always link dynamically against libc } { for darwin: always link dynamically against libc }
linklibc := true; linklibc := true;
if not(cs_profile in aktmoduleswitches) then if not(isdll) then
prtobj:='/usr/lib/crt1.o' if not(cs_profile in aktmoduleswitches) then
prtobj:='/usr/lib/crt1.o'
else
prtobj:='/usr/lib/gcrt1.o'
else else
prtobj:='/usr/lib/gcrt1.o'; prtobj:='';
end; end;
@ -464,6 +487,11 @@ begin
LinkRes.Add(')'); LinkRes.Add(')');
end; end;
end; end;
{ ignore the fact that our relocations are in non-writable sections, }
{ will be fixed once we have pic support }
if isdll and
(target_info.system = system_powerpc_darwin) then
LinkRes.Add('-read_only_relocs suppress');
{ Write and Close response } { Write and Close response }
linkres.writetodisk; linkres.writetodisk;
linkres.Free; linkres.Free;
@ -566,7 +594,7 @@ begin
Replace(cmdstr,'$FINI',FiniStr); Replace(cmdstr,'$FINI',FiniStr);
Replace(cmdstr,'$SONAME',SoNameStr); Replace(cmdstr,'$SONAME',SoNameStr);
success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false); success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,LdSupportsNoResponseFile);
{ Strip the library ? } { Strip the library ? }
if success and (cs_link_strip in aktglobalswitches) then if success and (cs_link_strip in aktglobalswitches) then