Implement -mmemcpy-strategy= and -mmemset-strategy= options
[official-gcc.git] / gcc / ada / gnatlink.adb
blob503c2f7b15263e7120e97187a1c30b4f979e7af7
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T L I N K --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1996-2013, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- Gnatlink usage: please consult the gnat documentation
28 with ALI; use ALI;
29 with Csets;
30 with Gnatvsn; use Gnatvsn;
31 with Hostparm;
32 with Indepsw; use Indepsw;
33 with Namet; use Namet;
34 with Opt;
35 with Osint; use Osint;
36 with Output; use Output;
37 with Snames;
38 with Switch; use Switch;
39 with System; use System;
40 with Table;
41 with Targparm; use Targparm;
42 with Types;
44 with Ada.Command_Line; use Ada.Command_Line;
45 with Ada.Exceptions; use Ada.Exceptions;
47 with System.OS_Lib; use System.OS_Lib;
48 with System.CRTL;
50 with Interfaces.C_Streams; use Interfaces.C_Streams;
51 with Interfaces.C.Strings; use Interfaces.C.Strings;
53 procedure Gnatlink is
54 pragma Ident (Gnatvsn.Gnat_Static_Version_String);
56 Shared_Libgcc_String : constant String := "-shared-libgcc";
57 Shared_Libgcc : constant String_Access :=
58 new String'(Shared_Libgcc_String);
59 -- Used to invoke gcc when the binder is invoked with -shared
61 Static_Libgcc_String : constant String := "-static-libgcc";
62 Static_Libgcc : constant String_Access :=
63 new String'(Static_Libgcc_String);
64 -- Used to invoke gcc when shared libs are not used
66 package Gcc_Linker_Options is new Table.Table (
67 Table_Component_Type => String_Access,
68 Table_Index_Type => Integer,
69 Table_Low_Bound => 1,
70 Table_Initial => 20,
71 Table_Increment => 100,
72 Table_Name => "Gnatlink.Gcc_Linker_Options");
73 -- Comments needed ???
75 package Libpath is new Table.Table (
76 Table_Component_Type => Character,
77 Table_Index_Type => Integer,
78 Table_Low_Bound => 1,
79 Table_Initial => 4096,
80 Table_Increment => 100,
81 Table_Name => "Gnatlink.Libpath");
82 -- Comments needed ???
84 package Linker_Options is new Table.Table (
85 Table_Component_Type => String_Access,
86 Table_Index_Type => Integer,
87 Table_Low_Bound => 1,
88 Table_Initial => 20,
89 Table_Increment => 100,
90 Table_Name => "Gnatlink.Linker_Options");
91 -- Comments needed ???
93 package Linker_Objects is new Table.Table (
94 Table_Component_Type => String_Access,
95 Table_Index_Type => Integer,
96 Table_Low_Bound => 1,
97 Table_Initial => 20,
98 Table_Increment => 100,
99 Table_Name => "Gnatlink.Linker_Objects");
100 -- This table collects the objects file to be passed to the linker. In the
101 -- case where the linker command line is too long then programs objects
102 -- are put on the Response_File_Objects table. Note that the binder object
103 -- file and the user's objects remain in this table. This is very
104 -- important because on the GNU linker command line the -L switch is not
105 -- used to look for objects files but -L switch is used to look for
106 -- objects listed in the response file. This is not a problem with the
107 -- applications objects as they are specified with a full name.
109 package Response_File_Objects is new Table.Table (
110 Table_Component_Type => String_Access,
111 Table_Index_Type => Integer,
112 Table_Low_Bound => 1,
113 Table_Initial => 20,
114 Table_Increment => 100,
115 Table_Name => "Gnatlink.Response_File_Objects");
116 -- This table collects the objects file that are to be put in the response
117 -- file. Only application objects are collected there (see details in
118 -- Linker_Objects table comments)
120 package Binder_Options_From_ALI is new Table.Table (
121 Table_Component_Type => String_Access,
122 Table_Index_Type => Integer,
123 Table_Low_Bound => 1, -- equals low bound of Argument_List for Spawn
124 Table_Initial => 20,
125 Table_Increment => 100,
126 Table_Name => "Gnatlink.Binder_Options_From_ALI");
127 -- This table collects the switches from the ALI file of the main
128 -- subprogram.
130 package Binder_Options is new Table.Table (
131 Table_Component_Type => String_Access,
132 Table_Index_Type => Integer,
133 Table_Low_Bound => 1, -- equals low bound of Argument_List for Spawn
134 Table_Initial => 20,
135 Table_Increment => 100,
136 Table_Name => "Gnatlink.Binder_Options");
137 -- This table collects the arguments to be passed to compile the binder
138 -- generated file.
140 Gcc : String_Access := Program_Name ("gcc", "gnatlink");
142 Read_Mode : constant String := "r" & ASCII.NUL;
144 Begin_Info : constant String := "-- BEGIN Object file/option list";
145 End_Info : constant String := "-- END Object file/option list ";
147 Gcc_Path : String_Access;
148 Linker_Path : String_Access;
149 Output_File_Name : String_Access;
150 Ali_File_Name : String_Access;
151 Binder_Spec_Src_File : String_Access;
152 Binder_Body_Src_File : String_Access;
153 Binder_Ali_File : String_Access;
154 Binder_Obj_File : String_Access;
156 Base_Command_Name : String_Access;
158 Tname : Temp_File_Name;
159 Tname_FD : File_Descriptor := Invalid_FD;
160 -- Temporary file used by linker to pass list of object files on
161 -- certain systems with limitations on size of arguments.
163 Debug_Flag_Present : Boolean := False;
164 Verbose_Mode : Boolean := False;
165 Very_Verbose_Mode : Boolean := False;
167 Standard_Gcc : Boolean := True;
169 Compile_Bind_File : Boolean := True;
170 -- Set to False if bind file is not to be compiled
172 Create_Map_File : Boolean := False;
173 -- Set to True by switch -M. The map file name is derived from
174 -- the ALI file name (mainprog.ali => mainprog.map).
176 Object_List_File_Supported : Boolean;
177 for Object_List_File_Supported'Size use Character'Size;
178 pragma Import
179 (C, Object_List_File_Supported, "__gnat_objlist_file_supported");
180 -- Predicate indicating whether the linker has an option whereby the
181 -- names of object files can be passed to the linker in a file.
183 Object_File_Option_Ptr : Interfaces.C.Strings.chars_ptr;
184 pragma Import (C, Object_File_Option_Ptr, "__gnat_object_file_option");
185 -- Pointer to a string representing the linker option which specifies
186 -- the response file.
188 Object_File_Option : constant String := Value (Object_File_Option_Ptr);
189 -- The linker option which specifies the response file as a string
191 Using_GNU_response_file : constant Boolean :=
192 Object_File_Option'Length > 0
193 and then Object_File_Option (Object_File_Option'Last) = '@';
194 -- Whether a GNU response file is used
196 Object_List_File_Required : Boolean := False;
197 -- Set to True to force generation of a response file
199 Shared_Libgcc_Default : Character;
200 for Shared_Libgcc_Default'Size use Character'Size;
201 pragma Import
202 (C, Shared_Libgcc_Default, "__gnat_shared_libgcc_default");
203 -- Indicates wether libgcc should be statically linked (use 'T') or
204 -- dynamically linked (use 'H') by default.
206 function Base_Name (File_Name : String) return String;
207 -- Return just the file name part without the extension (if present)
209 procedure Check_Existing_Executable (File_Name : String);
210 -- Delete any existing executable to avoid accidentally updating the target
211 -- of a symbolic link, but produce a Fatail_Error if File_Name matches any
212 -- of the source file names. This avoids overwriting of extensionless
213 -- source files by accident on systems where executables do not have
214 -- extensions.
216 procedure Delete (Name : String);
217 -- Wrapper to unlink as status is ignored by this application
219 procedure Error_Msg (Message : String);
220 -- Output the error or warning Message
222 procedure Exit_With_Error (Error : String);
223 -- Output Error and exit program with a fatal condition
225 procedure Process_Args;
226 -- Go through all the arguments and build option tables
228 procedure Process_Binder_File (Name : String);
229 -- Reads the binder file and extracts linker arguments
231 function To_Lower (A : Character) return Character;
232 -- Fold a character to lower case;
234 procedure To_Lower (A : in out String);
235 -- Fold a string to lower case;
237 procedure Usage;
238 -- Display usage
240 procedure Write_Header;
241 -- Show user the program name, version and copyright
243 procedure Write_Usage;
244 -- Show user the program options
246 ---------------
247 -- Base_Name --
248 ---------------
250 function Base_Name (File_Name : String) return String is
251 Findex1 : Natural;
252 Findex2 : Natural;
254 begin
255 Findex1 := File_Name'First;
257 -- The file might be specified by a full path name. However,
258 -- we want the path to be stripped away.
260 for J in reverse File_Name'Range loop
261 if Is_Directory_Separator (File_Name (J)) then
262 Findex1 := J + 1;
263 exit;
264 end if;
265 end loop;
267 Findex2 := File_Name'Last;
268 while Findex2 > Findex1
269 and then File_Name (Findex2) /= '.'
270 loop
271 Findex2 := Findex2 - 1;
272 end loop;
274 if Findex2 = Findex1 then
275 Findex2 := File_Name'Last + 1;
276 end if;
278 return File_Name (Findex1 .. Findex2 - 1);
279 end Base_Name;
281 -------------------------------
282 -- Check_Existing_Executable --
283 -------------------------------
285 procedure Check_Existing_Executable (File_Name : String) is
286 Ename : String := File_Name;
287 Efile : File_Name_Type;
288 Sfile : File_Name_Type;
290 begin
291 Canonical_Case_File_Name (Ename);
292 Name_Len := 0;
293 Add_Str_To_Name_Buffer (Ename);
294 Efile := Name_Find;
296 for J in Units.Table'First .. Units.Last loop
297 Sfile := Units.Table (J).Sfile;
298 if Sfile = Efile then
299 Exit_With_Error ("executable name """ & File_Name & """ matches "
300 & "source file name """ & Get_Name_String (Sfile) & """");
301 end if;
302 end loop;
304 Delete (File_Name);
305 end Check_Existing_Executable;
307 ------------
308 -- Delete --
309 ------------
311 procedure Delete (Name : String) is
312 Status : int;
313 pragma Unreferenced (Status);
314 begin
315 Status := unlink (Name'Address);
316 -- Is it really right to ignore an error here ???
317 end Delete;
319 ---------------
320 -- Error_Msg --
321 ---------------
323 procedure Error_Msg (Message : String) is
324 begin
325 Write_Str (Base_Command_Name.all);
326 Write_Str (": ");
327 Write_Str (Message);
328 Write_Eol;
329 end Error_Msg;
331 ---------------------
332 -- Exit_With_Error --
333 ---------------------
335 procedure Exit_With_Error (Error : String) is
336 begin
337 Error_Msg (Error);
338 Exit_Program (E_Fatal);
339 end Exit_With_Error;
341 ------------------
342 -- Process_Args --
343 ------------------
345 procedure Process_Args is
346 Next_Arg : Integer;
347 Skip_Next : Boolean := False;
348 -- Set to true if the next argument is to be added into the list of
349 -- linker's argument without parsing it.
351 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
353 -- Start of processing for Process_Args
355 begin
356 -- First, check for --version and --help
358 Check_Version_And_Help ("GNATLINK", "1995");
360 -- Loop through arguments of gnatlink command
362 Next_Arg := 1;
363 loop
364 exit when Next_Arg > Argument_Count;
366 Process_One_Arg : declare
367 Arg : constant String := Argument (Next_Arg);
369 begin
370 -- Case of argument which is a switch
372 -- We definitely need section by section comments here ???
374 if Skip_Next then
376 -- This argument must not be parsed, just add it to the
377 -- list of linker's options.
379 Skip_Next := False;
381 Linker_Options.Increment_Last;
382 Linker_Options.Table (Linker_Options.Last) :=
383 new String'(Arg);
385 elsif Arg'Length /= 0 and then Arg (1) = '-' then
386 if Arg'Length > 4 and then Arg (2 .. 5) = "gnat" then
387 Exit_With_Error
388 ("invalid switch: """ & Arg & """ (gnat not needed here)");
389 end if;
391 if Arg = "-Xlinker" then
393 -- Next argument should be sent directly to the linker.
394 -- We do not want to parse it here.
396 Skip_Next := True;
398 Linker_Options.Increment_Last;
399 Linker_Options.Table (Linker_Options.Last) :=
400 new String'(Arg);
402 elsif Arg (2) = 'g'
403 and then (Arg'Length < 5 or else Arg (2 .. 5) /= "gnat")
404 then
405 Debug_Flag_Present := True;
407 Linker_Options.Increment_Last;
408 Linker_Options.Table (Linker_Options.Last) :=
409 new String'(Arg);
411 Binder_Options.Increment_Last;
412 Binder_Options.Table (Binder_Options.Last) :=
413 Linker_Options.Table (Linker_Options.Last);
415 elsif Arg'Length >= 3 and then Arg (2) = 'M' then
416 declare
417 Switches : String_List_Access;
419 begin
420 Convert (Map_File, Arg (3 .. Arg'Last), Switches);
422 if Switches /= null then
423 for J in Switches'Range loop
424 Linker_Options.Increment_Last;
425 Linker_Options.Table (Linker_Options.Last) :=
426 Switches (J);
427 end loop;
428 end if;
429 end;
431 elsif Arg'Length = 2 then
432 case Arg (2) is
433 when 'b' =>
434 Linker_Options.Increment_Last;
435 Linker_Options.Table (Linker_Options.Last) :=
436 new String'(Arg);
438 Binder_Options.Increment_Last;
439 Binder_Options.Table (Binder_Options.Last) :=
440 Linker_Options.Table (Linker_Options.Last);
442 Next_Arg := Next_Arg + 1;
444 if Next_Arg > Argument_Count then
445 Exit_With_Error ("Missing argument for -b");
446 end if;
448 Get_Machine_Name : declare
449 Name_Arg : constant String_Access :=
450 new String'(Argument (Next_Arg));
452 begin
453 Linker_Options.Increment_Last;
454 Linker_Options.Table (Linker_Options.Last) :=
455 Name_Arg;
457 Binder_Options.Increment_Last;
458 Binder_Options.Table (Binder_Options.Last) :=
459 Name_Arg;
461 end Get_Machine_Name;
463 when 'f' =>
464 if Object_List_File_Supported then
465 Object_List_File_Required := True;
466 else
467 Exit_With_Error
468 ("Object list file not supported on this target");
469 end if;
471 when 'M' =>
472 Create_Map_File := True;
474 when 'n' =>
475 Compile_Bind_File := False;
477 when 'o' =>
478 Next_Arg := Next_Arg + 1;
480 if Next_Arg > Argument_Count then
481 Exit_With_Error ("Missing argument for -o");
482 end if;
484 Output_File_Name :=
485 new String'(Executable_Name
486 (Argument (Next_Arg),
487 Only_If_No_Suffix => True));
489 when 'P' =>
490 Opt.CodePeer_Mode := True;
492 when 'R' =>
493 Opt.Run_Path_Option := False;
495 when 'v' =>
497 -- Support "double" verbose mode. Second -v
498 -- gets sent to the linker and binder phases.
500 if Verbose_Mode then
501 Very_Verbose_Mode := True;
503 Linker_Options.Increment_Last;
504 Linker_Options.Table (Linker_Options.Last) :=
505 new String'(Arg);
507 Binder_Options.Increment_Last;
508 Binder_Options.Table (Binder_Options.Last) :=
509 Linker_Options.Table (Linker_Options.Last);
511 else
512 Verbose_Mode := True;
514 end if;
516 when others =>
517 Linker_Options.Increment_Last;
518 Linker_Options.Table (Linker_Options.Last) :=
519 new String'(Arg);
521 end case;
523 elsif Arg (2) = 'B' then
524 Linker_Options.Increment_Last;
525 Linker_Options.Table (Linker_Options.Last) :=
526 new String'(Arg);
528 Binder_Options.Increment_Last;
529 Binder_Options.Table (Binder_Options.Last) :=
530 Linker_Options.Table (Linker_Options.Last);
532 elsif Arg'Length >= 7 and then Arg (1 .. 7) = "--LINK=" then
533 if Arg'Length = 7 then
534 Exit_With_Error ("Missing argument for --LINK=");
535 end if;
537 Linker_Path :=
538 System.OS_Lib.Locate_Exec_On_Path (Arg (8 .. Arg'Last));
540 if Linker_Path = null then
541 Exit_With_Error
542 ("Could not locate linker: " & Arg (8 .. Arg'Last));
543 end if;
545 elsif Arg'Length > 6 and then Arg (1 .. 6) = "--GCC=" then
546 declare
547 Program_Args : constant Argument_List_Access :=
548 Argument_String_To_List
549 (Arg (7 .. Arg'Last));
551 begin
552 if Program_Args.all (1).all /= Gcc.all then
553 Gcc := new String'(Program_Args.all (1).all);
554 Standard_Gcc := False;
555 end if;
557 -- Set appropriate flags for switches passed
559 for J in 2 .. Program_Args.all'Last loop
560 declare
561 Arg : constant String := Program_Args.all (J).all;
562 AF : constant Integer := Arg'First;
564 begin
565 if Arg'Length /= 0 and then Arg (AF) = '-' then
566 if Arg (AF + 1) = 'g'
567 and then (Arg'Length = 2
568 or else Arg (AF + 2) in '0' .. '3'
569 or else Arg (AF + 2 .. Arg'Last) = "coff")
570 then
571 Debug_Flag_Present := True;
572 end if;
573 end if;
575 -- Add directory to source search dirs so that
576 -- Get_Target_Parameters can find system.ads
578 if Arg (AF .. AF + 1) = "-I"
579 and then Arg'Length > 2
580 then
581 Add_Src_Search_Dir (Arg (AF + 2 .. Arg'Last));
582 end if;
584 -- Pass to gcc for compiling binder generated file
585 -- No use passing libraries, it will just generate
586 -- a warning
588 if not (Arg (AF .. AF + 1) = "-l"
589 or else Arg (AF .. AF + 1) = "-L")
590 then
591 Binder_Options.Increment_Last;
592 Binder_Options.Table (Binder_Options.Last) :=
593 new String'(Arg);
594 end if;
596 -- Pass to gcc for linking program
598 Gcc_Linker_Options.Increment_Last;
599 Gcc_Linker_Options.Table
600 (Gcc_Linker_Options.Last) := new String'(Arg);
601 end;
602 end loop;
603 end;
605 -- Send all multi-character switches not recognized as
606 -- a special case by gnatlink to the linker/loader stage.
608 else
609 Linker_Options.Increment_Last;
610 Linker_Options.Table (Linker_Options.Last) :=
611 new String'(Arg);
612 end if;
614 -- Here if argument is a file name rather than a switch
616 else
617 -- If explicit ali file, capture it
619 if Arg'Length > 4
620 and then Arg (Arg'Last - 3 .. Arg'Last) = ".ali"
621 then
622 if Ali_File_Name = null then
623 Ali_File_Name := new String'(Arg);
624 else
625 Exit_With_Error ("cannot handle more than one ALI file");
626 end if;
628 -- If target object file, record object file
630 elsif Arg'Length > Get_Target_Object_Suffix.all'Length
631 and then Arg
632 (Arg'Last -
633 Get_Target_Object_Suffix.all'Length + 1 .. Arg'Last)
634 = Get_Target_Object_Suffix.all
635 then
636 Linker_Objects.Increment_Last;
637 Linker_Objects.Table (Linker_Objects.Last) :=
638 new String'(Arg);
640 -- If host object file, record object file
641 -- e.g. accept foo.o as well as foo.obj on VMS target
643 elsif Arg'Length > Get_Object_Suffix.all'Length
644 and then Arg
645 (Arg'Last - Get_Object_Suffix.all'Length + 1 .. Arg'Last)
646 = Get_Object_Suffix.all
647 then
648 Linker_Objects.Increment_Last;
649 Linker_Objects.Table (Linker_Objects.Last) :=
650 new String'(Arg);
652 -- If corresponding ali file exists, capture it
654 elsif Ali_File_Name = null
655 and then Is_Regular_File (Arg & ".ali")
656 then
657 Ali_File_Name := new String'(Arg & ".ali");
659 -- Otherwise assume this is a linker options entry, but
660 -- see below for interesting adjustment to this assumption.
662 else
663 Linker_Options.Increment_Last;
664 Linker_Options.Table (Linker_Options.Last) :=
665 new String'(Arg);
666 end if;
667 end if;
668 end Process_One_Arg;
670 Next_Arg := Next_Arg + 1;
671 end loop;
673 -- Compile the bind file with warnings suppressed, because
674 -- otherwise the with of the main program may cause junk warnings.
676 Binder_Options.Increment_Last;
677 Binder_Options.Table (Binder_Options.Last) := new String'("-gnatws");
679 -- If we did not get an ali file at all, and we had at least one
680 -- linker option, then assume that was the intended ali file after
681 -- all, so that we get a nicer message later on.
683 if Ali_File_Name = null
684 and then Linker_Options.Last >= Linker_Options.First
685 then
686 Ali_File_Name :=
687 new String'(Linker_Options.Table (Linker_Options.First).all &
688 ".ali");
689 end if;
690 end Process_Args;
692 -------------------------
693 -- Process_Binder_File --
694 -------------------------
696 procedure Process_Binder_File (Name : String) is
697 Fd : FILEs;
698 -- Binder file's descriptor
700 Link_Bytes : Integer := 0;
701 -- Projected number of bytes for the linker command line
703 Link_Max : Integer;
704 pragma Import (C, Link_Max, "__gnat_link_max");
705 -- Maximum number of bytes on the command line supported by the OS
706 -- linker. Passed this limit the response file mechanism must be used
707 -- if supported.
709 Next_Line : String (1 .. 1000);
710 -- Current line value
712 Nlast : Integer;
713 Nfirst : Integer;
714 -- Current line slice (the slice does not contain line terminator)
716 Last : Integer;
717 -- Current line last character for shared libraries (without version)
719 Objs_Begin : Integer := 0;
720 -- First object file index in Linker_Objects table
722 Objs_End : Integer := 0;
723 -- Last object file index in Linker_Objects table
725 Status : int;
726 pragma Warnings (Off, Status);
727 -- Used for various Interfaces.C_Streams calls
729 Closing_Status : Boolean;
730 pragma Warnings (Off, Closing_Status);
731 -- For call to Close
733 GNAT_Static : Boolean := False;
734 -- Save state of -static option
736 GNAT_Shared : Boolean := False;
737 -- Save state of -shared option
739 Xlinker_Was_Previous : Boolean := False;
740 -- Indicate that "-Xlinker" was the option preceding the current
741 -- option. If True, then the current option is never suppressed.
743 -- Rollback data
745 -- These data items are used to store current binder file context.
746 -- The context is composed of the file descriptor position and the
747 -- current line together with the slice indexes (first and last
748 -- position) for this line. The rollback data are used by the
749 -- Store_File_Context and Rollback_File_Context routines below.
750 -- The file context mechanism interact only with the Get_Next_Line
751 -- call. For example:
753 -- Store_File_Context;
754 -- Get_Next_Line;
755 -- Rollback_File_Context;
756 -- Get_Next_Line;
758 -- Both Get_Next_Line calls above will read the exact same data from
759 -- the file. In other words, Next_Line, Nfirst and Nlast variables
760 -- will be set with the exact same values.
762 RB_File_Pos : long; -- File position
763 RB_Next_Line : String (1 .. 1000); -- Current line content
764 RB_Nlast : Integer; -- Slice last index
765 RB_Nfirst : Integer; -- Slice first index
767 Run_Path_Option_Ptr : Interfaces.C.Strings.chars_ptr;
768 pragma Import (C, Run_Path_Option_Ptr, "__gnat_run_path_option");
769 -- Pointer to string representing the native linker option which
770 -- specifies the path where the dynamic loader should find shared
771 -- libraries. Equal to null string if this system doesn't support it.
773 Libgcc_Subdir_Ptr : Interfaces.C.Strings.chars_ptr;
774 pragma Import (C, Libgcc_Subdir_Ptr, "__gnat_default_libgcc_subdir");
775 -- Pointer to string indicating the installation subdirectory where
776 -- a default shared libgcc might be found.
778 Object_Library_Ext_Ptr : Interfaces.C.Strings.chars_ptr;
779 pragma Import
780 (C, Object_Library_Ext_Ptr, "__gnat_object_library_extension");
781 -- Pointer to string specifying the default extension for
782 -- object libraries, e.g. Unix uses ".a", VMS uses ".olb".
784 Separate_Run_Path_Options : Boolean;
785 for Separate_Run_Path_Options'Size use Character'Size;
786 pragma Import
787 (C, Separate_Run_Path_Options, "__gnat_separate_run_path_options");
788 -- Whether separate rpath options should be emitted for each directory
790 procedure Get_Next_Line;
791 -- Read the next line from the binder file without the line
792 -- terminator.
794 function Index (S, Pattern : String) return Natural;
795 -- Return the last occurrence of Pattern in S, or 0 if none
797 function Is_Option_Present (Opt : String) return Boolean;
798 -- Return true if the option Opt is already present in
799 -- Linker_Options table.
801 procedure Store_File_Context;
802 -- Store current file context, Fd position and current line data.
803 -- The file context is stored into the rollback data above (RB_*).
804 -- Store_File_Context can be called at any time, only the last call
805 -- will be used (i.e. this routine overwrites the file context).
807 procedure Rollback_File_Context;
808 -- Restore file context from rollback data. This routine must be called
809 -- after Store_File_Context. The binder file context will be restored
810 -- with the data stored by the last Store_File_Context call.
812 procedure Write_RF (S : String);
813 -- Write a string to the response file and check if it was successful.
814 -- Fail the program if it was not successful (disk full).
816 -------------------
817 -- Get_Next_Line --
818 -------------------
820 procedure Get_Next_Line is
821 Fchars : chars;
823 begin
824 Fchars := fgets (Next_Line'Address, Next_Line'Length, Fd);
826 if Fchars = System.Null_Address then
827 Exit_With_Error ("Error reading binder output");
828 end if;
830 Nfirst := Next_Line'First;
831 Nlast := Nfirst;
832 while Nlast <= Next_Line'Last
833 and then Next_Line (Nlast) /= ASCII.LF
834 and then Next_Line (Nlast) /= ASCII.CR
835 loop
836 Nlast := Nlast + 1;
837 end loop;
839 Nlast := Nlast - 1;
840 end Get_Next_Line;
842 -----------
843 -- Index --
844 -----------
846 function Index (S, Pattern : String) return Natural is
847 Len : constant Natural := Pattern'Length;
849 begin
850 for J in reverse S'First .. S'Last - Len + 1 loop
851 if Pattern = S (J .. J + Len - 1) then
852 return J;
853 end if;
854 end loop;
856 return 0;
857 end Index;
859 -----------------------
860 -- Is_Option_Present --
861 -----------------------
863 function Is_Option_Present (Opt : String) return Boolean is
864 begin
865 for I in 1 .. Linker_Options.Last loop
867 if Linker_Options.Table (I).all = Opt then
868 return True;
869 end if;
871 end loop;
873 return False;
874 end Is_Option_Present;
876 ---------------------------
877 -- Rollback_File_Context --
878 ---------------------------
880 procedure Rollback_File_Context is
881 begin
882 Next_Line := RB_Next_Line;
883 Nfirst := RB_Nfirst;
884 Nlast := RB_Nlast;
885 Status := fseek (Fd, RB_File_Pos, Interfaces.C_Streams.SEEK_SET);
887 if Status = -1 then
888 Exit_With_Error ("Error setting file position");
889 end if;
890 end Rollback_File_Context;
892 ------------------------
893 -- Store_File_Context --
894 ------------------------
896 procedure Store_File_Context is
897 use type System.CRTL.long;
898 begin
899 RB_Next_Line := Next_Line;
900 RB_Nfirst := Nfirst;
901 RB_Nlast := Nlast;
902 RB_File_Pos := ftell (Fd);
904 if RB_File_Pos = -1 then
905 Exit_With_Error ("Error getting file position");
906 end if;
907 end Store_File_Context;
909 --------------
910 -- Write_RF --
911 --------------
913 procedure Write_RF (S : String) is
914 Success : Boolean := True;
915 Back_Slash : constant Character := '\';
917 begin
918 -- If a GNU response file is used, space and backslash need to be
919 -- escaped because they are interpreted as a string separator and
920 -- an escape character respectively by the underlying mechanism.
921 -- On the other hand, quote and double-quote are not escaped since
922 -- they are interpreted as string delimiters on both sides.
924 if Using_GNU_response_file then
925 for J in S'Range loop
926 if S (J) = ' ' or else S (J) = '\' then
927 if Write (Tname_FD, Back_Slash'Address, 1) /= 1 then
928 Success := False;
929 end if;
930 end if;
932 if Write (Tname_FD, S (J)'Address, 1) /= 1 then
933 Success := False;
934 end if;
935 end loop;
937 else
938 if Write (Tname_FD, S'Address, S'Length) /= S'Length then
939 Success := False;
940 end if;
941 end if;
943 if Write (Tname_FD, ASCII.LF'Address, 1) /= 1 then
944 Success := False;
945 end if;
947 if not Success then
948 Exit_With_Error ("Error generating response file: disk full");
949 end if;
950 end Write_RF;
952 -- Start of processing for Process_Binder_File
954 begin
955 Fd := fopen (Name'Address, Read_Mode'Address);
957 if Fd = NULL_Stream then
958 Exit_With_Error ("Failed to open binder output");
959 end if;
961 -- Skip up to the Begin Info line
963 loop
964 Get_Next_Line;
965 exit when Next_Line (Nfirst .. Nlast) = Begin_Info;
966 end loop;
968 loop
969 Get_Next_Line;
971 -- Go to end when end line is reached (this will happen in
972 -- High_Integrity_Mode where no -L switches are generated)
974 exit when Next_Line (Nfirst .. Nlast) = End_Info;
976 Next_Line (Nfirst .. Nlast - 8) := Next_Line (Nfirst + 8 .. Nlast);
977 Nlast := Nlast - 8;
979 -- Go to next section when switches are reached
981 exit when Next_Line (1) = '-';
983 -- Otherwise we have another object file to collect
985 Linker_Objects.Increment_Last;
987 -- Mark the positions of first and last object files in case they
988 -- need to be placed with a named file on systems having linker
989 -- line limitations.
991 if Objs_Begin = 0 then
992 Objs_Begin := Linker_Objects.Last;
993 end if;
995 Linker_Objects.Table (Linker_Objects.Last) :=
996 new String'(Next_Line (Nfirst .. Nlast));
998 Link_Bytes := Link_Bytes + Nlast - Nfirst + 2;
999 -- Nlast - Nfirst + 1, for the size, plus one for the space between
1000 -- each arguments.
1001 end loop;
1003 Objs_End := Linker_Objects.Last;
1005 -- Continue to compute the Link_Bytes, the linker options are part of
1006 -- command line length.
1008 Store_File_Context;
1010 while Next_Line (Nfirst .. Nlast) /= End_Info loop
1011 Link_Bytes := Link_Bytes + Nlast - Nfirst + 2;
1012 Get_Next_Line;
1013 end loop;
1015 Rollback_File_Context;
1017 -- On systems that have limitations on handling very long linker lines
1018 -- we make use of the system linker option which takes a list of object
1019 -- file names from a file instead of the command line itself. What we do
1020 -- is to replace the list of object files by the special linker option
1021 -- which then reads the object file list from a file instead. The option
1022 -- to read from a file instead of the command line is only triggered if
1023 -- a conservative threshold is passed.
1025 if Object_List_File_Required
1026 or else (Object_List_File_Supported
1027 and then Link_Bytes > Link_Max)
1028 then
1029 -- Create a temporary file containing the Ada user object files
1030 -- needed by the link. This list is taken from the bind file and is
1031 -- output one object per line for maximal compatibility with linkers
1032 -- supporting this option.
1034 Create_Temp_File (Tname_FD, Tname);
1036 -- ??? File descriptor should be checked to not be Invalid_FD.
1037 -- ??? Status of Write and Close operations should be checked, and
1038 -- failure should occur if a status is wrong.
1040 for J in Objs_Begin .. Objs_End loop
1041 Write_RF (Linker_Objects.Table (J).all);
1043 Response_File_Objects.Increment_Last;
1044 Response_File_Objects.Table (Response_File_Objects.Last) :=
1045 Linker_Objects.Table (J);
1046 end loop;
1048 Close (Tname_FD, Closing_Status);
1050 -- Add the special objects list file option together with the name
1051 -- of the temporary file (removing the null character) to the objects
1052 -- file table.
1054 Linker_Objects.Table (Objs_Begin) :=
1055 new String'(Object_File_Option &
1056 Tname (Tname'First .. Tname'Last - 1));
1058 -- The slots containing these object file names are then removed
1059 -- from the objects table so they do not appear in the link. They are
1060 -- removed by moving up the linker options and non-Ada object files
1061 -- appearing after the Ada object list in the table.
1063 declare
1064 N : Integer;
1066 begin
1067 N := Objs_End - Objs_Begin + 1;
1069 for J in Objs_End + 1 .. Linker_Objects.Last loop
1070 Linker_Objects.Table (J - N + 1) := Linker_Objects.Table (J);
1071 end loop;
1073 Linker_Objects.Set_Last (Linker_Objects.Last - N + 1);
1074 end;
1075 end if;
1077 -- Process switches and options
1079 if Next_Line (Nfirst .. Nlast) /= End_Info then
1080 Xlinker_Was_Previous := False;
1082 loop
1083 if Xlinker_Was_Previous
1084 or else Next_Line (Nfirst .. Nlast) = "-Xlinker"
1085 then
1086 Linker_Options.Increment_Last;
1087 Linker_Options.Table (Linker_Options.Last) :=
1088 new String'(Next_Line (Nfirst .. Nlast));
1090 elsif Next_Line (Nfirst .. Nlast) = "-static" then
1091 GNAT_Static := True;
1093 elsif Next_Line (Nfirst .. Nlast) = "-shared" then
1094 GNAT_Shared := True;
1096 -- Add binder options only if not already set on the command line.
1097 -- This rule is a way to control the linker options order.
1099 -- The following test needs comments, why is it VMS specific.
1100 -- The above comment looks out of date ???
1102 elsif not (OpenVMS_On_Target
1103 and then
1104 Is_Option_Present (Next_Line (Nfirst .. Nlast)))
1105 then
1106 if Nlast > Nfirst + 2 and then
1107 Next_Line (Nfirst .. Nfirst + 1) = "-L"
1108 then
1109 -- Construct a library search path for use later to locate
1110 -- static gnatlib libraries.
1112 if Libpath.Last > 1 then
1113 Libpath.Increment_Last;
1114 Libpath.Table (Libpath.Last) := Path_Separator;
1115 end if;
1117 for I in Nfirst + 2 .. Nlast loop
1118 Libpath.Increment_Last;
1119 Libpath.Table (Libpath.Last) := Next_Line (I);
1120 end loop;
1122 Linker_Options.Increment_Last;
1124 Linker_Options.Table (Linker_Options.Last) :=
1125 new String'(Next_Line (Nfirst .. Nlast));
1127 elsif Next_Line (Nfirst .. Nlast) = "-ldecgnat"
1128 or else Next_Line (Nfirst .. Nlast) = "-lgnarl"
1129 or else Next_Line (Nfirst .. Nlast) = "-lgnat"
1130 or else Next_Line
1131 (1 .. Natural'Min (Nlast, 8 + Library_Version'Length)) =
1132 Shared_Lib ("gnarl")
1133 or else Next_Line
1134 (1 .. Natural'Min (Nlast, 7 + Library_Version'Length)) =
1135 Shared_Lib ("gnat")
1136 then
1137 -- If it is a shared library, remove the library version.
1138 -- We will be looking for the static version of the library
1139 -- as it is in the same directory as the shared version.
1141 if Next_Line (Nlast - Library_Version'Length + 1 .. Nlast)
1142 = Library_Version
1143 then
1144 -- Set Last to point to last character before the
1145 -- library version.
1147 Last := Nlast - Library_Version'Length - 1;
1148 else
1149 Last := Nlast;
1150 end if;
1152 -- Given a Gnat standard library, search the library path to
1153 -- find the library location.
1155 -- Shouldn't we abstract a proc here, we are getting awfully
1156 -- heavily nested ???
1158 declare
1159 File_Path : String_Access;
1161 Object_Lib_Extension : constant String :=
1162 Value (Object_Library_Ext_Ptr);
1164 File_Name : constant String := "lib" &
1165 Next_Line (Nfirst + 2 .. Last) &
1166 Object_Lib_Extension;
1168 Run_Path_Opt : constant String :=
1169 Value (Run_Path_Option_Ptr);
1171 GCC_Index : Natural;
1172 Run_Path_Opt_Index : Natural := 0;
1174 begin
1175 File_Path :=
1176 Locate_Regular_File (File_Name,
1177 String (Libpath.Table (1 .. Libpath.Last)));
1179 if File_Path /= null then
1180 if GNAT_Static then
1182 -- If static gnatlib found, explicitly
1183 -- specify to overcome possible linker
1184 -- default usage of shared version.
1186 Linker_Options.Increment_Last;
1188 Linker_Options.Table (Linker_Options.Last) :=
1189 new String'(File_Path.all);
1191 elsif GNAT_Shared then
1192 if Opt.Run_Path_Option then
1194 -- If shared gnatlib desired, add the
1195 -- appropriate system specific switch
1196 -- so that it can be located at runtime.
1198 if Run_Path_Opt'Length /= 0 then
1200 -- Output the system specific linker command
1201 -- that allows the image activator to find
1202 -- the shared library at runtime. Also add
1203 -- path to find libgcc_s.so, if relevant.
1205 declare
1206 Path : String (1 .. File_Path'Length + 15);
1207 Path_Last : constant Natural :=
1208 File_Path'Length;
1210 begin
1211 Path (1 .. File_Path'Length) :=
1212 File_Path.all;
1214 -- To find the location of the shared version
1215 -- of libgcc, we look for "gcc-lib" in the
1216 -- path of the library. However, this
1217 -- subdirectory is no longer present in
1218 -- recent versions of GCC. So, we look for
1219 -- the last subdirectory "lib" in the path.
1221 GCC_Index :=
1222 Index (Path (1 .. Path_Last), "gcc-lib");
1224 if GCC_Index /= 0 then
1226 -- The shared version of libgcc is
1227 -- located in the parent directory.
1229 GCC_Index := GCC_Index - 1;
1231 else
1232 GCC_Index :=
1233 Index
1234 (Path (1 .. Path_Last),
1235 "/lib/");
1237 if GCC_Index = 0 then
1238 GCC_Index :=
1239 Index (Path (1 .. Path_Last),
1240 Directory_Separator &
1241 "lib" &
1242 Directory_Separator);
1243 end if;
1245 -- If we have found a "lib" subdir in
1246 -- the path to libgnat, the possible
1247 -- shared libgcc of interest by default
1248 -- is in libgcc_subdir at the same
1249 -- level.
1251 if GCC_Index /= 0 then
1252 declare
1253 Subdir : constant String :=
1254 Value (Libgcc_Subdir_Ptr);
1255 begin
1256 Path
1257 (GCC_Index + 1 ..
1258 GCC_Index + Subdir'Length) :=
1259 Subdir;
1260 GCC_Index :=
1261 GCC_Index + Subdir'Length;
1262 end;
1263 end if;
1264 end if;
1266 -- Look for an eventual run_path_option in
1267 -- the linker switches.
1269 if Separate_Run_Path_Options then
1270 Linker_Options.Increment_Last;
1271 Linker_Options.Table
1272 (Linker_Options.Last) :=
1273 new String'
1274 (Run_Path_Opt
1275 & File_Path
1276 (1 .. File_Path'Length
1277 - File_Name'Length));
1279 if GCC_Index /= 0 then
1280 Linker_Options.Increment_Last;
1281 Linker_Options.Table
1282 (Linker_Options.Last) :=
1283 new String'
1284 (Run_Path_Opt
1285 & Path (1 .. GCC_Index));
1286 end if;
1288 else
1289 for J in reverse
1290 1 .. Linker_Options.Last
1291 loop
1292 if Linker_Options.Table (J) /= null
1293 and then
1294 Linker_Options.Table (J)'Length
1295 > Run_Path_Opt'Length
1296 and then
1297 Linker_Options.Table (J)
1298 (1 .. Run_Path_Opt'Length) =
1299 Run_Path_Opt
1300 then
1301 -- We have found an already
1302 -- specified run_path_option: we
1303 -- will add to this switch,
1304 -- because only one
1305 -- run_path_option should be
1306 -- specified.
1308 Run_Path_Opt_Index := J;
1309 exit;
1310 end if;
1311 end loop;
1313 -- If there is no run_path_option, we
1314 -- need to add one.
1316 if Run_Path_Opt_Index = 0 then
1317 Linker_Options.Increment_Last;
1318 end if;
1320 if GCC_Index = 0 then
1321 if Run_Path_Opt_Index = 0 then
1322 Linker_Options.Table
1323 (Linker_Options.Last) :=
1324 new String'
1325 (Run_Path_Opt
1326 & File_Path
1327 (1 .. File_Path'Length
1328 - File_Name'Length));
1330 else
1331 Linker_Options.Table
1332 (Run_Path_Opt_Index) :=
1333 new String'
1334 (Linker_Options.Table
1335 (Run_Path_Opt_Index).all
1336 & Path_Separator
1337 & File_Path
1338 (1 .. File_Path'Length
1339 - File_Name'Length));
1340 end if;
1342 else
1343 if Run_Path_Opt_Index = 0 then
1344 Linker_Options.Table
1345 (Linker_Options.Last) :=
1346 new String'
1347 (Run_Path_Opt
1348 & File_Path
1349 (1 .. File_Path'Length
1350 - File_Name'Length)
1351 & Path_Separator
1352 & Path (1 .. GCC_Index));
1354 else
1355 Linker_Options.Table
1356 (Run_Path_Opt_Index) :=
1357 new String'
1358 (Linker_Options.Table
1359 (Run_Path_Opt_Index).all
1360 & Path_Separator
1361 & File_Path
1362 (1 .. File_Path'Length
1363 - File_Name'Length)
1364 & Path_Separator
1365 & Path (1 .. GCC_Index));
1366 end if;
1367 end if;
1368 end if;
1369 end;
1370 end if;
1371 end if;
1373 -- Then we add the appropriate -l switch
1375 Linker_Options.Increment_Last;
1376 Linker_Options.Table (Linker_Options.Last) :=
1377 new String'(Next_Line (Nfirst .. Nlast));
1378 end if;
1380 else
1381 -- If gnatlib library not found, then
1382 -- add it anyway in case some other
1383 -- mechanism may find it.
1385 Linker_Options.Increment_Last;
1386 Linker_Options.Table (Linker_Options.Last) :=
1387 new String'(Next_Line (Nfirst .. Nlast));
1388 end if;
1389 end;
1390 else
1391 Linker_Options.Increment_Last;
1392 Linker_Options.Table (Linker_Options.Last) :=
1393 new String'(Next_Line (Nfirst .. Nlast));
1394 end if;
1395 end if;
1397 Xlinker_Was_Previous := Next_Line (Nfirst .. Nlast) = "-Xlinker";
1399 Get_Next_Line;
1400 exit when Next_Line (Nfirst .. Nlast) = End_Info;
1402 Next_Line (Nfirst .. Nlast - 8) := Next_Line (Nfirst + 8 .. Nlast);
1403 Nlast := Nlast - 8;
1404 end loop;
1405 end if;
1407 -- If -shared was specified, invoke gcc with -shared-libgcc
1409 if GNAT_Shared then
1410 Linker_Options.Increment_Last;
1411 Linker_Options.Table (Linker_Options.Last) := Shared_Libgcc;
1412 end if;
1414 Status := fclose (Fd);
1415 end Process_Binder_File;
1417 --------------
1418 -- To_Lower --
1419 --------------
1421 function To_Lower (A : Character) return Character is
1422 A_Val : constant Natural := Character'Pos (A);
1424 begin
1425 if A in 'A' .. 'Z'
1426 or else A_Val in 16#C0# .. 16#D6#
1427 or else A_Val in 16#D8# .. 16#DE#
1428 then
1429 return Character'Val (A_Val + 16#20#);
1430 else
1431 return A;
1432 end if;
1433 end To_Lower;
1435 procedure To_Lower (A : in out String) is
1436 begin
1437 for J in A'Range loop
1438 A (J) := To_Lower (A (J));
1439 end loop;
1440 end To_Lower;
1442 -----------
1443 -- Usage --
1444 -----------
1446 procedure Usage is
1447 begin
1448 Write_Str ("Usage: ");
1449 Write_Str (Base_Command_Name.all);
1450 Write_Str (" switches mainprog.ali [non-Ada-objects] [linker-options]");
1451 Write_Eol;
1452 Write_Eol;
1453 Write_Line (" mainprog.ali the ALI file of the main program");
1454 Write_Eol;
1455 Write_Eol;
1456 Display_Usage_Version_And_Help;
1457 Write_Line (" -f Force object file list to be generated");
1458 Write_Line (" -g Compile binder source file with debug information");
1459 Write_Line (" -n Do not compile the binder source file");
1460 Write_Line (" -P Process files for use by CodePeer");
1461 Write_Line (" -R Do not use a run_path_option");
1462 Write_Line (" -v Verbose mode");
1463 Write_Line (" -v -v Very verbose mode");
1464 Write_Eol;
1465 Write_Line (" -o nam Use 'nam' as the name of the executable");
1466 Write_Line (" -b target Compile the binder source to run on target");
1467 Write_Line (" -Bdir Load compiler executables from dir");
1469 if Is_Supported (Map_File) then
1470 Write_Line (" -Mmap Create map file map");
1471 Write_Line (" -M Create map file mainprog.map");
1472 end if;
1474 Write_Line (" --GCC=comp Use comp as the compiler");
1475 Write_Line (" --LINK=nam Use 'nam' for the linking rather than 'gcc'");
1476 Write_Eol;
1477 Write_Line (" [non-Ada-objects] list of non Ada object files");
1478 Write_Line (" [linker-options] other options for the linker");
1479 end Usage;
1481 ------------------
1482 -- Write_Header --
1483 ------------------
1485 procedure Write_Header is
1486 begin
1487 if Verbose_Mode then
1488 Write_Eol;
1489 Display_Version ("GNATLINK", "1995");
1490 end if;
1491 end Write_Header;
1493 -----------------
1494 -- Write_Usage --
1495 -----------------
1497 procedure Write_Usage is
1498 begin
1499 Write_Header;
1500 Usage;
1501 end Write_Usage;
1503 -- Start of processing for Gnatlink
1505 begin
1506 -- Add the directory where gnatlink is invoked in front of the path, if
1507 -- gnatlink is invoked with directory information. Only do this if the
1508 -- platform is not VMS, where the notion of path does not really exist.
1510 if not Hostparm.OpenVMS then
1511 declare
1512 Command : constant String := Command_Name;
1514 begin
1515 for Index in reverse Command'Range loop
1516 if Command (Index) = Directory_Separator then
1517 declare
1518 Absolute_Dir : constant String :=
1519 Normalize_Pathname
1520 (Command (Command'First .. Index));
1522 PATH : constant String :=
1523 Absolute_Dir &
1524 Path_Separator &
1525 Getenv ("PATH").all;
1527 begin
1528 Setenv ("PATH", PATH);
1529 end;
1531 exit;
1532 end if;
1533 end loop;
1534 end;
1535 end if;
1537 Base_Command_Name := new String'(Base_Name (Command_Name));
1539 -- Fold to lower case "GNATLINK" on VMS to be consistent with output
1540 -- from other GNAT utilities.
1542 if Hostparm.OpenVMS then
1543 To_Lower (Base_Command_Name.all);
1544 end if;
1546 Process_Args;
1548 if Argument_Count = 0
1549 or else (Verbose_Mode and then Argument_Count = 1)
1550 then
1551 Write_Usage;
1552 Exit_Program (E_Fatal);
1553 end if;
1555 -- Initialize packages to be used
1557 Csets.Initialize;
1558 Snames.Initialize;
1560 -- We always compile with -c
1562 Binder_Options_From_ALI.Increment_Last;
1563 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1564 new String'("-c");
1566 if Ali_File_Name = null then
1567 Exit_With_Error ("no ali file given for link");
1568 end if;
1570 if not Is_Regular_File (Ali_File_Name.all) then
1571 Exit_With_Error (Ali_File_Name.all & " not found");
1572 end if;
1574 -- Read the ALI file of the main subprogram if the binder generated file
1575 -- needs to be compiled and no --GCC= switch has been specified. Fetch the
1576 -- back end switches from this ALI file and use these switches to compile
1577 -- the binder generated file
1579 if Compile_Bind_File and then Standard_Gcc then
1580 Initialize_ALI;
1581 Name_Len := Ali_File_Name'Length;
1582 Name_Buffer (1 .. Name_Len) := Ali_File_Name.all;
1584 declare
1585 use Types;
1586 F : constant File_Name_Type := Name_Find;
1587 T : Text_Buffer_Ptr;
1588 A : ALI_Id;
1590 begin
1591 -- Load the ALI file
1593 T := Read_Library_Info (F, True);
1595 -- Read it. Note that we ignore errors, since we only want very
1596 -- limited information from the ali file, and likely a slightly
1597 -- wrong version will be just fine, though in normal operation
1598 -- we don't expect this to happen!
1600 A := Scan_ALI
1603 Ignore_ED => False,
1604 Err => False,
1605 Ignore_Errors => True);
1607 if A /= No_ALI_Id then
1609 Index in Units.Table (ALIs.Table (A).First_Unit).First_Arg ..
1610 Units.Table (ALIs.Table (A).First_Unit).Last_Arg
1611 loop
1612 -- Do not compile with the front end switches. However, --RTS
1613 -- is to be dealt with specially because it needs to be passed
1614 -- if the binder-generated file is in Ada and may also be used
1615 -- to drive the linker.
1617 declare
1618 Arg : String_Ptr renames Args.Table (Index);
1619 begin
1620 if not Is_Front_End_Switch (Arg.all) then
1621 Binder_Options_From_ALI.Increment_Last;
1622 Binder_Options_From_ALI.Table
1623 (Binder_Options_From_ALI.Last) := String_Access (Arg);
1625 elsif Arg'Length > 5
1626 and then Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
1627 then
1628 Binder_Options_From_ALI.Increment_Last;
1629 Binder_Options_From_ALI.Table
1630 (Binder_Options_From_ALI.Last) := String_Access (Arg);
1632 -- Set the RTS_*_Path_Name variables, so that
1633 -- the correct directories will be set when
1634 -- Osint.Add_Default_Search_Dirs will be called later.
1636 Opt.RTS_Src_Path_Name :=
1637 Get_RTS_Search_Dir
1638 (Arg (Arg'First + 6 .. Arg'Last), Include);
1640 Opt.RTS_Lib_Path_Name :=
1641 Get_RTS_Search_Dir
1642 (Arg (Arg'First + 6 .. Arg'Last), Objects);
1644 -- GNAT doesn't support the GCC multilib mechanism.
1645 -- This means that, when a multilib switch is used
1646 -- to request a particular compilation mode, the
1647 -- corresponding runtime switch (--RTS) must also be
1648 -- specified. The long-term goal is to fully support the
1649 -- multilib mechanism; however, in the meantime, it is
1650 -- convenient to eliminate the redundancy by keying the
1651 -- compilation mode on a single switch, namely --RTS.
1653 -- Pass -mrtp to the linker if --RTS=rtp was passed
1655 if Arg'Length > 8
1656 and then
1657 (Arg (Arg'First + 6 .. Arg'First + 8) = "rtp"
1658 or else Arg (Arg'Last - 2 .. Arg'Last) = "rtp")
1659 then
1660 Linker_Options.Increment_Last;
1661 Linker_Options.Table (Linker_Options.Last) :=
1662 new String'("-mrtp");
1663 end if;
1664 end if;
1665 end;
1666 end loop;
1667 end if;
1668 end;
1669 end if;
1671 -- Get target parameters
1673 Osint.Add_Default_Search_Dirs;
1674 Targparm.Get_Target_Parameters;
1676 if VM_Target /= No_VM then
1677 case VM_Target is
1678 when JVM_Target => Gcc := new String'("jvm-gnatcompile");
1679 when CLI_Target => Gcc := new String'("dotnet-gnatcompile");
1680 when No_VM => raise Program_Error;
1681 end case;
1682 end if;
1684 -- Compile the bind file with the following switches:
1686 -- -gnatA stops reading gnat.adc, since we don't know what
1687 -- pragmas would work, and we do not need it anyway.
1689 -- -gnatWb allows brackets coding for wide characters
1691 -- -gnatiw allows wide characters in identifiers. This is needed
1692 -- because bindgen uses brackets encoding for all upper
1693 -- half and wide characters in identifier names.
1695 -- In addition, in CodePeer mode compile with -x adascil -gnatcC
1697 Binder_Options_From_ALI.Increment_Last;
1698 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1699 new String'("-gnatA");
1700 Binder_Options_From_ALI.Increment_Last;
1701 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1702 new String'("-gnatWb");
1703 Binder_Options_From_ALI.Increment_Last;
1704 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1705 new String'("-gnatiw");
1707 if Opt.CodePeer_Mode then
1708 Binder_Options_From_ALI.Increment_Last;
1709 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1710 new String'("-x");
1711 Binder_Options_From_ALI.Increment_Last;
1712 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1713 new String'("adascil");
1714 Binder_Options_From_ALI.Increment_Last;
1715 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1716 new String'("-gnatcC");
1717 end if;
1719 -- Locate all the necessary programs and verify required files are present
1721 Gcc_Path := System.OS_Lib.Locate_Exec_On_Path (Gcc.all);
1723 if Gcc_Path = null then
1724 Exit_With_Error ("Couldn't locate " & Gcc.all);
1725 end if;
1727 if Linker_Path = null then
1728 if VM_Target = CLI_Target then
1729 Linker_Path := System.OS_Lib.Locate_Exec_On_Path ("dotnet-ld");
1731 if Linker_Path = null then
1732 Exit_With_Error ("Couldn't locate dotnet-ld");
1733 end if;
1735 elsif RTX_RTSS_Kernel_Module_On_Target then
1737 -- Use Microsoft linker for RTSS modules
1739 Linker_Path := System.OS_Lib.Locate_Exec_On_Path ("link");
1741 if Linker_Path = null then
1742 Exit_With_Error ("Couldn't locate link");
1743 end if;
1745 else
1746 Linker_Path := Gcc_Path;
1747 end if;
1748 end if;
1750 Write_Header;
1752 -- If no output name specified, then use the base name of .ali file name
1754 if Output_File_Name = null then
1755 Output_File_Name :=
1756 new String'(Base_Name (Ali_File_Name.all)
1757 & Get_Target_Debuggable_Suffix.all);
1758 end if;
1760 if RTX_RTSS_Kernel_Module_On_Target then
1761 Linker_Options.Increment_Last;
1762 Linker_Options.Table (Linker_Options.Last) :=
1763 new String'("/OUT:" & Output_File_Name.all);
1765 else
1766 Linker_Options.Increment_Last;
1767 Linker_Options.Table (Linker_Options.Last) := new String'("-o");
1769 Linker_Options.Increment_Last;
1770 Linker_Options.Table (Linker_Options.Last) :=
1771 new String'(Output_File_Name.all);
1772 end if;
1774 Check_Existing_Executable (Output_File_Name.all);
1776 -- Warn if main program is called "test", as that may be a built-in command
1777 -- on Unix. On non-Unix systems executables have a suffix, so the warning
1778 -- will not appear. However, do not warn in the case of a cross compiler.
1780 -- Assume this is a cross tool if the executable name is not gnatlink
1782 if Base_Command_Name.all = "gnatlink"
1783 and then Output_File_Name.all = "test"
1784 then
1785 Error_Msg ("warning: executable name """ & Output_File_Name.all
1786 & """ may conflict with shell command");
1787 end if;
1789 -- If -M switch was specified, add the switches to create the map file
1791 if Create_Map_File then
1792 declare
1793 Map_Name : constant String := Base_Name (Ali_File_Name.all) & ".map";
1794 Switches : String_List_Access;
1796 begin
1797 Convert (Map_File, Map_Name, Switches);
1799 if Switches /= null then
1800 for J in Switches'Range loop
1801 Linker_Options.Increment_Last;
1802 Linker_Options.Table (Linker_Options.Last) := Switches (J);
1803 end loop;
1804 end if;
1805 end;
1806 end if;
1808 -- Perform consistency checks
1810 -- Transform the .ali file name into the binder output file name
1812 Make_Binder_File_Names : declare
1813 Fname : constant String := Base_Name (Ali_File_Name.all);
1814 Fname_Len : Integer := Fname'Length;
1816 function Get_Maximum_File_Name_Length return Integer;
1817 pragma Import (C, Get_Maximum_File_Name_Length,
1818 "__gnat_get_maximum_file_name_length");
1820 Maximum_File_Name_Length : constant Integer :=
1821 Get_Maximum_File_Name_Length;
1823 Bind_File_Prefix : Types.String_Ptr;
1824 -- Contains prefix used for bind files
1826 begin
1827 -- Set prefix
1829 if OpenVMS_On_Target then
1830 Bind_File_Prefix := new String'("b__");
1831 else
1832 Bind_File_Prefix := new String'("b~");
1833 end if;
1835 -- If the length of the binder file becomes too long due to
1836 -- the addition of the "b?" prefix, then truncate it.
1838 if Maximum_File_Name_Length > 0 then
1839 while Fname_Len >
1840 Maximum_File_Name_Length - Bind_File_Prefix.all'Length
1841 loop
1842 Fname_Len := Fname_Len - 1;
1843 end loop;
1844 end if;
1846 declare
1847 Fnam : constant String :=
1848 Bind_File_Prefix.all &
1849 Fname (Fname'First .. Fname'First + Fname_Len - 1);
1851 begin
1852 Binder_Spec_Src_File := new String'(Fnam & ".ads");
1853 Binder_Body_Src_File := new String'(Fnam & ".adb");
1854 Binder_Ali_File := new String'(Fnam & ".ali");
1856 Binder_Obj_File := new String'(Fnam & Get_Target_Object_Suffix.all);
1857 end;
1859 if Fname_Len /= Fname'Length then
1860 Binder_Options.Increment_Last;
1861 Binder_Options.Table (Binder_Options.Last) := new String'("-o");
1862 Binder_Options.Increment_Last;
1863 Binder_Options.Table (Binder_Options.Last) := Binder_Obj_File;
1864 end if;
1865 end Make_Binder_File_Names;
1867 Process_Binder_File (Binder_Body_Src_File.all & ASCII.NUL);
1869 -- Compile the binder file. This is fast, so we always do it, unless
1870 -- specifically told not to by the -n switch
1872 if Compile_Bind_File then
1873 Bind_Step : declare
1874 Success : Boolean;
1875 Args : Argument_List
1876 (1 .. Binder_Options_From_ALI.Last + Binder_Options.Last + 1);
1878 begin
1879 for J in 1 .. Binder_Options_From_ALI.Last loop
1880 Args (J) := Binder_Options_From_ALI.Table (J);
1881 end loop;
1883 for J in 1 .. Binder_Options.Last loop
1884 Args (Binder_Options_From_ALI.Last + J) :=
1885 Binder_Options.Table (J);
1886 end loop;
1888 -- Use the full path of the binder generated source, so that it is
1889 -- guaranteed that the debugger will find this source, even with
1890 -- STABS.
1892 Args (Args'Last) :=
1893 new String'(Normalize_Pathname (Binder_Body_Src_File.all));
1895 if Verbose_Mode then
1896 Write_Str (Base_Name (Gcc_Path.all));
1898 for J in Args'Range loop
1899 Write_Str (" ");
1900 Write_Str (Args (J).all);
1901 end loop;
1903 Write_Eol;
1904 end if;
1906 System.OS_Lib.Spawn (Gcc_Path.all, Args, Success);
1908 if not Success then
1909 Exit_Program (E_Fatal);
1910 end if;
1911 end Bind_Step;
1912 end if;
1914 -- In CodePeer mode, there's nothing left to do after the binder file has
1915 -- been compiled.
1917 if Opt.CodePeer_Mode then
1918 return;
1919 end if;
1921 -- Now, actually link the program
1923 -- Skip this step for now on JVM since the Java interpreter will do
1924 -- the actual link at run time. We might consider packing all class files
1925 -- in a .zip file during this step.
1927 if VM_Target /= JVM_Target then
1928 Link_Step : declare
1929 Num_Args : Natural :=
1930 (Linker_Options.Last - Linker_Options.First + 1) +
1931 (Gcc_Linker_Options.Last - Gcc_Linker_Options.First + 1) +
1932 (Linker_Objects.Last - Linker_Objects.First + 1);
1933 Stack_Op : Boolean := False;
1934 IDENT_Op : Boolean := False;
1936 begin
1937 if AAMP_On_Target then
1939 -- Remove extraneous flags not relevant for AAMP
1941 for J in reverse Linker_Options.First .. Linker_Options.Last loop
1942 if Linker_Options.Table (J)'Length = 0
1943 or else Linker_Options.Table (J) (1 .. 3) = "-Wl"
1944 or else Linker_Options.Table (J) (1 .. 3) = "-sh"
1945 or else Linker_Options.Table (J) (1 .. 2) = "-O"
1946 or else Linker_Options.Table (J) (1 .. 2) = "-g"
1947 then
1948 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
1949 Linker_Options.Table (J + 1 .. Linker_Options.Last);
1950 Linker_Options.Decrement_Last;
1951 Num_Args := Num_Args - 1;
1952 end if;
1953 end loop;
1955 elsif RTX_RTSS_Kernel_Module_On_Target then
1957 -- Remove flags not relevant for Microsoft linker and adapt some
1958 -- others.
1960 for J in reverse Linker_Options.First .. Linker_Options.Last loop
1962 -- Remove flags that are not accepted
1964 if Linker_Options.Table (J)'Length = 0
1965 or else Linker_Options.Table (J) (1 .. 2) = "-l"
1966 or else Linker_Options.Table (J) (1 .. 3) = "-Wl"
1967 or else Linker_Options.Table (J) (1 .. 3) = "-sh"
1968 or else Linker_Options.Table (J) (1 .. 2) = "-O"
1969 or else Linker_Options.Table (J) (1 .. 8) = "-Xlinker"
1970 or else Linker_Options.Table (J) (1 .. 9) = "-mthreads"
1971 then
1972 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
1973 Linker_Options.Table (J + 1 .. Linker_Options.Last);
1974 Linker_Options.Decrement_Last;
1975 Num_Args := Num_Args - 1;
1977 -- Replace "-L" by its counterpart "/LIBPATH:" and UNIX "/" by
1978 -- Windows "\".
1979 elsif Linker_Options.Table (J) (1 .. 2) = "-L" then
1980 declare
1981 Libpath_Option : constant String_Access := new String'
1982 ("/LIBPATH:" &
1983 Linker_Options.Table (J)
1984 (3 .. Linker_Options.Table (J).all'Last));
1985 begin
1986 for Index in 10 .. Libpath_Option'Last loop
1987 if Libpath_Option (Index) = '/' then
1988 Libpath_Option (Index) := '\';
1989 end if;
1990 end loop;
1992 Linker_Options.Table (J) := Libpath_Option;
1993 end;
1995 -- Replace "-g" by "/DEBUG"
1996 elsif Linker_Options.Table (J) (1 .. 2) = "-g" then
1997 Linker_Options.Table (J) := new String'("/DEBUG");
1999 -- Replace "-o" by "/OUT:"
2000 elsif Linker_Options.Table (J) (1 .. 2) = "-o" then
2001 Linker_Options.Table (J + 1) := new String'
2002 ("/OUT:" & Linker_Options.Table (J + 1).all);
2004 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2005 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2006 Linker_Options.Decrement_Last;
2007 Num_Args := Num_Args - 1;
2009 -- Replace "--stack=" by "/STACK:"
2010 elsif Linker_Options.Table (J) (1 .. 8) = "--stack=" then
2011 Linker_Options.Table (J) := new String'
2012 ("/STACK:" &
2013 Linker_Options.Table (J)
2014 (9 .. Linker_Options.Table (J).all'Last));
2016 -- Replace "-v" by its counterpart "/VERBOSE"
2017 elsif Linker_Options.Table (J) (1 .. 2) = "-v" then
2018 Linker_Options.Table (J) := new String'("/VERBOSE");
2019 end if;
2020 end loop;
2022 -- Add some required flags to create RTSS modules
2024 declare
2025 Flags_For_Linker : constant array (1 .. 17) of String_Access :=
2026 (new String'("/NODEFAULTLIB"),
2027 new String'("/INCREMENTAL:NO"),
2028 new String'("/NOLOGO"),
2029 new String'("/DRIVER"),
2030 new String'("/ALIGN:0x20"),
2031 new String'("/SUBSYSTEM:NATIVE"),
2032 new String'("/ENTRY:_RtapiProcessEntryCRT@8"),
2033 new String'("/RELEASE"),
2034 new String'("startupCRT.obj"),
2035 new String'("rtxlibcmt.lib"),
2036 new String'("oldnames.lib"),
2037 new String'("rtapi_rtss.lib"),
2038 new String'("Rtx_Rtss.lib"),
2039 new String'("libkernel32.a"),
2040 new String'("libws2_32.a"),
2041 new String'("libmswsock.a"),
2042 new String'("libadvapi32.a"));
2043 -- These flags need to be passed to Microsoft linker. They
2044 -- come from the RTX documentation.
2046 Gcc_Lib_Path : constant String_Access := new String'
2047 ("/LIBPATH:" & Include_Dir_Default_Prefix & "\..\");
2048 -- Place to look for gcc related libraries, such as libgcc
2050 begin
2051 -- Replace UNIX "/" by Windows "\" in the path
2053 for Index in 10 .. Gcc_Lib_Path.all'Last loop
2054 if Gcc_Lib_Path (Index) = '/' then
2055 Gcc_Lib_Path (Index) := '\';
2056 end if;
2057 end loop;
2059 Linker_Options.Increment_Last;
2060 Linker_Options.Table (Linker_Options.Last) := Gcc_Lib_Path;
2061 Num_Args := Num_Args + 1;
2063 for Index in Flags_For_Linker'Range loop
2064 Linker_Options.Increment_Last;
2065 Linker_Options.Table (Linker_Options.Last) :=
2066 Flags_For_Linker (Index);
2067 Num_Args := Num_Args + 1;
2068 end loop;
2069 end;
2070 end if;
2072 -- Remove duplicate stack size setting from the Linker_Options
2073 -- table. The stack setting option "-Xlinker --stack=R,C" can be
2074 -- found in one line when set by a pragma Linker_Options or in two
2075 -- lines ("-Xlinker" then "--stack=R,C") when set on the command
2076 -- line. We also check for the "-Wl,--stack=R" style option.
2078 -- We must remove the second stack setting option instance
2079 -- because the one on the command line will always be the first
2080 -- one. And any subsequent stack setting option will overwrite the
2081 -- previous one. This is done especially for GNAT/NT where we set
2082 -- the stack size for tasking programs by a pragma in the NT
2083 -- specific tasking package System.Task_Primitives.Operations.
2085 -- Note: This is not a FOR loop that runs from Linker_Options.First
2086 -- to Linker_Options.Last, since operations within the loop can
2087 -- modify the length of the table.
2089 Clean_Link_Option_Set : declare
2090 J : Natural := Linker_Options.First;
2091 Shared_Libgcc_Seen : Boolean := False;
2093 begin
2094 while J <= Linker_Options.Last loop
2096 if Linker_Options.Table (J).all = "-Xlinker"
2097 and then J < Linker_Options.Last
2098 and then Linker_Options.Table (J + 1)'Length > 8
2099 and then Linker_Options.Table (J + 1) (1 .. 8) = "--stack="
2100 then
2101 if Stack_Op then
2102 Linker_Options.Table (J .. Linker_Options.Last - 2) :=
2103 Linker_Options.Table (J + 2 .. Linker_Options.Last);
2104 Linker_Options.Decrement_Last;
2105 Linker_Options.Decrement_Last;
2106 Num_Args := Num_Args - 2;
2108 else
2109 Stack_Op := True;
2110 end if;
2111 end if;
2113 -- Remove duplicate -shared-libgcc switch
2115 if Linker_Options.Table (J).all = Shared_Libgcc_String then
2116 if Shared_Libgcc_Seen then
2117 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2118 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2119 Linker_Options.Decrement_Last;
2120 Num_Args := Num_Args - 1;
2122 else
2123 Shared_Libgcc_Seen := True;
2124 end if;
2125 end if;
2127 -- Here we just check for a canonical form that matches the
2128 -- pragma Linker_Options set in the NT runtime.
2130 if (Linker_Options.Table (J)'Length > 17
2131 and then Linker_Options.Table (J) (1 .. 17)
2132 = "-Xlinker --stack=")
2133 or else
2134 (Linker_Options.Table (J)'Length > 12
2135 and then Linker_Options.Table (J) (1 .. 12)
2136 = "-Wl,--stack=")
2137 then
2138 if Stack_Op then
2139 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2140 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2141 Linker_Options.Decrement_Last;
2142 Num_Args := Num_Args - 1;
2144 else
2145 Stack_Op := True;
2146 end if;
2147 end if;
2149 -- Remove duplicate IDENTIFICATION directives (VMS)
2151 if Linker_Options.Table (J)'Length > 29
2152 and then Linker_Options.Table (J) (1 .. 30) =
2153 "--for-linker=--identification="
2154 then
2155 if IDENT_Op then
2156 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2157 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2158 Linker_Options.Decrement_Last;
2159 Num_Args := Num_Args - 1;
2161 else
2162 IDENT_Op := True;
2163 end if;
2164 end if;
2166 J := J + 1;
2167 end loop;
2169 if Linker_Path = Gcc_Path and then VM_Target = No_VM then
2171 -- For systems where the default is to link statically with
2172 -- libgcc, if gcc is not called with -shared-libgcc, call it
2173 -- with -static-libgcc, as there are some platforms where one
2174 -- of these two switches is compulsory to link.
2176 if Shared_Libgcc_Default = 'T'
2177 and then not Shared_Libgcc_Seen
2178 then
2179 Linker_Options.Increment_Last;
2180 Linker_Options.Table (Linker_Options.Last) := Static_Libgcc;
2181 Num_Args := Num_Args + 1;
2182 end if;
2184 elsif RTX_RTSS_Kernel_Module_On_Target then
2186 -- Force the use of the static libgcc for RTSS modules
2188 Linker_Options.Increment_Last;
2189 Linker_Options.Table (Linker_Options.Last) :=
2190 new String'("libgcc.a");
2191 Num_Args := Num_Args + 1;
2192 end if;
2194 end Clean_Link_Option_Set;
2196 -- Prepare arguments for call to linker
2198 Call_Linker : declare
2199 Success : Boolean;
2200 Args : Argument_List (1 .. Num_Args + 1);
2201 Index : Integer := Args'First;
2203 begin
2204 Args (Index) := Binder_Obj_File;
2206 -- Add the object files and any -largs libraries
2208 for J in Linker_Objects.First .. Linker_Objects.Last loop
2209 Index := Index + 1;
2210 Args (Index) := Linker_Objects.Table (J);
2211 end loop;
2213 -- Add the linker options from the binder file
2215 for J in Linker_Options.First .. Linker_Options.Last loop
2216 Index := Index + 1;
2217 Args (Index) := Linker_Options.Table (J);
2218 end loop;
2220 -- Finally add the libraries from the --GCC= switch
2222 for J in Gcc_Linker_Options.First .. Gcc_Linker_Options.Last loop
2223 Index := Index + 1;
2224 Args (Index) := Gcc_Linker_Options.Table (J);
2225 end loop;
2227 if Verbose_Mode then
2228 Write_Str (Linker_Path.all);
2230 for J in Args'Range loop
2231 Write_Str (" ");
2232 Write_Str (Args (J).all);
2233 end loop;
2235 Write_Eol;
2237 -- If we are on very verbose mode (-v -v) and a response file
2238 -- is used we display its content.
2240 if Very_Verbose_Mode and then Tname_FD /= Invalid_FD then
2241 Write_Eol;
2242 Write_Str ("Response file (" &
2243 Tname (Tname'First .. Tname'Last - 1) &
2244 ") content : ");
2245 Write_Eol;
2247 for J in
2248 Response_File_Objects.First ..
2249 Response_File_Objects.Last
2250 loop
2251 Write_Str (Response_File_Objects.Table (J).all);
2252 Write_Eol;
2253 end loop;
2255 Write_Eol;
2256 end if;
2257 end if;
2259 System.OS_Lib.Spawn (Linker_Path.all, Args, Success);
2261 if Success then
2263 -- Delete the temporary file used in conjunction with linking
2264 -- if one was created. See Process_Bind_File for details.
2266 if Tname_FD /= Invalid_FD then
2267 Delete (Tname);
2268 end if;
2270 else
2271 Error_Msg ("error when calling " & Linker_Path.all);
2272 Exit_Program (E_Fatal);
2273 end if;
2274 end Call_Linker;
2275 end Link_Step;
2276 end if;
2278 -- Only keep the binder output file and it's associated object
2279 -- file if compiling with the -g option. These files are only
2280 -- useful if debugging.
2282 if not Debug_Flag_Present then
2283 Delete (Binder_Ali_File.all & ASCII.NUL);
2284 Delete (Binder_Spec_Src_File.all & ASCII.NUL);
2285 Delete (Binder_Body_Src_File.all & ASCII.NUL);
2287 if VM_Target = No_VM then
2288 Delete (Binder_Obj_File.all & ASCII.NUL);
2289 end if;
2290 end if;
2292 Exit_Program (E_Success);
2294 exception
2295 when X : others =>
2296 Write_Line (Exception_Information (X));
2297 Exit_With_Error ("INTERNAL ERROR. Please report");
2298 end Gnatlink;