+ Internal linker for go32v2:

* Enable smart linking on go32v2
  * Adapted external linker script for long section names (ld 2.17 from fpcbuild repository does not seem to actually remove unused sections though)
  * Do not pass '-lc' twice to external linker
  * Pass -Map with correct filename to external linker if -Xm is specified on command line
  * Debug sections for DJCOFF must have zero memory position and flag COFF_STYP_INFO (not COFF_STYP_NOLOAD).

git-svn-id: trunk@21435 -
This commit is contained in:
sergei 2012-05-30 13:45:36 +00:00
parent 1403cec462
commit 3a89544cd6
3 changed files with 125 additions and 12 deletions

View File

@ -336,6 +336,9 @@ implementation
COFF_STYP_TEXT = $0020;
COFF_STYP_DATA = $0040;
COFF_STYP_BSS = $0080;
COFF_STYP_INFO = $0200;
COFF_STYP_OVER = $0400;
COFF_STYP_LIB = $0800;
PE_SUBSYSTEM_NATIVE = 1;
PE_SUBSYSTEM_WINDOWS_GUI = 2;
@ -732,7 +735,7 @@ const pemagic : array[0..3] of byte = (
result:=COFF_STYP_DATA;
end
else if oso_debug in aoptions then
result:=COFF_STYP_NOLOAD
result:=COFF_STYP_INFO
else
result:=COFF_STYP_REG;
end;
@ -747,7 +750,7 @@ const pemagic : array[0..3] of byte = (
result:=[oso_load]
else if flags and COFF_STYP_DATA<>0 then
result:=[oso_data,oso_load]
else if flags and COFF_STYP_NOLOAD<>0 then
else if flags and COFF_STYP_INFO<>0 then
result:=[oso_data,oso_debug]
else
result:=[oso_data]
@ -2130,9 +2133,9 @@ const pemagic : array[0..3] of byte = (
s:='/'+ToStr(strpos);
end;
move(s[1],sechdr.name,length(s));
sechdr.rvaofs:=mempos;
if win32 then
begin
sechdr.rvaofs:=mempos;
sechdr.vsize:=Size;
{ sechdr.dataSize is size of initialized data, rounded up to FileAlignment
(so it can be greater than VirtualSize). Must be zero for sections that
@ -2142,7 +2145,11 @@ const pemagic : array[0..3] of byte = (
end
else
begin
sechdr.vsize:=mempos;
if not (oso_debug in SecOptions) then
begin
sechdr.rvaofs:=mempos;
sechdr.vsize:=mempos;
end;
sechdr.datasize:=Size;
end;
if (Size>0) then
@ -3074,7 +3081,7 @@ const pemagic : array[0..3] of byte = (
asmbin : '';
asmcmd : '';
supported_targets : [system_i386_go32v2];
flags : [af_outputbinary];
flags : [af_outputbinary,af_smartlink_sections];
labelprefix : '.L';
comment : '';
dollarsign: '$';

View File

@ -34,7 +34,7 @@ unit i_go32v2;
system : system_i386_GO32V2;
name : 'GO32 V2 DOS extender';
shortname : 'Go32v2';
flags : [tf_use_8_3,tf_smartlink_library];
flags : [tf_use_8_3,tf_smartlink_library,tf_smartlink_sections];
cpu : cpu_i386;
unit_env : 'GO32V2UNITS';
extradefines : 'DPMI';

View File

@ -34,7 +34,7 @@ implementation
cutils,cfileutl,cclasses,
globtype,globals,systems,verbose,script,
fmodule,i_go32v2,
link,ogcoff;
link,ogcoff,aasmbase;
type
TInternalLinkerGo32v2=class(TInternallinker)
@ -66,7 +66,109 @@ implementation
procedure TInternalLinkerGo32v2.DefaultLinkScript;
var
s: TCmdStr;
linklibc: Boolean;
i: longint;
procedure AddLib(const name: TCmdStr);
var
s2: TCmdStr;
begin
if FindLibraryFile(name,target_info.staticClibprefix,target_info.staticClibext,s2) then
LinkScript.Concat('READSTATICLIBRARY '+MaybeQuoted(s2))
else
Comment(V_Error,'Import library not found for '+name);
end;
begin
with LinkScript do
begin
Concat('READOBJECT '+GetShortName(FindObjectFile('prt0','',false)));
while not ObjectFiles.Empty do
begin
s:=ObjectFiles.GetFirst;
if s<>'' then
Concat('READOBJECT '+MaybeQuoted(s));
end;
while not StaticLibFiles.Empty do
begin
s:=StaticLibFiles.GetFirst;
if s<>'' then
Concat('READSTATICLIBRARY '+MaybeQuoted(s));
end;
linklibc:=False;
while not SharedLibFiles.Empty do
begin
S:=SharedLibFiles.GetFirst;
if S<>'c' then
begin
i:=Pos(target_info.sharedlibext,S);
if i>0 then
Delete(S,i,255);
AddLib(s);
end
else
linklibc:=true;
end;
{ be sure that to add libc and libgcc at the end }
if linklibc then
begin
AddLib('c');
AddLib('gcc');
end;
Concat('ENTRYNAME start');
Concat('HEADER');
Concat('EXESECTION .text');
Concat(' OBJSECTION .text*');
Concat(' SYMBOL etext');
Concat(' PROVIDE _etext');
Concat('ENDEXESECTION');
Concat('EXESECTION .data');
Concat(' SYMBOL djgpp_first_ctor');
Concat(' OBJSECTION .ctors.*');
Concat(' OBJSECTION .ctor');
Concat(' OBJSECTION .ctors');
Concat(' SYMBOL djgpp_last_ctor');
Concat(' SYMBOL djgpp_first_dtor');
Concat(' OBJSECTION .dtors.*');
Concat(' OBJSECTION .dtor');
Concat(' OBJSECTION .dtors');
Concat(' SYMBOL djgpp_last_dtor');
Concat(' SYMBOL __environ');
Concat(' PROVIDE _environ');
Concat(' LONG 0');
Concat(' OBJSECTION .data*');
Concat(' OBJSECTION .fpc*');
Concat(' OBJSECTION .gcc_exc*');
Concat(' SYMBOL ___EH_FRAME_BEGIN__');
Concat(' OBJSECTION .eh_fram*');
Concat(' SYMBOL ___EH_FRAME_END__');
Concat(' LONG 0');
Concat(' SYMBOL edata');
Concat(' SYMBOL _edata');
Concat('ENDEXESECTION');
Concat('EXESECTION .bss');
//ScriptRes.Add(' _object.2 = . ;');
//ScriptRes.Add(' . += 32 ;');
Concat(' OBJSECTION .bss*');
Concat(' SYMBOL end');
Concat(' SYMBOL _end');
Concat('ENDEXESECTION');
{ Stabs debugging sections }
Concat('EXESECTION .stab');
Concat(' OBJSECTION .stab');
Concat('ENDEXESECTION');
Concat('EXESECTION .stabstr');
Concat(' OBJSECTION .stabstr');
Concat('ENDEXESECTION');
{ DWARF 2 }
ConcatGenericSections('.debug_aranges,.debug_pubnames,.debug_info,.debug_abbrev,'+
'.debug_line,.debug_frame,.debug_str,.debug_loc,.debug_macinfo');
Concat('STABS');
Concat('SYMBOLS');
end;
end;
@ -107,6 +209,10 @@ begin
{ Add all options to link.res instead of passing them via command line:
DOS command line is limited to 126 characters! }
LinkRes.Add('--script='+maybequoted(outputexedir+Info.ScriptName));
if (cs_link_map in current_settings.globalswitches) then
LinkRes.Add('-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map')));
if create_smartlink_sections then
LinkRes.Add('--gc-sections');
if info.ExtraOptions<>'' then
LinkRes.Add(Info.ExtraOptions);
(* Potential issues with older ld version??? *)
@ -140,10 +246,7 @@ begin
LinkRes.Add('-l'+s);
end
else
begin
LinkRes.Add('-l'+s);
linklibc:=true;
end;
linklibc:=true;
end;
{ be sure that libc&libgcc is the last lib }
if linklibc then
@ -189,6 +292,7 @@ begin
end;
end;
ScriptRes.Add(' *(.text)');
ScriptRes.Add(' *(.text.*)');
ScriptRes.Add(' etext = . ;');
ScriptRes.Add(' PROVIDE(_etext = .);');
ScriptRes.Add(' . = ALIGN(0x200);');
@ -208,6 +312,7 @@ begin
ScriptRes.Add(' PROVIDE(_environ = .);');
ScriptRes.Add(' LONG(0)');
ScriptRes.Add(' *(.data)');
ScriptRes.Add(' *(.data.*)');
ScriptRes.Add(' *(.fpc*)');
ScriptRes.Add(' *(.gcc_exc)');
ScriptRes.Add(' ___EH_FRAME_BEGIN__ = . ;');
@ -222,6 +327,7 @@ begin
ScriptRes.Add(' _object.2 = . ;');
ScriptRes.Add(' . += 32 ;');
ScriptRes.Add(' *(.bss)');
ScriptRes.Add(' *(.bss.*)');
ScriptRes.Add(' *(COMMON)');
ScriptRes.Add(' end = . ; _end = .;');
ScriptRes.Add(' . = ALIGN(0x200);');
@ -402,6 +508,6 @@ end;
initialization
RegisterExternalLinker(system_i386_go32v2_info,TExternalLinkerGo32v2);
// RegisterInternalLinker(system_i386_go32v2_info,TInternalLinkerGo32v2);
RegisterInternalLinker(system_i386_go32v2_info,TInternalLinkerGo32v2);
RegisterTarget(system_i386_go32v2_info);
end.