fixing pr42337
[official-gcc.git] / gcc / ada / gnatlink.adb
blob708e1794d0401786c3751ab975ab81c4fbcc2768
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-2009, 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 : String := "-- BEGIN Object file/option list";
145 End_Info : String := "-- END Object file/option list ";
146 -- Note: above lines are modified in C mode, see option processing
148 Gcc_Path : String_Access;
149 Linker_Path : String_Access;
150 Output_File_Name : String_Access;
151 Ali_File_Name : String_Access;
152 Binder_Spec_Src_File : String_Access;
153 Binder_Body_Src_File : String_Access;
154 Binder_Ali_File : String_Access;
155 Binder_Obj_File : String_Access;
157 Tname : Temp_File_Name;
158 Tname_FD : File_Descriptor := Invalid_FD;
159 -- Temporary file used by linker to pass list of object files on
160 -- certain systems with limitations on size of arguments.
162 Lname : String_Access := null;
163 -- File used by linker for CLI target, used to concatenate all .il files
164 -- when the command line passed to ilasm is too long
166 Debug_Flag_Present : Boolean := False;
167 Verbose_Mode : Boolean := False;
168 Very_Verbose_Mode : Boolean := False;
170 Ada_Bind_File : Boolean := True;
171 -- Set to True if bind file is generated in Ada
173 Standard_Gcc : Boolean := True;
175 Compile_Bind_File : Boolean := True;
176 -- Set to False if bind file is not to be compiled
178 Create_Map_File : Boolean := False;
179 -- Set to True by switch -M. The map file name is derived from
180 -- the ALI file name (mainprog.ali => mainprog.map).
182 Object_List_File_Supported : Boolean;
183 for Object_List_File_Supported'Size use Character'Size;
184 pragma Import
185 (C, Object_List_File_Supported, "__gnat_objlist_file_supported");
186 -- Predicate indicating whether the linker has an option whereby the
187 -- names of object files can be passed to the linker in a file.
189 Object_List_File_Required : Boolean := False;
190 -- Set to True to force generation of a response file
192 Shared_Libgcc_Default : Character;
193 for Shared_Libgcc_Default'Size use Character'Size;
194 pragma Import
195 (C, Shared_Libgcc_Default, "__gnat_shared_libgcc_default");
196 -- Indicates wether libgcc should be statically linked (use 'T') or
197 -- dynamically linked (use 'H') by default.
199 function Base_Name (File_Name : String) return String;
200 -- Return just the file name part without the extension (if present)
202 procedure Delete (Name : String);
203 -- Wrapper to unlink as status is ignored by this application
205 procedure Error_Msg (Message : String);
206 -- Output the error or warning Message
208 procedure Exit_With_Error (Error : String);
209 -- Output Error and exit program with a fatal condition
211 procedure Process_Args;
212 -- Go through all the arguments and build option tables
214 procedure Process_Binder_File (Name : String);
215 -- Reads the binder file and extracts linker arguments
217 procedure Usage;
218 -- Display usage
220 procedure Write_Header;
221 -- Show user the program name, version and copyright
223 procedure Write_Usage;
224 -- Show user the program options
226 ---------------
227 -- Base_Name --
228 ---------------
230 function Base_Name (File_Name : String) return String is
231 Findex1 : Natural;
232 Findex2 : Natural;
234 begin
235 Findex1 := File_Name'First;
237 -- The file might be specified by a full path name. However,
238 -- we want the path to be stripped away.
240 for J in reverse File_Name'Range loop
241 if Is_Directory_Separator (File_Name (J)) then
242 Findex1 := J + 1;
243 exit;
244 end if;
245 end loop;
247 Findex2 := File_Name'Last;
248 while Findex2 > Findex1
249 and then File_Name (Findex2) /= '.'
250 loop
251 Findex2 := Findex2 - 1;
252 end loop;
254 if Findex2 = Findex1 then
255 Findex2 := File_Name'Last + 1;
256 end if;
258 return File_Name (Findex1 .. Findex2 - 1);
259 end Base_Name;
261 ------------
262 -- Delete --
263 ------------
265 procedure Delete (Name : String) is
266 Status : int;
267 pragma Unreferenced (Status);
268 begin
269 Status := unlink (Name'Address);
270 -- Is it really right to ignore an error here ???
271 end Delete;
273 ---------------
274 -- Error_Msg --
275 ---------------
277 procedure Error_Msg (Message : String) is
278 begin
279 Write_Str (Base_Name (Command_Name));
280 Write_Str (": ");
281 Write_Str (Message);
282 Write_Eol;
283 end Error_Msg;
285 ---------------------
286 -- Exit_With_Error --
287 ---------------------
289 procedure Exit_With_Error (Error : String) is
290 begin
291 Error_Msg (Error);
292 Exit_Program (E_Fatal);
293 end Exit_With_Error;
295 ------------------
296 -- Process_Args --
297 ------------------
299 procedure Process_Args is
300 Next_Arg : Integer;
301 Skip_Next : Boolean := False;
302 -- Set to true if the next argument is to be added into the list of
303 -- linker's argument without parsing it.
305 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
307 -- Start of processing for Process_Args
309 begin
310 -- First, check for --version and --help
312 Check_Version_And_Help ("GNATLINK", "1995");
314 -- Loop through arguments of gnatlink command
316 Next_Arg := 1;
317 loop
318 exit when Next_Arg > Argument_Count;
320 Process_One_Arg : declare
321 Arg : constant String := Argument (Next_Arg);
323 begin
324 -- Case of argument which is a switch
326 -- We definitely need section by section comments here ???
328 if Skip_Next then
330 -- This argument must not be parsed, just add it to the
331 -- list of linker's options.
333 Skip_Next := False;
335 Linker_Options.Increment_Last;
336 Linker_Options.Table (Linker_Options.Last) :=
337 new String'(Arg);
339 elsif Arg'Length /= 0 and then Arg (1) = '-' then
340 if Arg'Length > 4 and then Arg (2 .. 5) = "gnat" then
341 Exit_With_Error
342 ("invalid switch: """ & Arg & """ (gnat not needed here)");
343 end if;
345 if Arg = "-Xlinker" then
347 -- Next argument should be sent directly to the linker.
348 -- We do not want to parse it here.
350 Skip_Next := True;
352 Linker_Options.Increment_Last;
353 Linker_Options.Table (Linker_Options.Last) :=
354 new String'(Arg);
356 elsif Arg (2) = 'g'
357 and then (Arg'Length < 5 or else Arg (2 .. 5) /= "gnat")
358 then
359 Debug_Flag_Present := True;
361 Linker_Options.Increment_Last;
362 Linker_Options.Table (Linker_Options.Last) :=
363 new String'(Arg);
365 Binder_Options.Increment_Last;
366 Binder_Options.Table (Binder_Options.Last) :=
367 Linker_Options.Table (Linker_Options.Last);
369 elsif Arg'Length >= 3 and then Arg (2) = 'M' then
370 declare
371 Switches : String_List_Access;
373 begin
374 Convert (Map_File, Arg (3 .. Arg'Last), Switches);
376 if Switches /= null then
377 for J in Switches'Range loop
378 Linker_Options.Increment_Last;
379 Linker_Options.Table (Linker_Options.Last) :=
380 Switches (J);
381 end loop;
382 end if;
383 end;
385 elsif Arg'Length = 2 then
386 case Arg (2) is
387 when 'A' =>
388 Ada_Bind_File := True;
389 Begin_Info := "-- BEGIN Object file/option list";
390 End_Info := "-- END Object file/option list ";
392 when 'b' =>
393 Linker_Options.Increment_Last;
394 Linker_Options.Table (Linker_Options.Last) :=
395 new String'(Arg);
397 Binder_Options.Increment_Last;
398 Binder_Options.Table (Binder_Options.Last) :=
399 Linker_Options.Table (Linker_Options.Last);
401 Next_Arg := Next_Arg + 1;
403 if Next_Arg > Argument_Count then
404 Exit_With_Error ("Missing argument for -b");
405 end if;
407 Get_Machine_Name : declare
408 Name_Arg : constant String_Access :=
409 new String'(Argument (Next_Arg));
411 begin
412 Linker_Options.Increment_Last;
413 Linker_Options.Table (Linker_Options.Last) :=
414 Name_Arg;
416 Binder_Options.Increment_Last;
417 Binder_Options.Table (Binder_Options.Last) :=
418 Name_Arg;
420 end Get_Machine_Name;
422 when 'C' =>
423 Ada_Bind_File := False;
424 Begin_Info := "/* BEGIN Object file/option list";
425 End_Info := " END Object file/option list */";
427 when 'f' =>
428 if Object_List_File_Supported then
429 Object_List_File_Required := True;
430 else
431 Exit_With_Error
432 ("Object list file not supported on this target");
433 end if;
435 when 'M' =>
436 Create_Map_File := True;
438 when 'n' =>
439 Compile_Bind_File := False;
441 when 'o' =>
442 Next_Arg := Next_Arg + 1;
444 if Next_Arg > Argument_Count then
445 Exit_With_Error ("Missing argument for -o");
446 end if;
448 Output_File_Name :=
449 new String'(Executable_Name
450 (Argument (Next_Arg),
451 Only_If_No_Suffix => True));
453 when 'R' =>
454 Opt.Run_Path_Option := False;
456 when 'v' =>
458 -- Support "double" verbose mode. Second -v
459 -- gets sent to the linker and binder phases.
461 if Verbose_Mode then
462 Very_Verbose_Mode := True;
464 Linker_Options.Increment_Last;
465 Linker_Options.Table (Linker_Options.Last) :=
466 new String'(Arg);
468 Binder_Options.Increment_Last;
469 Binder_Options.Table (Binder_Options.Last) :=
470 Linker_Options.Table (Linker_Options.Last);
472 else
473 Verbose_Mode := True;
475 end if;
477 when others =>
478 Linker_Options.Increment_Last;
479 Linker_Options.Table (Linker_Options.Last) :=
480 new String'(Arg);
482 end case;
484 elsif Arg (2) = 'B' then
485 Linker_Options.Increment_Last;
486 Linker_Options.Table (Linker_Options.Last) :=
487 new String'(Arg);
489 Binder_Options.Increment_Last;
490 Binder_Options.Table (Binder_Options.Last) :=
491 Linker_Options.Table (Linker_Options.Last);
493 elsif Arg'Length >= 7 and then Arg (1 .. 7) = "--LINK=" then
494 if Arg'Length = 7 then
495 Exit_With_Error ("Missing argument for --LINK=");
496 end if;
498 Linker_Path :=
499 System.OS_Lib.Locate_Exec_On_Path (Arg (8 .. Arg'Last));
501 if Linker_Path = null then
502 Exit_With_Error
503 ("Could not locate linker: " & Arg (8 .. Arg'Last));
504 end if;
506 elsif Arg'Length > 6 and then Arg (1 .. 6) = "--GCC=" then
507 declare
508 Program_Args : constant Argument_List_Access :=
509 Argument_String_To_List
510 (Arg (7 .. Arg'Last));
512 begin
513 if Program_Args.all (1).all /= Gcc.all then
514 Gcc := new String'(Program_Args.all (1).all);
515 Standard_Gcc := False;
516 end if;
518 -- Set appropriate flags for switches passed
520 for J in 2 .. Program_Args.all'Last loop
521 declare
522 Arg : constant String := Program_Args.all (J).all;
523 AF : constant Integer := Arg'First;
525 begin
526 if Arg'Length /= 0 and then Arg (AF) = '-' then
527 if Arg (AF + 1) = 'g'
528 and then (Arg'Length = 2
529 or else Arg (AF + 2) in '0' .. '3'
530 or else Arg (AF + 2 .. Arg'Last) = "coff")
531 then
532 Debug_Flag_Present := True;
533 end if;
534 end if;
536 -- Add directory to source search dirs so that
537 -- Get_Target_Parameters can find system.ads
539 if Arg (AF .. AF + 1) = "-I"
540 and then Arg'Length > 2
541 then
542 Add_Src_Search_Dir (Arg (AF + 2 .. Arg'Last));
543 end if;
545 -- Pass to gcc for compiling binder generated file
546 -- No use passing libraries, it will just generate
547 -- a warning
549 if not (Arg (AF .. AF + 1) = "-l"
550 or else Arg (AF .. AF + 1) = "-L")
551 then
552 Binder_Options.Increment_Last;
553 Binder_Options.Table (Binder_Options.Last) :=
554 new String'(Arg);
555 end if;
557 -- Pass to gcc for linking program
559 Gcc_Linker_Options.Increment_Last;
560 Gcc_Linker_Options.Table
561 (Gcc_Linker_Options.Last) := new String'(Arg);
562 end;
563 end loop;
564 end;
566 -- Send all multi-character switches not recognized as
567 -- a special case by gnatlink to the linker/loader stage.
569 else
570 Linker_Options.Increment_Last;
571 Linker_Options.Table (Linker_Options.Last) :=
572 new String'(Arg);
573 end if;
575 -- Here if argument is a file name rather than a switch
577 else
578 -- If explicit ali file, capture it
580 if Arg'Length > 4
581 and then Arg (Arg'Last - 3 .. Arg'Last) = ".ali"
582 then
583 if Ali_File_Name = null then
584 Ali_File_Name := new String'(Arg);
585 else
586 Exit_With_Error ("cannot handle more than one ALI file");
587 end if;
589 -- If target object file, record object file
591 elsif Arg'Length > Get_Target_Object_Suffix.all'Length
592 and then Arg
593 (Arg'Last -
594 Get_Target_Object_Suffix.all'Length + 1 .. Arg'Last)
595 = Get_Target_Object_Suffix.all
596 then
597 Linker_Objects.Increment_Last;
598 Linker_Objects.Table (Linker_Objects.Last) :=
599 new String'(Arg);
601 -- If host object file, record object file
602 -- e.g. accept foo.o as well as foo.obj on VMS target
604 elsif Arg'Length > Get_Object_Suffix.all'Length
605 and then Arg
606 (Arg'Last - Get_Object_Suffix.all'Length + 1 .. Arg'Last)
607 = Get_Object_Suffix.all
608 then
609 Linker_Objects.Increment_Last;
610 Linker_Objects.Table (Linker_Objects.Last) :=
611 new String'(Arg);
613 -- If corresponding ali file exists, capture it
615 elsif Ali_File_Name = null
616 and then Is_Regular_File (Arg & ".ali")
617 then
618 Ali_File_Name := new String'(Arg & ".ali");
620 -- Otherwise assume this is a linker options entry, but
621 -- see below for interesting adjustment to this assumption.
623 else
624 Linker_Options.Increment_Last;
625 Linker_Options.Table (Linker_Options.Last) :=
626 new String'(Arg);
627 end if;
628 end if;
629 end Process_One_Arg;
631 Next_Arg := Next_Arg + 1;
632 end loop;
634 -- If Ada bind file, then compile it with warnings suppressed, because
635 -- otherwise the with of the main program may cause junk warnings.
637 if Ada_Bind_File then
638 Binder_Options.Increment_Last;
639 Binder_Options.Table (Binder_Options.Last) := new String'("-gnatws");
640 end if;
642 -- If we did not get an ali file at all, and we had at least one
643 -- linker option, then assume that was the intended ali file after
644 -- all, so that we get a nicer message later on.
646 if Ali_File_Name = null
647 and then Linker_Options.Last >= Linker_Options.First
648 then
649 Ali_File_Name :=
650 new String'(Linker_Options.Table (Linker_Options.First).all &
651 ".ali");
652 end if;
653 end Process_Args;
655 -------------------------
656 -- Process_Binder_File --
657 -------------------------
659 procedure Process_Binder_File (Name : String) is
660 Fd : FILEs;
661 -- Binder file's descriptor
663 Link_Bytes : Integer := 0;
664 -- Projected number of bytes for the linker command line
666 Link_Max : Integer;
667 pragma Import (C, Link_Max, "__gnat_link_max");
668 -- Maximum number of bytes on the command line supported by the OS
669 -- linker. Passed this limit the response file mechanism must be used
670 -- if supported.
672 Next_Line : String (1 .. 1000);
673 -- Current line value
675 Nlast : Integer;
676 Nfirst : Integer;
677 -- Current line slice (the slice does not contain line terminator)
679 Last : Integer;
680 -- Current line last character for shared libraries (without version)
682 Objs_Begin : Integer := 0;
683 -- First object file index in Linker_Objects table
685 Objs_End : Integer := 0;
686 -- Last object file index in Linker_Objects table
688 Status : int;
689 pragma Warnings (Off, Status);
690 -- Used for various Interfaces.C_Streams calls
692 Closing_Status : Boolean;
693 pragma Warnings (Off, Closing_Status);
694 -- For call to Close
696 GNAT_Static : Boolean := False;
697 -- Save state of -static option
699 GNAT_Shared : Boolean := False;
700 -- Save state of -shared option
702 Xlinker_Was_Previous : Boolean := False;
703 -- Indicate that "-Xlinker" was the option preceding the current
704 -- option. If True, then the current option is never suppressed.
706 -- Rollback data
708 -- These data items are used to store current binder file context.
709 -- The context is composed of the file descriptor position and the
710 -- current line together with the slice indexes (first and last
711 -- position) for this line. The rollback data are used by the
712 -- Store_File_Context and Rollback_File_Context routines below.
713 -- The file context mechanism interact only with the Get_Next_Line
714 -- call. For example:
716 -- Store_File_Context;
717 -- Get_Next_Line;
718 -- Rollback_File_Context;
719 -- Get_Next_Line;
721 -- Both Get_Next_Line calls above will read the exact same data from
722 -- the file. In other words, Next_Line, Nfirst and Nlast variables
723 -- will be set with the exact same values.
725 RB_File_Pos : long; -- File position
726 RB_Next_Line : String (1 .. 1000); -- Current line content
727 RB_Nlast : Integer; -- Slice last index
728 RB_Nfirst : Integer; -- Slice first index
730 Run_Path_Option_Ptr : Interfaces.C.Strings.chars_ptr;
731 pragma Import (C, Run_Path_Option_Ptr, "__gnat_run_path_option");
732 -- Pointer to string representing the native linker option which
733 -- specifies the path where the dynamic loader should find shared
734 -- libraries. Equal to null string if this system doesn't support it.
736 Object_Library_Ext_Ptr : Interfaces.C.Strings.chars_ptr;
737 pragma Import
738 (C, Object_Library_Ext_Ptr, "__gnat_object_library_extension");
739 -- Pointer to string specifying the default extension for
740 -- object libraries, e.g. Unix uses ".a", VMS uses ".olb".
742 Object_File_Option_Ptr : Interfaces.C.Strings.chars_ptr;
743 pragma Import (C, Object_File_Option_Ptr, "__gnat_object_file_option");
744 -- Pointer to a string representing the linker option which specifies
745 -- the response file.
747 Using_GNU_Linker : Boolean;
748 for Using_GNU_Linker'Size use Character'Size;
749 pragma Import (C, Using_GNU_Linker, "__gnat_using_gnu_linker");
750 -- Predicate indicating whether this target uses the GNU linker. In
751 -- this case we must output a GNU linker compatible response file.
753 Separate_Run_Path_Options : Boolean;
754 for Separate_Run_Path_Options'Size use Character'Size;
755 pragma Import
756 (C, Separate_Run_Path_Options, "__gnat_separate_run_path_options");
757 -- Whether separate rpath options should be emitted for each directory
759 Opening : aliased constant String := """";
760 Closing : aliased constant String := '"' & ASCII.LF;
761 -- Needed to quote object paths in object list files when GNU linker
762 -- is used.
764 procedure Get_Next_Line;
765 -- Read the next line from the binder file without the line
766 -- terminator.
768 function Index (S, Pattern : String) return Natural;
769 -- Return the last occurrence of Pattern in S, or 0 if none
771 function Is_Option_Present (Opt : String) return Boolean;
772 -- Return true if the option Opt is already present in
773 -- Linker_Options table.
775 procedure Store_File_Context;
776 -- Store current file context, Fd position and current line data.
777 -- The file context is stored into the rollback data above (RB_*).
778 -- Store_File_Context can be called at any time, only the last call
779 -- will be used (i.e. this routine overwrites the file context).
781 procedure Rollback_File_Context;
782 -- Restore file context from rollback data. This routine must be called
783 -- after Store_File_Context. The binder file context will be restored
784 -- with the data stored by the last Store_File_Context call.
786 -------------------
787 -- Get_Next_Line --
788 -------------------
790 procedure Get_Next_Line is
791 Fchars : chars;
793 begin
794 Fchars := fgets (Next_Line'Address, Next_Line'Length, Fd);
796 if Fchars = System.Null_Address then
797 Exit_With_Error ("Error reading binder output");
798 end if;
800 Nfirst := Next_Line'First;
801 Nlast := Nfirst;
802 while Nlast <= Next_Line'Last
803 and then Next_Line (Nlast) /= ASCII.LF
804 and then Next_Line (Nlast) /= ASCII.CR
805 loop
806 Nlast := Nlast + 1;
807 end loop;
809 Nlast := Nlast - 1;
810 end Get_Next_Line;
812 -----------
813 -- Index --
814 -----------
816 function Index (S, Pattern : String) return Natural is
817 Len : constant Natural := Pattern'Length;
819 begin
820 for J in reverse S'First .. S'Last - Len + 1 loop
821 if Pattern = S (J .. J + Len - 1) then
822 return J;
823 end if;
824 end loop;
826 return 0;
827 end Index;
829 -----------------------
830 -- Is_Option_Present --
831 -----------------------
833 function Is_Option_Present (Opt : String) return Boolean is
834 begin
835 for I in 1 .. Linker_Options.Last loop
837 if Linker_Options.Table (I).all = Opt then
838 return True;
839 end if;
841 end loop;
843 return False;
844 end Is_Option_Present;
846 ---------------------------
847 -- Rollback_File_Context --
848 ---------------------------
850 procedure Rollback_File_Context is
851 begin
852 Next_Line := RB_Next_Line;
853 Nfirst := RB_Nfirst;
854 Nlast := RB_Nlast;
855 Status := fseek (Fd, RB_File_Pos, Interfaces.C_Streams.SEEK_SET);
857 if Status = -1 then
858 Exit_With_Error ("Error setting file position");
859 end if;
860 end Rollback_File_Context;
862 ------------------------
863 -- Store_File_Context --
864 ------------------------
866 procedure Store_File_Context is
867 use type System.CRTL.long;
868 begin
869 RB_Next_Line := Next_Line;
870 RB_Nfirst := Nfirst;
871 RB_Nlast := Nlast;
872 RB_File_Pos := ftell (Fd);
874 if RB_File_Pos = -1 then
875 Exit_With_Error ("Error getting file position");
876 end if;
877 end Store_File_Context;
879 -- Start of processing for Process_Binder_File
881 begin
882 Fd := fopen (Name'Address, Read_Mode'Address);
884 if Fd = NULL_Stream then
885 Exit_With_Error ("Failed to open binder output");
886 end if;
888 -- Skip up to the Begin Info line
890 loop
891 Get_Next_Line;
892 exit when Next_Line (Nfirst .. Nlast) = Begin_Info;
893 end loop;
895 loop
896 Get_Next_Line;
898 -- Go to end when end line is reached (this will happen in
899 -- High_Integrity_Mode where no -L switches are generated)
901 exit when Next_Line (Nfirst .. Nlast) = End_Info;
903 if Ada_Bind_File then
904 Next_Line (Nfirst .. Nlast - 8) :=
905 Next_Line (Nfirst + 8 .. Nlast);
906 Nlast := Nlast - 8;
907 end if;
909 -- Go to next section when switches are reached
911 exit when Next_Line (1) = '-';
913 -- Otherwise we have another object file to collect
915 Linker_Objects.Increment_Last;
917 -- Mark the positions of first and last object files in case
918 -- they need to be placed with a named file on systems having
919 -- linker line limitations.
921 if Objs_Begin = 0 then
922 Objs_Begin := Linker_Objects.Last;
923 end if;
925 Linker_Objects.Table (Linker_Objects.Last) :=
926 new String'(Next_Line (Nfirst .. Nlast));
928 Link_Bytes := Link_Bytes + Nlast - Nfirst + 2;
929 -- Nlast - Nfirst + 1, for the size, plus one for the space between
930 -- each arguments.
931 end loop;
933 Objs_End := Linker_Objects.Last;
935 -- Continue to compute the Link_Bytes, the linker options are part of
936 -- command line length.
938 Store_File_Context;
940 while Next_Line (Nfirst .. Nlast) /= End_Info loop
941 Link_Bytes := Link_Bytes + Nlast - Nfirst + 2;
942 Get_Next_Line;
943 end loop;
945 Rollback_File_Context;
947 -- On systems that have limitations on handling very long linker lines
948 -- we make use of the system linker option which takes a list of object
949 -- file names from a file instead of the command line itself. What we do
950 -- is to replace the list of object files by the special linker option
951 -- which then reads the object file list from a file instead. The option
952 -- to read from a file instead of the command line is only triggered if
953 -- a conservative threshold is passed.
955 if VM_Target = CLI_Target
956 and then Link_Bytes > Link_Max
957 then
958 Lname := new String'("l~" & Base_Name (Ali_File_Name.all) & ".il");
960 for J in Objs_Begin .. Objs_End loop
961 Copy_File (Linker_Objects.Table (J).all, Lname.all,
962 Success => Closing_Status,
963 Mode => Append);
964 end loop;
966 -- Add the special objects list file option together with the name
967 -- of the temporary file to the objects file table.
969 Linker_Objects.Table (Objs_Begin) :=
970 new String'(Value (Object_File_Option_Ptr) & Lname.all);
972 -- The slots containing these object file names are then removed
973 -- from the objects table so they do not appear in the link. They
974 -- are removed by moving up the linker options and non-Ada object
975 -- files appearing after the Ada object list in the table.
977 declare
978 N : Integer;
980 begin
981 N := Objs_End - Objs_Begin + 1;
983 for J in Objs_End + 1 .. Linker_Objects.Last loop
984 Linker_Objects.Table (J - N + 1) := Linker_Objects.Table (J);
985 end loop;
987 Linker_Objects.Set_Last (Linker_Objects.Last - N + 1);
988 end;
990 elsif Object_List_File_Required
991 or else (Object_List_File_Supported
992 and then Link_Bytes > Link_Max)
993 then
994 -- Create a temporary file containing the Ada user object files
995 -- needed by the link. This list is taken from the bind file
996 -- and is output one object per line for maximal compatibility with
997 -- linkers supporting this option.
999 Create_Temp_File (Tname_FD, Tname);
1001 -- ??? File descriptor should be checked to not be Invalid_FD.
1002 -- ??? Status of Write and Close operations should be checked, and
1003 -- failure should occur if a status is wrong.
1005 -- If target is using the GNU linker we must add a special header
1006 -- and footer in the response file.
1008 -- The syntax is : INPUT (object1.o object2.o ... )
1010 -- Because the GNU linker does not like name with characters such
1011 -- as '!', we must put the object paths between double quotes.
1013 if Using_GNU_Linker then
1014 declare
1015 GNU_Header : aliased constant String := "INPUT (";
1017 begin
1018 Status := Write (Tname_FD, GNU_Header'Address,
1019 GNU_Header'Length);
1020 end;
1021 end if;
1023 for J in Objs_Begin .. Objs_End loop
1025 -- Opening quote for GNU linker
1027 if Using_GNU_Linker then
1028 Status := Write (Tname_FD, Opening'Address, 1);
1029 end if;
1031 Status := Write (Tname_FD, Linker_Objects.Table (J).all'Address,
1032 Linker_Objects.Table (J).all'Length);
1034 -- Closing quote for GNU linker
1036 if Using_GNU_Linker then
1037 Status := Write (Tname_FD, Closing'Address, 2);
1039 else
1040 Status := Write (Tname_FD, ASCII.LF'Address, 1);
1041 end if;
1043 Response_File_Objects.Increment_Last;
1044 Response_File_Objects.Table (Response_File_Objects.Last) :=
1045 Linker_Objects.Table (J);
1046 end loop;
1048 -- Handle GNU linker response file footer
1050 if Using_GNU_Linker then
1051 declare
1052 GNU_Footer : aliased constant String := ")";
1054 begin
1055 Status := Write (Tname_FD, GNU_Footer'Address,
1056 GNU_Footer'Length);
1057 end;
1058 end if;
1060 Close (Tname_FD, Closing_Status);
1062 -- Add the special objects list file option together with the name
1063 -- of the temporary file (removing the null character) to the objects
1064 -- file table.
1066 Linker_Objects.Table (Objs_Begin) :=
1067 new String'(Value (Object_File_Option_Ptr) &
1068 Tname (Tname'First .. Tname'Last - 1));
1070 -- The slots containing these object file names are then removed
1071 -- from the objects table so they do not appear in the link. They
1072 -- are removed by moving up the linker options and non-Ada object
1073 -- files appearing after the Ada object list in the table.
1075 declare
1076 N : Integer;
1078 begin
1079 N := Objs_End - Objs_Begin + 1;
1081 for J in Objs_End + 1 .. Linker_Objects.Last loop
1082 Linker_Objects.Table (J - N + 1) := Linker_Objects.Table (J);
1083 end loop;
1085 Linker_Objects.Set_Last (Linker_Objects.Last - N + 1);
1086 end;
1087 end if;
1089 -- Process switches and options
1091 if Next_Line (Nfirst .. Nlast) /= End_Info then
1092 Xlinker_Was_Previous := False;
1094 loop
1095 if Xlinker_Was_Previous
1096 or else Next_Line (Nfirst .. Nlast) = "-Xlinker"
1097 then
1098 Linker_Options.Increment_Last;
1099 Linker_Options.Table (Linker_Options.Last) :=
1100 new String'(Next_Line (Nfirst .. Nlast));
1102 elsif Next_Line (Nfirst .. Nlast) = "-static" then
1103 GNAT_Static := True;
1105 elsif Next_Line (Nfirst .. Nlast) = "-shared" then
1106 GNAT_Shared := True;
1108 -- Add binder options only if not already set on the command
1109 -- line. This rule is a way to control the linker options order.
1111 -- The following test needs comments, why is it VMS specific.
1112 -- The above comment looks out of date ???
1114 elsif not (OpenVMS_On_Target
1115 and then
1116 Is_Option_Present (Next_Line (Nfirst .. Nlast)))
1117 then
1118 if Nlast > Nfirst + 2 and then
1119 Next_Line (Nfirst .. Nfirst + 1) = "-L"
1120 then
1121 -- Construct a library search path for use later
1122 -- to locate static gnatlib libraries.
1124 if Libpath.Last > 1 then
1125 Libpath.Increment_Last;
1126 Libpath.Table (Libpath.Last) := Path_Separator;
1127 end if;
1129 for I in Nfirst + 2 .. Nlast loop
1130 Libpath.Increment_Last;
1131 Libpath.Table (Libpath.Last) := Next_Line (I);
1132 end loop;
1134 Linker_Options.Increment_Last;
1136 Linker_Options.Table (Linker_Options.Last) :=
1137 new String'(Next_Line (Nfirst .. Nlast));
1139 elsif Next_Line (Nfirst .. Nlast) = "-ldecgnat"
1140 or else Next_Line (Nfirst .. Nlast) = "-lgnarl"
1141 or else Next_Line (Nfirst .. Nlast) = "-lgnat"
1142 or else Next_Line
1143 (1 .. Natural'Min (Nlast, 8 + Library_Version'Length)) =
1144 Shared_Lib ("gnarl")
1145 or else Next_Line
1146 (1 .. Natural'Min (Nlast, 7 + Library_Version'Length)) =
1147 Shared_Lib ("gnat")
1148 then
1149 -- If it is a shared library, remove the library version.
1150 -- We will be looking for the static version of the library
1151 -- as it is in the same directory as the shared version.
1153 if Next_Line (Nlast - Library_Version'Length + 1 .. Nlast)
1154 = Library_Version
1155 then
1156 -- Set Last to point to last character before the
1157 -- library version.
1159 Last := Nlast - Library_Version'Length - 1;
1160 else
1161 Last := Nlast;
1162 end if;
1164 -- Given a Gnat standard library, search the
1165 -- library path to find the library location
1167 declare
1168 File_Path : String_Access;
1170 Object_Lib_Extension : constant String :=
1171 Value (Object_Library_Ext_Ptr);
1173 File_Name : constant String := "lib" &
1174 Next_Line (Nfirst + 2 .. Last) &
1175 Object_Lib_Extension;
1177 Run_Path_Opt : constant String :=
1178 Value (Run_Path_Option_Ptr);
1180 GCC_Index : Natural;
1181 Run_Path_Opt_Index : Natural := 0;
1183 begin
1184 File_Path :=
1185 Locate_Regular_File (File_Name,
1186 String (Libpath.Table (1 .. Libpath.Last)));
1188 if File_Path /= null then
1189 if GNAT_Static then
1191 -- If static gnatlib found, explicitly
1192 -- specify to overcome possible linker
1193 -- default usage of shared version.
1195 Linker_Options.Increment_Last;
1197 Linker_Options.Table (Linker_Options.Last) :=
1198 new String'(File_Path.all);
1200 elsif GNAT_Shared then
1201 if Opt.Run_Path_Option then
1202 -- If shared gnatlib desired, add the
1203 -- appropriate system specific switch
1204 -- so that it can be located at runtime.
1206 if Run_Path_Opt'Length /= 0 then
1207 -- Output the system specific linker command
1208 -- that allows the image activator to find
1209 -- the shared library at runtime.
1210 -- Also add path to find libgcc_s.so, if
1211 -- relevant.
1213 -- To find the location of the shared version
1214 -- of libgcc, we look for "gcc-lib" in the
1215 -- path of the library. However, this
1216 -- subdirectory is no longer present in
1217 -- in recent version of GCC. So, we look for
1218 -- the last subdirectory "lib" in the path.
1220 GCC_Index :=
1221 Index (File_Path.all, "gcc-lib");
1223 if GCC_Index /= 0 then
1224 -- The shared version of libgcc is
1225 -- located in the parent directory.
1227 GCC_Index := GCC_Index - 1;
1229 else
1230 GCC_Index :=
1231 Index (File_Path.all, "/lib/");
1233 if GCC_Index = 0 then
1234 GCC_Index :=
1235 Index (File_Path.all,
1236 Directory_Separator &
1237 "lib" &
1238 Directory_Separator);
1239 end if;
1241 -- We have found a subdirectory "lib",
1242 -- this is where the shared version of
1243 -- libgcc should be located.
1245 if GCC_Index /= 0 then
1246 GCC_Index := GCC_Index + 3;
1247 end if;
1248 end if;
1250 -- Look for an eventual run_path_option in
1251 -- the linker switches.
1253 if Separate_Run_Path_Options then
1254 Linker_Options.Increment_Last;
1255 Linker_Options.Table
1256 (Linker_Options.Last) :=
1257 new String'
1258 (Run_Path_Opt
1259 & File_Path
1260 (1 .. File_Path'Length
1261 - File_Name'Length));
1263 if GCC_Index /= 0 then
1264 Linker_Options.Increment_Last;
1265 Linker_Options.Table
1266 (Linker_Options.Last) :=
1267 new String'
1268 (Run_Path_Opt
1269 & File_Path (1 .. GCC_Index));
1270 end if;
1271 else
1272 for J in reverse
1273 1 .. Linker_Options.Last
1274 loop
1275 if Linker_Options.Table (J) /= null
1276 and then
1277 Linker_Options.Table (J)'Length
1278 > Run_Path_Opt'Length
1279 and then
1280 Linker_Options.Table (J)
1281 (1 .. Run_Path_Opt'Length) =
1282 Run_Path_Opt
1283 then
1284 -- We have found a already specified
1285 -- run_path_option: we will add to
1286 -- this switch, because only one
1287 -- run_path_option should be
1288 -- specified.
1290 Run_Path_Opt_Index := J;
1291 exit;
1292 end if;
1293 end loop;
1295 -- If there is no run_path_option, we need
1296 -- to add one.
1298 if Run_Path_Opt_Index = 0 then
1299 Linker_Options.Increment_Last;
1300 end if;
1302 if GCC_Index = 0 then
1303 if Run_Path_Opt_Index = 0 then
1304 Linker_Options.Table
1305 (Linker_Options.Last) :=
1306 new String'
1307 (Run_Path_Opt
1308 & File_Path
1309 (1 .. File_Path'Length
1310 - File_Name'Length));
1312 else
1313 Linker_Options.Table
1314 (Run_Path_Opt_Index) :=
1315 new String'
1316 (Linker_Options.Table
1317 (Run_Path_Opt_Index).all
1318 & Path_Separator
1319 & File_Path
1320 (1 .. File_Path'Length
1321 - File_Name'Length));
1322 end if;
1324 else
1325 if Run_Path_Opt_Index = 0 then
1326 Linker_Options.Table
1327 (Linker_Options.Last) :=
1328 new String'(Run_Path_Opt
1329 & File_Path
1330 (1 .. File_Path'Length
1331 - File_Name'Length)
1332 & Path_Separator
1333 & File_Path (1 .. GCC_Index));
1335 else
1336 Linker_Options.Table
1337 (Run_Path_Opt_Index) :=
1338 new String'
1339 (Linker_Options.Table
1340 (Run_Path_Opt_Index).all
1341 & Path_Separator
1342 & File_Path
1343 (1 .. File_Path'Length
1344 - File_Name'Length)
1345 & Path_Separator
1346 & File_Path (1 .. GCC_Index));
1347 end if;
1348 end if;
1349 end if;
1350 end if;
1351 end if;
1353 -- Then we add the appropriate -l switch
1355 Linker_Options.Increment_Last;
1356 Linker_Options.Table (Linker_Options.Last) :=
1357 new String'(Next_Line (Nfirst .. Nlast));
1358 end if;
1360 else
1361 -- If gnatlib library not found, then
1362 -- add it anyway in case some other
1363 -- mechanism may find it.
1365 Linker_Options.Increment_Last;
1366 Linker_Options.Table (Linker_Options.Last) :=
1367 new String'(Next_Line (Nfirst .. Nlast));
1368 end if;
1369 end;
1370 else
1371 Linker_Options.Increment_Last;
1372 Linker_Options.Table (Linker_Options.Last) :=
1373 new String'(Next_Line (Nfirst .. Nlast));
1374 end if;
1375 end if;
1377 Xlinker_Was_Previous := Next_Line (Nfirst .. Nlast) = "-Xlinker";
1379 Get_Next_Line;
1380 exit when Next_Line (Nfirst .. Nlast) = End_Info;
1382 if Ada_Bind_File then
1383 Next_Line (Nfirst .. Nlast - 8) :=
1384 Next_Line (Nfirst + 8 .. Nlast);
1385 Nlast := Nlast - 8;
1386 end if;
1387 end loop;
1388 end if;
1390 -- If -shared was specified, invoke gcc with -shared-libgcc
1392 if GNAT_Shared then
1393 Linker_Options.Increment_Last;
1394 Linker_Options.Table (Linker_Options.Last) := Shared_Libgcc;
1395 end if;
1397 Status := fclose (Fd);
1398 end Process_Binder_File;
1400 -----------
1401 -- Usage --
1402 -----------
1404 procedure Usage is
1405 begin
1406 Write_Str ("Usage: ");
1407 Write_Str (Base_Name (Command_Name));
1408 Write_Str (" switches mainprog.ali [non-Ada-objects] [linker-options]");
1409 Write_Eol;
1410 Write_Eol;
1411 Write_Line (" mainprog.ali the ALI file of the main program");
1412 Write_Eol;
1413 Write_Line (" -A Binder generated source file is in Ada (default)");
1414 Write_Line (" -C Binder generated source file is in C");
1415 Write_Line (" -f force object file list to be generated");
1416 Write_Line (" -g Compile binder source file with debug information");
1417 Write_Line (" -n Do not compile the binder source file");
1418 Write_Line (" -R Do not use a run_path_option");
1419 Write_Line (" -v verbose mode");
1420 Write_Line (" -v -v very verbose mode");
1421 Write_Eol;
1422 Write_Line (" -o nam Use 'nam' as the name of the executable");
1423 Write_Line (" -b target Compile the binder source to run on target");
1424 Write_Line (" -Bdir Load compiler executables from dir");
1426 if Is_Supported (Map_File) then
1427 Write_Line (" -Mmap Create map file map");
1428 Write_Line (" -M Create map file mainprog.map");
1429 end if;
1431 Write_Line (" --GCC=comp Use comp as the compiler");
1432 Write_Line (" --LINK=nam Use 'nam' for the linking rather than 'gcc'");
1433 Write_Eol;
1434 Write_Line (" [non-Ada-objects] list of non Ada object files");
1435 Write_Line (" [linker-options] other options for the linker");
1436 end Usage;
1438 ------------------
1439 -- Write_Header --
1440 ------------------
1442 procedure Write_Header is
1443 begin
1444 if Verbose_Mode then
1445 Write_Eol;
1446 Display_Version ("GNATLINK", "1995");
1447 end if;
1448 end Write_Header;
1450 -----------------
1451 -- Write_Usage --
1452 -----------------
1454 procedure Write_Usage is
1455 begin
1456 Write_Header;
1457 Usage;
1458 end Write_Usage;
1460 -- Start of processing for Gnatlink
1462 begin
1463 -- Add the directory where gnatlink is invoked in front of the
1464 -- path, if gnatlink is invoked with directory information.
1465 -- Only do this if the platform is not VMS, where the notion of path
1466 -- does not really exist.
1468 if not Hostparm.OpenVMS then
1469 declare
1470 Command : constant String := Command_Name;
1472 begin
1473 for Index in reverse Command'Range loop
1474 if Command (Index) = Directory_Separator then
1475 declare
1476 Absolute_Dir : constant String :=
1477 Normalize_Pathname
1478 (Command (Command'First .. Index));
1480 PATH : constant String :=
1481 Absolute_Dir &
1482 Path_Separator &
1483 Getenv ("PATH").all;
1485 begin
1486 Setenv ("PATH", PATH);
1487 end;
1489 exit;
1490 end if;
1491 end loop;
1492 end;
1493 end if;
1495 Process_Args;
1497 if Argument_Count = 0
1498 or else
1499 (Verbose_Mode and then Argument_Count = 1)
1500 then
1501 Write_Usage;
1502 Exit_Program (E_Fatal);
1503 end if;
1505 -- Initialize packages to be used
1507 Namet.Initialize;
1508 Csets.Initialize;
1509 Snames.Initialize;
1511 -- We always compile with -c
1513 Binder_Options_From_ALI.Increment_Last;
1514 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1515 new String'("-c");
1517 if Ali_File_Name = null then
1518 Exit_With_Error ("no ali file given for link");
1519 end if;
1521 if not Is_Regular_File (Ali_File_Name.all) then
1522 Exit_With_Error (Ali_File_Name.all & " not found");
1523 end if;
1525 -- Read the ALI file of the main subprogram if the binder generated
1526 -- file needs to be compiled and no --GCC= switch has been specified.
1527 -- Fetch the back end switches from this ALI file and use these switches
1528 -- to compile the binder generated file
1530 if Compile_Bind_File and then Standard_Gcc then
1532 Initialize_ALI;
1533 Name_Len := Ali_File_Name'Length;
1534 Name_Buffer (1 .. Name_Len) := Ali_File_Name.all;
1536 declare
1537 use Types;
1538 F : constant File_Name_Type := Name_Find;
1539 T : Text_Buffer_Ptr;
1540 A : ALI_Id;
1542 begin
1543 -- Load the ALI file
1545 T := Read_Library_Info (F, True);
1547 -- Read it. Note that we ignore errors, since we only want very
1548 -- limited information from the ali file, and likely a slightly
1549 -- wrong version will be just fine, though in normal operation
1550 -- we don't expect this to happen!
1552 A := Scan_ALI
1555 Ignore_ED => False,
1556 Err => False,
1557 Ignore_Errors => True);
1559 if A /= No_ALI_Id then
1561 Index in Units.Table (ALIs.Table (A).First_Unit).First_Arg ..
1562 Units.Table (ALIs.Table (A).First_Unit).Last_Arg
1563 loop
1564 -- Do not compile with the front end switches. However, --RTS
1565 -- is to be dealt with specially because it needs to be passed
1566 -- if the binder-generated file is in Ada and may also be used
1567 -- to drive the linker.
1569 declare
1570 Arg : String_Ptr renames Args.Table (Index);
1571 begin
1572 if not Is_Front_End_Switch (Arg.all) then
1573 Binder_Options_From_ALI.Increment_Last;
1574 Binder_Options_From_ALI.Table
1575 (Binder_Options_From_ALI.Last) := String_Access (Arg);
1577 elsif Arg'Length > 5
1578 and then Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
1579 then
1580 if Ada_Bind_File then
1581 Binder_Options_From_ALI.Increment_Last;
1582 Binder_Options_From_ALI.Table
1583 (Binder_Options_From_ALI.Last)
1584 := String_Access (Arg);
1585 end if;
1587 -- Set the RTS_*_Path_Name variables, so that the
1588 -- correct directories will be set when
1589 -- Osint.Add_Default_Search_Dirs will be called later.
1591 Opt.RTS_Src_Path_Name :=
1592 Get_RTS_Search_Dir
1593 (Arg (Arg'First + 6 .. Arg'Last), Include);
1595 Opt.RTS_Lib_Path_Name :=
1596 Get_RTS_Search_Dir
1597 (Arg (Arg'First + 6 .. Arg'Last), Objects);
1599 -- GNAT doesn't support the GCC multilib mechanism.
1600 -- This means that, when a multilib switch is used
1601 -- to request a particular compilation mode, the
1602 -- corresponding runtime switch (--RTS) must also be
1603 -- specified. The long-term goal is to fully support the
1604 -- multilib mechanism; however, in the meantime, it is
1605 -- convenient to eliminate the redundancy by keying the
1606 -- compilation mode on a single switch, namely --RTS.
1608 -- Pass -mrtp to the linker if --RTS=rtp was passed
1610 if Arg'Length > 8
1611 and then Arg (Arg'First + 6 .. Arg'First + 8) = "rtp"
1612 then
1613 Linker_Options.Increment_Last;
1614 Linker_Options.Table (Linker_Options.Last) :=
1615 new String'("-mrtp");
1617 -- Pass -fsjlj to the linker if --RTS=sjlj was passed
1619 elsif Arg'Length > 9
1620 and then Arg (Arg'First + 6 .. Arg'First + 9) = "sjlj"
1621 then
1622 Linker_Options.Increment_Last;
1623 Linker_Options.Table (Linker_Options.Last) :=
1624 new String'("-fsjlj");
1625 end if;
1626 end if;
1627 end;
1628 end loop;
1629 end if;
1630 end;
1631 end if;
1633 -- Get target parameters
1635 Osint.Add_Default_Search_Dirs;
1636 Targparm.Get_Target_Parameters;
1638 if VM_Target /= No_VM then
1639 case VM_Target is
1640 when JVM_Target => Gcc := new String'("jvm-gnatcompile");
1641 when CLI_Target => Gcc := new String'("dotnet-gnatcompile");
1642 when No_VM => raise Program_Error;
1643 end case;
1645 Ada_Bind_File := True;
1646 Begin_Info := "-- BEGIN Object file/option list";
1647 End_Info := "-- END Object file/option list ";
1648 end if;
1650 -- If the main program is in Ada it is compiled with the following
1651 -- switches:
1653 -- -gnatA stops reading gnat.adc, since we don't know what
1654 -- pragmas would work, and we do not need it anyway.
1656 -- -gnatWb allows brackets coding for wide characters
1658 -- -gnatiw allows wide characters in identifiers. This is needed
1659 -- because bindgen uses brackets encoding for all upper
1660 -- half and wide characters in identifier names.
1662 if Ada_Bind_File then
1663 Binder_Options_From_ALI.Increment_Last;
1664 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1665 new String'("-gnatA");
1666 Binder_Options_From_ALI.Increment_Last;
1667 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1668 new String'("-gnatWb");
1669 Binder_Options_From_ALI.Increment_Last;
1670 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1671 new String'("-gnatiw");
1672 end if;
1674 -- Locate all the necessary programs and verify required files are present
1676 Gcc_Path := System.OS_Lib.Locate_Exec_On_Path (Gcc.all);
1678 if Gcc_Path = null then
1679 Exit_With_Error ("Couldn't locate " & Gcc.all);
1680 end if;
1682 if Linker_Path = null then
1683 if VM_Target = CLI_Target then
1684 Linker_Path := System.OS_Lib.Locate_Exec_On_Path ("ilasm");
1686 if Linker_Path = null then
1687 Exit_With_Error ("Couldn't locate ilasm");
1688 end if;
1690 elsif RTX_RTSS_Kernel_Module_On_Target then
1692 -- Use Microsoft linker for RTSS modules
1694 Linker_Path := System.OS_Lib.Locate_Exec_On_Path ("link");
1696 if Linker_Path = null then
1697 Exit_With_Error ("Couldn't locate link");
1698 end if;
1700 else
1701 Linker_Path := Gcc_Path;
1702 end if;
1703 end if;
1705 Write_Header;
1707 -- If no output name specified, then use the base name of .ali file name
1709 if Output_File_Name = null then
1710 Output_File_Name :=
1711 new String'(Base_Name (Ali_File_Name.all)
1712 & Get_Target_Debuggable_Suffix.all);
1713 end if;
1715 if VM_Target = CLI_Target then
1716 Linker_Options.Increment_Last;
1717 Linker_Options.Table (Linker_Options.Last) := new String'("/QUIET");
1719 Linker_Options.Increment_Last;
1720 Linker_Options.Table (Linker_Options.Last) := new String'("/DEBUG");
1722 Linker_Options.Increment_Last;
1723 Linker_Options.Table (Linker_Options.Last) :=
1724 new String'("/OUTPUT=" & Output_File_Name.all);
1726 elsif RTX_RTSS_Kernel_Module_On_Target then
1727 Linker_Options.Increment_Last;
1728 Linker_Options.Table (Linker_Options.Last) :=
1729 new String'("/OUT:" & Output_File_Name.all);
1731 else
1732 Linker_Options.Increment_Last;
1733 Linker_Options.Table (Linker_Options.Last) := new String'("-o");
1735 Linker_Options.Increment_Last;
1736 Linker_Options.Table (Linker_Options.Last) :=
1737 new String'(Output_File_Name.all);
1738 end if;
1740 -- Delete existing executable, in case it is a symbolic link, to avoid
1741 -- modifying the target of the symbolic link.
1743 declare
1744 Dummy : Boolean;
1745 pragma Unreferenced (Dummy);
1747 begin
1748 Delete_File (Output_File_Name.all, Dummy);
1749 end;
1751 -- Warn if main program is called "test", as that may be a built-in command
1752 -- on Unix. On non-Unix systems executables have a suffix, so the warning
1753 -- will not appear. However, do not warn in the case of a cross compiler.
1755 -- Assume this is a cross tool if the executable name is not gnatlink
1757 if Base_Name (Command_Name) = "gnatlink"
1758 and then Output_File_Name.all = "test"
1759 then
1760 Error_Msg ("warning: executable name """ & Output_File_Name.all
1761 & """ may conflict with shell command");
1762 end if;
1764 -- If -M switch was specified, add the switches to create the map file
1766 if Create_Map_File then
1767 declare
1768 Map_Name : constant String := Base_Name (Ali_File_Name.all) & ".map";
1769 Switches : String_List_Access;
1771 begin
1772 Convert (Map_File, Map_Name, Switches);
1774 if Switches /= null then
1775 for J in Switches'Range loop
1776 Linker_Options.Increment_Last;
1777 Linker_Options.Table (Linker_Options.Last) := Switches (J);
1778 end loop;
1779 end if;
1780 end;
1781 end if;
1783 -- Perform consistency checks
1785 -- Transform the .ali file name into the binder output file name
1787 Make_Binder_File_Names : declare
1788 Fname : constant String := Base_Name (Ali_File_Name.all);
1789 Fname_Len : Integer := Fname'Length;
1791 function Get_Maximum_File_Name_Length return Integer;
1792 pragma Import (C, Get_Maximum_File_Name_Length,
1793 "__gnat_get_maximum_file_name_length");
1795 Maximum_File_Name_Length : constant Integer :=
1796 Get_Maximum_File_Name_Length;
1798 Bind_File_Prefix : Types.String_Ptr;
1799 -- Contains prefix used for bind files
1801 begin
1802 -- Set prefix
1804 if not Ada_Bind_File then
1805 Bind_File_Prefix := new String'("b_");
1806 elsif OpenVMS_On_Target then
1807 Bind_File_Prefix := new String'("b__");
1808 else
1809 Bind_File_Prefix := new String'("b~");
1810 end if;
1812 -- If the length of the binder file becomes too long due to
1813 -- the addition of the "b?" prefix, then truncate it.
1815 if Maximum_File_Name_Length > 0 then
1816 while Fname_Len >
1817 Maximum_File_Name_Length - Bind_File_Prefix.all'Length
1818 loop
1819 Fname_Len := Fname_Len - 1;
1820 end loop;
1821 end if;
1823 declare
1824 Fnam : constant String :=
1825 Bind_File_Prefix.all &
1826 Fname (Fname'First .. Fname'First + Fname_Len - 1);
1828 begin
1829 if Ada_Bind_File then
1830 Binder_Spec_Src_File := new String'(Fnam & ".ads");
1831 Binder_Body_Src_File := new String'(Fnam & ".adb");
1832 Binder_Ali_File := new String'(Fnam & ".ali");
1833 else
1834 Binder_Body_Src_File := new String'(Fnam & ".c");
1835 end if;
1837 Binder_Obj_File := new String'(Fnam & Get_Target_Object_Suffix.all);
1838 end;
1840 if Fname_Len /= Fname'Length then
1841 Binder_Options.Increment_Last;
1842 Binder_Options.Table (Binder_Options.Last) := new String'("-o");
1843 Binder_Options.Increment_Last;
1844 Binder_Options.Table (Binder_Options.Last) := Binder_Obj_File;
1845 end if;
1846 end Make_Binder_File_Names;
1848 Process_Binder_File (Binder_Body_Src_File.all & ASCII.NUL);
1850 -- Compile the binder file. This is fast, so we always do it, unless
1851 -- specifically told not to by the -n switch
1853 if Compile_Bind_File then
1854 Bind_Step : declare
1855 Success : Boolean;
1856 Args : Argument_List
1857 (1 .. Binder_Options_From_ALI.Last + Binder_Options.Last + 1);
1859 begin
1860 for J in 1 .. Binder_Options_From_ALI.Last loop
1861 Args (J) := Binder_Options_From_ALI.Table (J);
1862 end loop;
1864 for J in 1 .. Binder_Options.Last loop
1865 Args (Binder_Options_From_ALI.Last + J) :=
1866 Binder_Options.Table (J);
1867 end loop;
1869 -- Use the full path of the binder generated source, so that it is
1870 -- guaranteed that the debugger will find this source, even with
1871 -- STABS.
1873 Args (Args'Last) :=
1874 new String'(Normalize_Pathname (Binder_Body_Src_File.all));
1876 if Verbose_Mode then
1877 Write_Str (Base_Name (Gcc_Path.all));
1879 for J in Args'Range loop
1880 Write_Str (" ");
1881 Write_Str (Args (J).all);
1882 end loop;
1884 Write_Eol;
1885 end if;
1887 System.OS_Lib.Spawn (Gcc_Path.all, Args, Success);
1889 if not Success then
1890 Exit_Program (E_Fatal);
1891 end if;
1892 end Bind_Step;
1893 end if;
1895 -- Now, actually link the program
1897 -- Skip this step for now on JVM since the Java interpreter will do
1898 -- the actual link at run time. We might consider packing all class files
1899 -- in a .zip file during this step.
1901 if VM_Target /= JVM_Target then
1902 Link_Step : declare
1903 Num_Args : Natural :=
1904 (Linker_Options.Last - Linker_Options.First + 1) +
1905 (Gcc_Linker_Options.Last - Gcc_Linker_Options.First + 1) +
1906 (Linker_Objects.Last - Linker_Objects.First + 1);
1907 Stack_Op : Boolean := False;
1908 IDENT_Op : Boolean := False;
1910 begin
1911 if VM_Target = CLI_Target then
1913 -- Remove extraneous flags not relevant for CIL. Also remove empty
1914 -- arguments, since ilasm chokes on them.
1916 for J in reverse Linker_Options.First .. Linker_Options.Last loop
1917 if Linker_Options.Table (J)'Length = 0
1918 or else Linker_Options.Table (J) (1 .. 2) = "-L"
1919 or else Linker_Options.Table (J) (1 .. 2) = "-l"
1920 or else Linker_Options.Table (J) (1 .. 3) = "-Wl"
1921 or else Linker_Options.Table (J) (1 .. 3) = "-sh"
1922 or else Linker_Options.Table (J) (1 .. 2) = "-g"
1923 then
1924 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
1925 Linker_Options.Table (J + 1 .. Linker_Options.Last);
1926 Linker_Options.Decrement_Last;
1927 Num_Args := Num_Args - 1;
1928 end if;
1929 end loop;
1931 elsif RTX_RTSS_Kernel_Module_On_Target then
1933 -- Remove flags not relevant for Microsoft linker and adapt some
1934 -- others.
1936 for J in reverse Linker_Options.First .. Linker_Options.Last loop
1938 -- Remove flags that are not accepted
1939 if Linker_Options.Table (J)'Length = 0
1940 or else Linker_Options.Table (J) (1 .. 2) = "-l"
1941 or else Linker_Options.Table (J) (1 .. 3) = "-Wl"
1942 or else Linker_Options.Table (J) (1 .. 3) = "-sh"
1943 or else Linker_Options.Table (J) (1 .. 8) = "-Xlinker"
1944 or else Linker_Options.Table (J) (1 .. 9) = "-mthreads"
1945 then
1946 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
1947 Linker_Options.Table (J + 1 .. Linker_Options.Last);
1948 Linker_Options.Decrement_Last;
1949 Num_Args := Num_Args - 1;
1951 -- Replace "-L" by its counterpart "/LIBPATH:" and UNIX "/" by
1952 -- Windows "\".
1953 elsif Linker_Options.Table (J) (1 .. 2) = "-L" then
1954 declare
1955 Libpath_Option : constant String_Access := new String'
1956 ("/LIBPATH:" &
1957 Linker_Options.Table (J)
1958 (3 .. Linker_Options.Table (J).all'Last));
1959 begin
1960 for Index in 10 .. Libpath_Option'Last loop
1961 if Libpath_Option (Index) = '/' then
1962 Libpath_Option (Index) := '\';
1963 end if;
1964 end loop;
1966 Linker_Options.Table (J) := Libpath_Option;
1967 end;
1969 -- Replace "-g" by "/DEBUG"
1970 elsif Linker_Options.Table (J) (1 .. 2) = "-g" then
1971 Linker_Options.Table (J) := new String'("/DEBUG");
1973 -- Replace "-o" by "/OUT:"
1974 elsif Linker_Options.Table (J) (1 .. 2) = "-o" then
1975 Linker_Options.Table (J + 1) := new String'
1976 ("/OUT:" & Linker_Options.Table (J + 1).all);
1978 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
1979 Linker_Options.Table (J + 1 .. Linker_Options.Last);
1980 Linker_Options.Decrement_Last;
1981 Num_Args := Num_Args - 1;
1983 -- Replace "--stack=" by "/STACK:"
1984 elsif Linker_Options.Table (J) (1 .. 8) = "--stack=" then
1985 Linker_Options.Table (J) := new String'
1986 ("/STACK:" &
1987 Linker_Options.Table (J)
1988 (9 .. Linker_Options.Table (J).all'Last));
1990 -- Replace "-v" by its counterpart "/VERBOSE"
1991 elsif Linker_Options.Table (J) (1 .. 2) = "-v" then
1992 Linker_Options.Table (J) := new String'("/VERBOSE");
1993 end if;
1994 end loop;
1996 -- Add some required flags to create RTSS modules
1998 declare
1999 Flags_For_Linker : constant array (1 .. 17) of String_Access :=
2000 (new String'("/NODEFAULTLIB"),
2001 new String'("/INCREMENTAL:NO"),
2002 new String'("/NOLOGO"),
2003 new String'("/DRIVER"),
2004 new String'("/ALIGN:0x20"),
2005 new String'("/SUBSYSTEM:NATIVE"),
2006 new String'("/ENTRY:_RtapiProcessEntryCRT@8"),
2007 new String'("/RELEASE"),
2008 new String'("startupCRT.obj"),
2009 new String'("rtxlibcmt.lib"),
2010 new String'("oldnames.lib"),
2011 new String'("rtapi_rtss.lib"),
2012 new String'("Rtx_Rtss.lib"),
2013 new String'("libkernel32.a"),
2014 new String'("libws2_32.a"),
2015 new String'("libmswsock.a"),
2016 new String'("libadvapi32.a"));
2017 -- These flags need to be passed to Microsoft linker. They
2018 -- come from the RTX documentation.
2020 Gcc_Lib_Path : constant String_Access := new String'
2021 ("/LIBPATH:" & Include_Dir_Default_Prefix & "\..\");
2022 -- Place to look for gcc related libraries, such as libgcc
2024 begin
2025 -- Replace UNIX "/" by Windows "\" in the path
2027 for Index in 10 .. Gcc_Lib_Path.all'Last loop
2028 if Gcc_Lib_Path (Index) = '/' then
2029 Gcc_Lib_Path (Index) := '\';
2030 end if;
2031 end loop;
2033 Linker_Options.Increment_Last;
2034 Linker_Options.Table (Linker_Options.Last) := Gcc_Lib_Path;
2035 Num_Args := Num_Args + 1;
2037 for Index in Flags_For_Linker'Range loop
2038 Linker_Options.Increment_Last;
2039 Linker_Options.Table (Linker_Options.Last) :=
2040 Flags_For_Linker (Index);
2041 Num_Args := Num_Args + 1;
2042 end loop;
2043 end;
2044 end if;
2046 -- Remove duplicate stack size setting from the Linker_Options
2047 -- table. The stack setting option "-Xlinker --stack=R,C" can be
2048 -- found in one line when set by a pragma Linker_Options or in two
2049 -- lines ("-Xlinker" then "--stack=R,C") when set on the command
2050 -- line. We also check for the "-Wl,--stack=R" style option.
2052 -- We must remove the second stack setting option instance
2053 -- because the one on the command line will always be the first
2054 -- one. And any subsequent stack setting option will overwrite the
2055 -- previous one. This is done especially for GNAT/NT where we set
2056 -- the stack size for tasking programs by a pragma in the NT
2057 -- specific tasking package System.Task_Primitives.Operations.
2059 -- Note: This is not a FOR loop that runs from Linker_Options.First
2060 -- to Linker_Options.Last, since operations within the loop can
2061 -- modify the length of the table.
2063 Clean_Link_Option_Set : declare
2064 J : Natural := Linker_Options.First;
2065 Shared_Libgcc_Seen : Boolean := False;
2067 begin
2068 while J <= Linker_Options.Last loop
2070 if Linker_Options.Table (J).all = "-Xlinker"
2071 and then J < Linker_Options.Last
2072 and then Linker_Options.Table (J + 1)'Length > 8
2073 and then Linker_Options.Table (J + 1) (1 .. 8) = "--stack="
2074 then
2075 if Stack_Op then
2076 Linker_Options.Table (J .. Linker_Options.Last - 2) :=
2077 Linker_Options.Table (J + 2 .. Linker_Options.Last);
2078 Linker_Options.Decrement_Last;
2079 Linker_Options.Decrement_Last;
2080 Num_Args := Num_Args - 2;
2082 else
2083 Stack_Op := True;
2084 end if;
2085 end if;
2087 -- Remove duplicate -shared-libgcc switch
2089 if Linker_Options.Table (J).all = Shared_Libgcc_String then
2090 if Shared_Libgcc_Seen then
2091 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2092 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2093 Linker_Options.Decrement_Last;
2094 Num_Args := Num_Args - 1;
2096 else
2097 Shared_Libgcc_Seen := True;
2098 end if;
2099 end if;
2101 -- Here we just check for a canonical form that matches the
2102 -- pragma Linker_Options set in the NT runtime.
2104 if (Linker_Options.Table (J)'Length > 17
2105 and then Linker_Options.Table (J) (1 .. 17)
2106 = "-Xlinker --stack=")
2107 or else
2108 (Linker_Options.Table (J)'Length > 12
2109 and then Linker_Options.Table (J) (1 .. 12)
2110 = "-Wl,--stack=")
2111 then
2112 if Stack_Op then
2113 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2114 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2115 Linker_Options.Decrement_Last;
2116 Num_Args := Num_Args - 1;
2118 else
2119 Stack_Op := True;
2120 end if;
2121 end if;
2123 -- Remove duplicate IDENTIFICATION directives (VMS)
2125 if Linker_Options.Table (J)'Length > 27
2126 and then Linker_Options.Table (J) (1 .. 28)
2127 = "--for-linker=IDENTIFICATION="
2128 then
2129 if IDENT_Op then
2130 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2131 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2132 Linker_Options.Decrement_Last;
2133 Num_Args := Num_Args - 1;
2134 else
2135 IDENT_Op := True;
2136 end if;
2137 end if;
2139 J := J + 1;
2140 end loop;
2142 if Linker_Path = Gcc_Path and then VM_Target = No_VM then
2144 -- For systems where the default is to link statically with
2145 -- libgcc, if gcc is not called with -shared-libgcc, call it
2146 -- with -static-libgcc, as there are some platforms where one
2147 -- of these two switches is compulsory to link.
2149 if Shared_Libgcc_Default = 'T'
2150 and then not Shared_Libgcc_Seen
2151 then
2152 Linker_Options.Increment_Last;
2153 Linker_Options.Table (Linker_Options.Last) := Static_Libgcc;
2154 Num_Args := Num_Args + 1;
2155 end if;
2157 elsif RTX_RTSS_Kernel_Module_On_Target then
2159 -- Force the use of the static libgcc for RTSS modules
2161 Linker_Options.Increment_Last;
2162 Linker_Options.Table (Linker_Options.Last) :=
2163 new String'("libgcc.a");
2164 Num_Args := Num_Args + 1;
2165 end if;
2167 end Clean_Link_Option_Set;
2169 -- Prepare arguments for call to linker
2171 Call_Linker : declare
2172 Success : Boolean;
2173 Args : Argument_List (1 .. Num_Args + 1);
2174 Index : Integer := Args'First;
2176 begin
2177 Args (Index) := Binder_Obj_File;
2179 -- Add the object files and any -largs libraries
2181 for J in Linker_Objects.First .. Linker_Objects.Last loop
2182 Index := Index + 1;
2183 Args (Index) := Linker_Objects.Table (J);
2184 end loop;
2186 -- Add the linker options from the binder file
2188 for J in Linker_Options.First .. Linker_Options.Last loop
2189 Index := Index + 1;
2190 Args (Index) := Linker_Options.Table (J);
2191 end loop;
2193 -- Finally add the libraries from the --GCC= switch
2195 for J in Gcc_Linker_Options.First .. Gcc_Linker_Options.Last loop
2196 Index := Index + 1;
2197 Args (Index) := Gcc_Linker_Options.Table (J);
2198 end loop;
2200 if Verbose_Mode then
2201 Write_Str (Linker_Path.all);
2203 for J in Args'Range loop
2204 Write_Str (" ");
2205 Write_Str (Args (J).all);
2206 end loop;
2208 Write_Eol;
2210 -- If we are on very verbose mode (-v -v) and a response file
2211 -- is used we display its content.
2213 if Very_Verbose_Mode and then Tname_FD /= Invalid_FD then
2214 Write_Eol;
2215 Write_Str ("Response file (" &
2216 Tname (Tname'First .. Tname'Last - 1) &
2217 ") content : ");
2218 Write_Eol;
2220 for J in
2221 Response_File_Objects.First ..
2222 Response_File_Objects.Last
2223 loop
2224 Write_Str (Response_File_Objects.Table (J).all);
2225 Write_Eol;
2226 end loop;
2228 Write_Eol;
2229 end if;
2230 end if;
2232 System.OS_Lib.Spawn (Linker_Path.all, Args, Success);
2234 -- Delete the temporary file used in conjunction with linking if
2235 -- one was created. See Process_Bind_File for details.
2237 if Tname_FD /= Invalid_FD then
2238 Delete (Tname);
2239 end if;
2241 if Lname /= null then
2242 Delete (Lname.all & ASCII.NUL);
2243 end if;
2245 if not Success then
2246 Error_Msg ("error when calling " & Linker_Path.all);
2247 Exit_Program (E_Fatal);
2248 end if;
2249 end Call_Linker;
2250 end Link_Step;
2251 end if;
2253 -- Only keep the binder output file and it's associated object
2254 -- file if compiling with the -g option. These files are only
2255 -- useful if debugging.
2257 if not Debug_Flag_Present then
2258 if Binder_Ali_File /= null then
2259 Delete (Binder_Ali_File.all & ASCII.NUL);
2260 end if;
2262 if Binder_Spec_Src_File /= null then
2263 Delete (Binder_Spec_Src_File.all & ASCII.NUL);
2264 end if;
2266 Delete (Binder_Body_Src_File.all & ASCII.NUL);
2268 if VM_Target = No_VM then
2269 Delete (Binder_Obj_File.all & ASCII.NUL);
2270 end if;
2271 end if;
2273 Exit_Program (E_Success);
2275 exception
2276 when X : others =>
2277 Write_Line (Exception_Information (X));
2278 Exit_With_Error ("INTERNAL ERROR. Please report");
2279 end Gnatlink;