~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to fpcsrc/compiler/systems/t_sunos.pas

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
    Copyright (c) 1998-2002 by Peter Vreman
 
3
 
 
4
    This unit implements support import,export,link routines
 
5
    for the (i386) solaris target
 
6
 
 
7
    This program is free software; you can redistribute it and/or modify
 
8
    it under the terms of the GNU General Public License as published by
 
9
    the Free Software Foundation; either version 2 of the License, or
 
10
    (at your option) any later version.
 
11
 
 
12
    This program is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
    GNU General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU General Public License
 
18
    along with this program; if not, write to the Free Software
 
19
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
 
 
21
 ****************************************************************************
 
22
}
 
23
unit t_sunos;
 
24
 
 
25
{$i fpcdefs.inc}
 
26
 
 
27
interface
 
28
 
 
29
{ copy from t_linux
 
30
// Up to now we use gld since the solaris ld seems not support .res-files}
 
31
{-$DEFINE LinkTest} { DON't del link.res and write Info }
 
32
{$DEFINE GnuLd} {The other is not implemented }
 
33
 
 
34
implementation
 
35
 
 
36
  uses
 
37
    sysutils,
 
38
    cutils,cfileutils,cclasses,
 
39
    verbose,systems,globtype,globals,
 
40
    symconst,script,
 
41
    fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,
 
42
    cgobj,
 
43
    import,export,link,i_sunos,ogbase;
 
44
 
 
45
  type
 
46
    timportlibsolaris=class(timportlib)
 
47
      procedure generatelib;override;
 
48
    end;
 
49
 
 
50
    texportlibsolaris=class(texportlib)
 
51
      procedure preparelib(const s : string);override;
 
52
      procedure exportprocedure(hp : texported_item);override;
 
53
      procedure exportvar(hp : texported_item);override;
 
54
      procedure generatelib;override;
 
55
    end;
 
56
 
 
57
    tlinkersolaris=class(texternallinker)
 
58
    private
 
59
      Glibc2,
 
60
      Glibc21 : boolean;
 
61
      Function  WriteResponseFile(isdll:boolean) : Boolean;
 
62
    public
 
63
      constructor Create;override;
 
64
      procedure SetDefaultInfo;override;
 
65
      function  MakeExecutable:boolean;override;
 
66
      function  MakeSharedLibrary:boolean;override;
 
67
    end;
 
68
 
 
69
 
 
70
{*****************************************************************************
 
71
                               TIMPORTLIBsolaris
 
72
*****************************************************************************}
 
73
 
 
74
    procedure timportlibsolaris.generatelib;
 
75
      var
 
76
        i : longint;
 
77
        ImportLibrary : TImportLibrary;
 
78
      begin
 
79
        for i:=0 to current_module.ImportLibraryList.Count-1 do
 
80
          begin
 
81
            ImportLibrary:=TImportLibrary(current_module.ImportLibraryList[i]);
 
82
            current_module.linkothersharedlibs.add(ImportLibrary.Name,link_always);
 
83
          end;
 
84
      end;
 
85
 
 
86
 
 
87
{*****************************************************************************
 
88
                               TEXPORTLIBsolaris
 
89
*****************************************************************************}
 
90
 
 
91
procedure texportlibsolaris.preparelib(const s:string);
 
92
begin
 
93
end;
 
94
 
 
95
 
 
96
procedure texportlibsolaris.exportprocedure(hp : texported_item);
 
97
var
 
98
  hp2 : texported_item;
 
99
begin
 
100
  { first test the index value }
 
101
  if (hp.options and eo_index)<>0 then
 
102
   begin
 
103
     Message1(parser_e_no_export_with_index_for_target,'solaris');
 
104
     exit;
 
105
   end;
 
106
  { use pascal name is none specified }
 
107
  if (hp.options and eo_name)=0 then
 
108
    begin
 
109
       hp.name:=stringdup(hp.sym.name);
 
110
       hp.options:=hp.options or eo_name;
 
111
    end;
 
112
  { now place in correct order }
 
113
  hp2:=texported_item(current_module._exports.first);
 
114
  while assigned(hp2) and
 
115
     (hp.name^>hp2.name^) do
 
116
    hp2:=texported_item(hp2.next);
 
117
  { insert hp there !! }
 
118
  if assigned(hp2) and (hp2.name^=hp.name^) then
 
119
    begin
 
120
      { this is not allowed !! }
 
121
      Message1(parser_e_export_name_double,hp.name^);
 
122
      exit;
 
123
    end;
 
124
  if hp2=texported_item(current_module._exports.first) then
 
125
    current_module._exports.insert(hp)
 
126
  else if assigned(hp2) then
 
127
    begin
 
128
       hp.next:=hp2;
 
129
       hp.previous:=hp2.previous;
 
130
       if assigned(hp2.previous) then
 
131
         hp2.previous.next:=hp;
 
132
       hp2.previous:=hp;
 
133
    end
 
134
  else
 
135
    current_module._exports.concat(hp);
 
136
end;
 
137
 
 
138
 
 
139
procedure texportlibsolaris.exportvar(hp : texported_item);
 
140
begin
 
141
  hp.is_var:=true;
 
142
  exportprocedure(hp);
 
143
end;
 
144
 
 
145
 
 
146
procedure texportlibsolaris.generatelib;
 
147
var
 
148
  hp2 : texported_item;
 
149
  pd  : tprocdef;
 
150
begin
 
151
  new_section(current_asmdata.asmlists[al_procedures],sec_code,'',0);
 
152
  hp2:=texported_item(current_module._exports.first);
 
153
  while assigned(hp2) do
 
154
   begin
 
155
     if (not hp2.is_var) and
 
156
        (hp2.sym.typ=procsym) then
 
157
      begin
 
158
        { the manglednames can already be the same when the procedure
 
159
          is declared with cdecl }
 
160
        pd:=tprocdef(tprocsym(hp2.sym).ProcdefList[0]);
 
161
        if pd.mangledname<>hp2.name^ then
 
162
         begin
 
163
           { place jump in al_procedures }
 
164
           current_asmdata.asmlists[al_procedures].concat(tai_align.create(target_info.alignment.procalign));
 
165
           current_asmdata.asmlists[al_procedures].concat(Tai_symbol.Createname_global(hp2.name^,AT_FUNCTION,0));
 
166
           cg.a_jmp_name(current_asmdata.asmlists[al_procedures],pd.mangledname);
 
167
           current_asmdata.asmlists[al_procedures].concat(Tai_symbol_end.Createname(hp2.name^));
 
168
         end;
 
169
      end
 
170
     else
 
171
      Message1(parser_e_no_export_of_variables_for_target,'linux');
 
172
     hp2:=texported_item(hp2.next);
 
173
   end;
 
174
end;
 
175
 
 
176
 
 
177
{*****************************************************************************
 
178
                                  TLINKERsolaris
 
179
*****************************************************************************}
 
180
 
 
181
Constructor TLinkersolaris.Create;
 
182
begin
 
183
  Inherited Create;
 
184
  if NOT Dontlinkstdlibpath Then
 
185
   LibrarySearchPath.AddPath('/lib;/usr/lib;/usr/X11R6/lib;/opt/sfw/lib',true);
 
186
{$ifdef  LinkTest}
 
187
     if (cs_link_staticflag in current_settings.globalswitches) then  WriteLN('ForceLinkStaticFlag');
 
188
     if (cs_link_static in current_settings.globalswitches) then  WriteLN('LinkStatic-Flag');
 
189
     if (cs_link_shared in current_settings.globalswitches) then  WriteLN('LinkSynamicFlag');
 
190
{$EndIf}
 
191
end;
 
192
 
 
193
 
 
194
procedure TLinkersolaris.SetDefaultInfo;
 
195
{
 
196
  This will also detect which libc version will be used
 
197
}
 
198
begin
 
199
  Glibc2:=false;
 
200
  Glibc21:=false;
 
201
  with Info do
 
202
   begin
 
203
{$IFDEF GnuLd}
 
204
     ExeCmd[1]:='gld $OPT $DYNLINK $STATIC $STRIP -L. -o $EXE $RES';
 
205
     DllCmd[1]:='gld $OPT -shared -L. -o $EXE $RES';
 
206
     DllCmd[2]:='strip --strip-unneeded $EXE';
 
207
     DynamicLinker:=''; { Gnu uses the default }
 
208
     Glibc21:=false;
 
209
{$ELSE}
 
210
    Not Implememted
 
211
{$ENDIF}
 
212
(* Linux Stuff not needed?
 
213
     { first try glibc2 } // muss noch gendert werden
 
214
     if FileExists(DynamicLinker) then
 
215
      begin
 
216
        Glibc2:=true;
 
217
        { Check for 2.0 files, else use the glibc 2.1 stub }
 
218
        if FileExists('/lib/ld-2.0.*') then
 
219
         Glibc21:=false
 
220
        else
 
221
         Glibc21:=true;
 
222
      end
 
223
     else
 
224
      DynamicLinker:='/lib/ld-linux.so.1';
 
225
*)
 
226
   end;
 
227
 
 
228
end;
 
229
 
 
230
 
 
231
Function TLinkersolaris.WriteResponseFile(isdll:boolean) : Boolean;
 
232
Var
 
233
  linkres      : TLinkRes;
 
234
  i            : longint;
 
235
  cprtobj,
 
236
  gprtobj,
 
237
  prtobj       : string[80];
 
238
  HPath        : TCmdStrListItem;
 
239
  s,s2         : TCmdStr;
 
240
  linkdynamic,
 
241
  linklibc     : boolean;
 
242
begin
 
243
  WriteResponseFile:=False;
 
244
{ set special options for some targets }
 
245
  linkdynamic:=not(SharedLibFiles.empty);
 
246
{  linkdynamic:=false; // da nicht getestet }
 
247
  linklibc:=(SharedLibFiles.Find('c')<>nil);
 
248
  prtobj:='prt0';
 
249
  cprtobj:='cprt0';
 
250
  gprtobj:='gprt0';
 
251
  if cs_profile in current_settings.moduleswitches then
 
252
   begin
 
253
     prtobj:=gprtobj;
 
254
     if not glibc2 then
 
255
      AddSharedLibrary('gmon');
 
256
     AddSharedLibrary('c');
 
257
     linklibc:=true;
 
258
   end
 
259
  else
 
260
   begin
 
261
     if linklibc then
 
262
       prtobj:=cprtobj
 
263
      else
 
264
       AddSharedLibrary('c'); { quick hack: this solaris implementation needs alwys libc }
 
265
   end;
 
266
 
 
267
  { Open link.res file }
 
268
  LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
 
269
 
 
270
  { Write path to search libraries }
 
271
  HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
 
272
  while assigned(HPath) do
 
273
   begin
 
274
     LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
 
275
     HPath:=TCmdStrListItem(HPath.Next);
 
276
   end;
 
277
  HPath:=TCmdStrListItem(LibrarySearchPath.First);
 
278
  while assigned(HPath) do
 
279
   begin
 
280
     LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
 
281
     HPath:=TCmdStrListItem(HPath.Next);
 
282
   end;
 
283
 
 
284
  LinkRes.Add('INPUT(');
 
285
  { add objectfiles, start with prt0 always }
 
286
  { solaris port contains _start inside the system unit, it
 
287
    needs only one entry because it is linked always against libc
 
288
  if prtobj<>'' then
 
289
   LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
 
290
  }
 
291
  { try to add crti and crtbegin if linking to C }
 
292
  if linklibc then { Needed in solaris? }
 
293
   begin
 
294
{     if librarysearchpath.FindFile('crtbegin.o',s) then
 
295
      LinkRes.AddFileName(s);}
 
296
     if librarysearchpath.FindFile('crti.o',false,s) then
 
297
      LinkRes.AddFileName(s);
 
298
   end;
 
299
  { main objectfiles }
 
300
  while not ObjectFiles.Empty do
 
301
   begin
 
302
     s:=ObjectFiles.GetFirst;
 
303
     if s<>'' then
 
304
      LinkRes.AddFileName(maybequoted(s));
 
305
   end;
 
306
  LinkRes.Add(')');
 
307
 
 
308
  { Write staticlibraries }
 
309
  if not StaticLibFiles.Empty then
 
310
   begin
 
311
     LinkRes.Add('GROUP(');
 
312
     While not StaticLibFiles.Empty do
 
313
      begin
 
314
        S:=StaticLibFiles.GetFirst;
 
315
        LinkRes.AddFileName(maybequoted(s))
 
316
      end;
 
317
     LinkRes.Add(')');
 
318
   end;
 
319
 
 
320
  { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
 
321
    here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
 
322
  if not SharedLibFiles.Empty then
 
323
   begin
 
324
     LinkRes.Add('INPUT(');
 
325
     While not SharedLibFiles.Empty do
 
326
      begin
 
327
        S:=SharedLibFiles.GetFirst;
 
328
        if s<>'c' then
 
329
         begin
 
330
           i:=Pos(target_info.sharedlibext,S);
 
331
           if i>0 then
 
332
            Delete(S,i,255);
 
333
           LinkRes.Add('-l'+s);
 
334
         end
 
335
        else
 
336
         begin
 
337
           linklibc:=true;
 
338
           linkdynamic:=false; { libc will include the ld-solaris (war ld-linux) for us }
 
339
         end;
 
340
      end;
 
341
     { be sure that libc is the last lib }
 
342
     if linklibc then
 
343
      LinkRes.Add('-lc');
 
344
     { when we have -static for the linker the we also need libgcc }
 
345
     if (cs_link_staticflag in current_settings.globalswitches) then begin
 
346
      LinkRes.Add('-lgcc');
 
347
     end;
 
348
     if linkdynamic and (Info.DynamicLinker<>'') then { gld has a default, DynamicLinker is not set in solaris }
 
349
       LinkRes.AddFileName(Info.DynamicLinker);
 
350
     LinkRes.Add(')');
 
351
   end;
 
352
  { objects which must be at the end }
 
353
  if linklibc then {needed in solaris ? }
 
354
   begin
 
355
     if {librarysearchpath.FindFile('crtend.o',s1) or}
 
356
        librarysearchpath.FindFile('crtn.o',false,s2) then
 
357
      begin
 
358
        LinkRes.Add('INPUT(');
 
359
{        LinkRes.AddFileName(s1);}
 
360
        LinkRes.AddFileName(s2);
 
361
        LinkRes.Add(')');
 
362
      end;
 
363
   end;
 
364
{ Write and Close response }
 
365
  linkres.writetodisk;
 
366
  LinkRes.Free;
 
367
 
 
368
  WriteResponseFile:=True;
 
369
end;
 
370
 
 
371
 
 
372
function TLinkersolaris.MakeExecutable:boolean;
 
373
var
 
374
  binstr,
 
375
  cmdstr  : TCmdStr;
 
376
  success : boolean;
 
377
  DynLinkStr : string[60];
 
378
  StaticStr,
 
379
  StripStr   : string[40];
 
380
begin
 
381
  if not(cs_link_nolink in current_settings.globalswitches) then
 
382
   Message1(exec_i_linking,current_module.exefilename^);
 
383
 
 
384
{ Create some replacements }
 
385
  StaticStr:='';
 
386
  StripStr:='';
 
387
  DynLinkStr:='';
 
388
  if (cs_link_staticflag in current_settings.globalswitches) then
 
389
    StaticStr:='-Bstatic';
 
390
  if (cs_link_strip in current_settings.globalswitches) then
 
391
   StripStr:='-s';
 
392
  If (cs_profile in current_settings.moduleswitches) or
 
393
     ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
 
394
   DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
 
395
  { solaris sets DynamicLinker, but gld will (hopefully) defaults to -Bdynamic and add the default-linker }
 
396
{ Write used files and libraries }
 
397
  WriteResponseFile(false);
 
398
 
 
399
{ Call linker }
 
400
  SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
 
401
  Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
 
402
  Replace(cmdstr,'$OPT',Info.ExtraOptions);
 
403
  Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
 
404
  Replace(cmdstr,'$STATIC',StaticStr);
 
405
  Replace(cmdstr,'$STRIP',StripStr);
 
406
  Replace(cmdstr,'$DYNLINK',DynLinkStr);
 
407
  success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
 
408
 
 
409
{ Remove ReponseFile }
 
410
{$IFNDEF LinkTest}
 
411
  if (success) and not(cs_link_nolink in current_settings.globalswitches) then
 
412
   DeleteFile(outputexedir+Info.ResName);
 
413
{$ENDIF}
 
414
  MakeExecutable:=success;   { otherwise a recursive call to link method }
 
415
end;
 
416
 
 
417
 
 
418
Function TLinkersolaris.MakeSharedLibrary:boolean;
 
419
var
 
420
  binstr,
 
421
  cmdstr  : TCmdStr;
 
422
  success : boolean;
 
423
begin
 
424
  MakeSharedLibrary:=false;
 
425
  if not(cs_link_nolink in current_settings.globalswitches) then
 
426
   Message1(exec_i_linking,current_module.sharedlibfilename^);
 
427
 
 
428
{ Write used files and libraries }
 
429
  WriteResponseFile(true);
 
430
 
 
431
{ Call linker }
 
432
  SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
 
433
  Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
 
434
  Replace(cmdstr,'$OPT',Info.ExtraOptions);
 
435
  Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
 
436
  success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
 
437
 
 
438
{ Strip the library ? }
 
439
  if success and (cs_link_strip in current_settings.globalswitches) then
 
440
   begin
 
441
     SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
 
442
     Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
 
443
     success:=DoExec(utilsprefix+FindUtil(binstr),cmdstr,true,false);
 
444
   end;
 
445
 
 
446
{ Remove ReponseFile }
 
447
{$IFNDEF LinkTest}
 
448
  if (success) and not(cs_link_nolink in current_settings.globalswitches) then
 
449
   DeleteFile(outputexedir+Info.ResName);
 
450
{$ENDIF}
 
451
  MakeSharedLibrary:=success;   { otherwise a recursive call to link method }
 
452
end;
 
453
 
 
454
 
 
455
{*****************************************************************************
 
456
                                     Initialize
 
457
*****************************************************************************}
 
458
 
 
459
initialization
 
460
{$ifdef i386}
 
461
  RegisterExternalLinker(system_i386_solaris_info,TLinkersolaris);
 
462
  RegisterImport(system_i386_solaris,TImportLibsolaris);
 
463
  RegisterExport(system_i386_solaris,TExportLibsolaris);
 
464
  RegisterTarget(system_i386_solaris_info);
 
465
{$endif i386}
 
466
 
 
467
{$ifdef sparc}
 
468
  RegisterExternalLinker(system_sparc_solaris_info,TLinkersolaris);
 
469
  RegisterImport(system_sparc_solaris,TImportLibsolaris);
 
470
  RegisterExport(system_sparc_solaris,TExportLibsolaris);
 
471
  RegisterTarget(system_sparc_solaris_info);
 
472
{$endif sparc}
 
473
end.