~ubuntu-branches/ubuntu/feisty/fpc/feisty

« back to all changes in this revision

Viewing changes to compiler/systems/t_bsd.pas

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-01-27 20:08:50 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070127200850-9mrptaqqjsx9nwa7
Tags: 2.0.4-5
* Fixed Build-Depends.
* Add myself to Uploaders in debian/control.
* Make sure that the sources are really patched before building them.
* Build unit 'libc' on powerpc too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
{
2
 
    $Id: t_bsd.pas,v 1.30 2005/04/27 21:47:08 marco Exp $
3
2
    Copyright (c) 1998-2002 by Peter Vreman (original Linux)
4
3
              (c) 2000      by Marco van de Voort (FreeBSD mods)
5
4
 
36
35
    gdb,
37
36
{$endif gdb}
38
37
    cutils,cclasses,
 
38
{$ifdef USE_SYSUTILS}
 
39
    sysutils,
 
40
{$else USE_SYSUTILS}
 
41
    dos,
 
42
{$endif USE_SYSUTILS}
39
43
    verbose,systems,globtype,globals,
40
44
    symconst,script,
41
45
    fmodule,aasmbase,aasmtai,aasmcpu,cpubase,symsym,symdef,
79
83
      procedure SetDefaultInfo;override;
80
84
      function  MakeExecutable:boolean;override;
81
85
      function  MakeSharedLibrary:boolean;override;
 
86
      procedure LoadPredefinedLibraryOrder; override;
82
87
    end;
83
88
 
84
89
 
168
173
  { first test the index value }
169
174
  if (hp.options and eo_index)<>0 then
170
175
   begin
171
 
     Message1(parser_e_no_export_with_index_for_target,'freebsd');
 
176
     Message1(parser_e_no_export_with_index_for_target,'*bsd/darwin');
172
177
     exit;
173
178
   end;
174
179
  { now place in correct order }
226
231
           codeSegment.concat(Taicpu.Op_sym(A_JMP,S_NO,objectlibrary.newasmsymbol(tprocsym(hp2.sym).first_procdef.mangledname,AB_EXTERNAL,AT_FUNCTION)));
227
232
           codeSegment.concat(Tai_symbol_end.Createname(hp2.name^));
228
233
{$endif i386}
 
234
{$ifdef powerpc}
 
235
           codesegment.concat(Tai_align.create(16));
 
236
           codesegment.concat(Tai_symbol.Createname_global(hp2.name^,AT_FUNCTION,0));
 
237
           codeSegment.concat(Taicpu.Op_sym(A_B,objectlibrary.newasmsymbol(tprocsym(hp2.sym).first_procdef.mangledname,AB_EXTERNAL,AT_FUNCTION)));
 
238
           codeSegment.concat(Tai_symbol_end.Createname(hp2.name^));
 
239
{$endif powerpc}
229
240
         end;
230
241
      end
231
242
     else
232
 
      Message1(parser_e_no_export_of_variables_for_target,'freebsd');
 
243
      Message1(parser_e_no_export_of_variables_for_target,'*bsd/darwin');
233
244
     hp2:=texported_item(hp2.next);
234
245
   end;
235
246
end;
262
273
   begin
263
274
     if LdSupportsNoResponseFile then
264
275
       begin
265
 
         ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE `cat $RES`';
 
276
         if (target_info.system <> system_powerpc_darwin) then
 
277
           begin
 
278
             ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE `cat $RES`';
 
279
             DllCmd[1]:='ld $OPT -shared -L. -o $EXE `cat $RES`'
 
280
           end
 
281
         else
 
282
           begin
 
283
             ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE `cat $RES`';
 
284
             DllCmd[1]:='libtool $OPT -dynamic -init _PASCALMAIN -multiply_defined suppress  -L. -o $EXE `cat $RES`'
 
285
           end
266
286
       end
267
287
     else
268
 
       ExeCmd[1]:='ld $OPT $DYNLINK $STATIC  $GCSECTIONS $STRIP -L. -o $EXE $RES';
269
 
     DllCmd[1]:='ld $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
270
 
     DllCmd[2]:='strip --strip-unneeded $EXE';
271
 
     { first try glibc2 }
272
 
{$ifdef GLIBC2} {Keep linux code in place. FBSD might go to a different
273
 
                                glibc too once}
274
 
     DynamicLinker:='/lib/ld-linux.so.2';
275
 
     if FileExists(DynamicLinker) then
276
 
      begin
277
 
        Glibc2:=true;
278
 
        { Check for 2.0 files, else use the glibc 2.1 stub }
279
 
        if FileExists('/lib/ld-2.0.*') then
280
 
         Glibc21:=false
281
 
        else
282
 
         Glibc21:=true;
283
 
      end
 
288
       begin
 
289
         ExeCmd[1]:='ld $OPT $DYNLINK $STATIC  $GCSECTIONS $STRIP -L. -o $EXE $RES';
 
290
         DllCmd[1]:='ld $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
 
291
       end;
 
292
     if (target_info.system <> system_powerpc_darwin) then
 
293
       DllCmd[2]:='strip --strip-unneeded $EXE'
284
294
     else
285
 
      DynamicLinker:='/lib/ld-linux.so.1';
286
 
{$else}
 
295
       DllCmd[2]:='strip -x $EXE';
287
296
      DynamicLinker:='';
288
 
{$endif}
289
297
   end;
290
298
end;
291
299
 
 
300
procedure TLinkerBSD.LoadPredefinedLibraryOrder;
 
301
// put your linkorder/linkalias overrides here. 
 
302
// Note: assumes only called when reordering/aliasing is used.
 
303
Begin
 
304
  if not(target_info.system in [system_powerpc_darwin,system_i386_darwin]) then
 
305
    begin
 
306
      if (target_info.system =system_i386_freebsd) and 
 
307
             not (cs_link_no_default_lib_order in  aktglobalswitches) Then   
 
308
        Begin
 
309
          LinkLibraryOrder.add('gcc','',15);            
 
310
          LinkLibraryOrder.add('c','',50);                   // c and c_p mutual. excl? 
 
311
          LinkLibraryOrder.add('c_p','',55);                    
 
312
          LinkLibraryOrder.add('pthread','',75);             // pthread and c_r should be mutually exclusive
 
313
          LinkLibraryOrder.add('c_r','',76);                            
 
314
          LinkLibraryOrder.add('kvm','',80);                 // must be before ncurses
 
315
          if (cs_link_pthread in aktglobalswitches) Then     // convert libpthread to libc_r.
 
316
            LinkLibraryAliases.add('pthread','c_r');
 
317
        end;
 
318
    end
 
319
else
 
320
    begin
 
321
          LinkLibraryOrder.add('gcc','',15);            
 
322
          LinkLibraryOrder.add('c','',50);
 
323
   end;
 
324
End;
292
325
 
293
326
Function TLinkerBSD.WriteResponseFile(isdll:boolean) : Boolean;
294
327
Var
303
336
  linkdynamic,
304
337
  linklibc     : boolean;
305
338
  Fl1,Fl2      : Boolean;
306
 
 
 
339
  IsDarwin     : Boolean;
 
340
  ReOrder      : Boolean;
 
341
  
307
342
begin
308
343
  WriteResponseFile:=False;
 
344
  ReOrder:=False;
 
345
  IsDarwin:=target_info.system in [system_powerpc_darwin,system_i386_darwin];
309
346
{ set special options for some targets }
310
 
  if target_info.system <> system_powerpc_darwin then
 
347
  if not IsDarwin Then
311
348
    begin
312
 
      linkdynamic:=not(SharedLibFiles.empty);
313
 
      linklibc:=(SharedLibFiles.Find('c')<>nil);
314
 
      linkpthread:=(SharedLibFiles.Find('pthread')<>nil);
315
 
      if (target_info.system =system_i386_freebsd) and linkpthread Then
316
 
        Begin
317
 
          if not (cs_link_pthread in aktglobalswitches) Then
318
 
            begin
319
 
              {delete pthreads from list, in this case it is in libc_r}
320
 
              SharedLibFiles.Remove(SharedLibFiles.Find('pthread').str);
321
 
              LibrarySuffix:='r';
322
 
            end;
323
 
        End;
324
349
      prtobj:='prt0';
325
350
      cprtobj:='cprt0';
326
351
      gprtobj:='gprt0';
 
352
      linkdynamic:=not(SharedLibFiles.empty);
 
353
      linklibc:=(SharedLibFiles.Find('c')<>nil);
 
354
      // this one is a bit complex.
 
355
      // Only reorder for now if -XL or -XO params are given
 
356
      // or when -Xf.
 
357
      reorder:= linklibc and
 
358
                ( 
 
359
                  ReorderEntries
 
360
                   or
 
361
                  (cs_link_pthread in aktglobalswitches));
327
362
      if cs_profile in aktmoduleswitches then
328
363
       begin
329
364
         prtobj:=gprtobj;
336
371
         if linklibc then
337
372
          prtobj:=cprtobj;
338
373
       end;
 
374
      // after this point addition of shared libs not allowed.  
339
375
    end
340
376
  else
341
377
    begin
342
 
      { for darwin: always link dynamically against libc�}
 
378
      { for darwin: always link dynamically against libc }
343
379
      linklibc := true;
344
 
      if not(cs_profile in aktmoduleswitches) then
345
 
        prtobj:='/usr/lib/crt1.o'
 
380
      reorder:=reorderentries;
 
381
      if not(isdll) then
 
382
        if not(cs_profile in aktmoduleswitches) then
 
383
          begin
 
384
             if librarysearchpath.FindFile('crt1.o',s) then
 
385
             prtobj:=s
 
386
            else
 
387
             prtobj:='/usr/lib/crt1.o';
 
388
          end
 
389
        else
 
390
          prtobj:='/usr/lib/gcrt1.o'
346
391
      else
347
 
        prtobj:='/usr/lib/gcrt1.o';
 
392
        prtobj:='';
348
393
    end;
349
394
 
 
395
  if reorder Then
 
396
     ExpandAndApplyOrder(SharedLibFiles);
350
397
 
351
398
  { Open link.res file }
352
399
  LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
353
400
 
 
401
  if (not isdll) then
 
402
    begin
 
403
      case target_info.system of
 
404
        system_powerpc_darwin:
 
405
           LinkRes.Add('-arch ppc');
 
406
        system_i386_darwin:
 
407
           LinkRes.Add('-arch i386');
 
408
      end;
 
409
  end;
354
410
  { Write path to search libraries }
355
411
  HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
356
412
  while assigned(HPath) do
378
434
   LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
379
435
  { try to add crti and crtbegin if linking to C }
380
436
  if linklibc and
381
 
     (target_info.system <> system_powerpc_darwin) then
 
437
     not IsDarwin Then
382
438
   begin
383
439
     if librarysearchpath.FindFile('crtbegin.o',s) then
384
440
      LinkRes.AddFileName(s);
418
474
     While not SharedLibFiles.Empty do
419
475
      begin
420
476
        S:=SharedLibFiles.GetFirst;
421
 
        if s<>'c' then
 
477
        if (s<>'c') or reorder then
422
478
         begin
423
479
           i:=Pos(target_info.sharedlibext,S);
424
480
           if i>0 then
432
488
         end;
433
489
      end;
434
490
     { be sure that libc is the last lib }
435
 
     if linklibc then
 
491
     if linklibc and not reorder then
436
492
       Begin
437
493
         If LibrarySuffix=' ' Then
438
494
          LinkRes.Add('-lc')
451
507
   end;
452
508
  { objects which must be at the end }
453
509
  if linklibc and
454
 
     (target_info.system <> system_powerpc_darwin) then
 
510
     not IsDarwin Then
455
511
   begin
456
512
     Fl1:=librarysearchpath.FindFile('crtend.o',s1);
457
513
     Fl2:=librarysearchpath.FindFile('crtn.o',s2);
465
521
        LinkRes.Add(')');
466
522
      end;
467
523
   end;
 
524
  { ignore the fact that our relocations are in non-writable sections, }
 
525
  { will be fixed once we have pic support                             }
 
526
  if isdll and IsDarwin Then
 
527
    LinkRes.Add('-read_only_relocs suppress');
468
528
{ Write and Close response }
469
529
  linkres.writetodisk;
470
530
  linkres.Free;
515
575
   DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
516
576
 
517
577
  if CShared Then
518
 
   DynLinKStr:=DynLinkStr+' --shared';
 
578
   begin
 
579
   if  (target_info.system <> system_powerpc_darwin) then
 
580
     DynLinKStr:=DynLinkStr+' --shared'
 
581
    else
 
582
     DynLinKStr:=DynLinkStr+' -dynamic'; // one dash!
 
583
   end;  
519
584
{ Write used files and libraries }
520
585
  WriteResponseFile(false);
521
586
 
560
625
 
561
626
{ Call linker }
562
627
  SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
 
628
{$ifndef darwin}
563
629
  Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
 
630
{$else darwin}
 
631
{$ifdef USE_SYSUTILS}
 
632
  Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename^)));
 
633
{$else USE_SYSUTILS}
 
634
  Replace(cmdstr,'$EXE',maybequoted(FExpand(current_module.sharedlibfilename^)));
 
635
{$endif USE_SYSUTILS}
 
636
{$endif darwin}
564
637
  Replace(cmdstr,'$OPT',Info.ExtraOptions);
565
638
  Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
566
639
  Replace(cmdstr,'$INIT',InitStr);
567
640
  Replace(cmdstr,'$FINI',FiniStr);
568
641
  Replace(cmdstr,'$SONAME',SoNameStr);
569
642
 
570
 
  success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
 
643
  success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,LdSupportsNoResponseFile);
571
644
 
572
645
{ Strip the library ? }
573
646
  if success and (cs_link_strip in aktglobalswitches) then
629
702
  RegisterTarget(system_powerpc_netbsd_info);
630
703
{$endif powerpc}
631
704
end.
632
 
{
633
 
  $Log: t_bsd.pas,v $
634
 
  Revision 1.30  2005/04/27 21:47:08  marco
635
 
   * $GCSECTIONS also added to else case
636
 
 
637
 
  Revision 1.29  2005/04/27 14:47:54  marco
638
 
   * tf_smartlink_sections and some shared lib pull-ups from t_linux
639
 
 
640
 
  Revision 1.28  2005/02/14 17:13:10  peter
641
 
    * truncate log
642
 
 
643
 
}