PR target/58115
[official-gcc.git] / gcc / ada / gnatlink.adb
blob68262f447e44a24d8911c0888fe1eefe486098d0
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 and then File_Name (Findex2) /= '.' loop
269 Findex2 := Findex2 - 1;
270 end loop;
272 if Findex2 = Findex1 then
273 Findex2 := File_Name'Last + 1;
274 end if;
276 return File_Name (Findex1 .. Findex2 - 1);
277 end Base_Name;
279 -------------------------------
280 -- Check_Existing_Executable --
281 -------------------------------
283 procedure Check_Existing_Executable (File_Name : String) is
284 Ename : String := File_Name;
285 Efile : File_Name_Type;
286 Sfile : File_Name_Type;
288 begin
289 Canonical_Case_File_Name (Ename);
290 Name_Len := 0;
291 Add_Str_To_Name_Buffer (Ename);
292 Efile := Name_Find;
294 for J in Units.Table'First .. Units.Last loop
295 Sfile := Units.Table (J).Sfile;
296 if Sfile = Efile then
297 Exit_With_Error ("executable name """ & File_Name & """ matches "
298 & "source file name """ & Get_Name_String (Sfile) & """");
299 end if;
300 end loop;
302 Delete (File_Name);
303 end Check_Existing_Executable;
305 ------------
306 -- Delete --
307 ------------
309 procedure Delete (Name : String) is
310 Status : int;
311 pragma Unreferenced (Status);
312 begin
313 Status := unlink (Name'Address);
314 -- Is it really right to ignore an error here ???
315 end Delete;
317 ---------------
318 -- Error_Msg --
319 ---------------
321 procedure Error_Msg (Message : String) is
322 begin
323 Write_Str (Base_Command_Name.all);
324 Write_Str (": ");
325 Write_Str (Message);
326 Write_Eol;
327 end Error_Msg;
329 ---------------------
330 -- Exit_With_Error --
331 ---------------------
333 procedure Exit_With_Error (Error : String) is
334 begin
335 Error_Msg (Error);
336 Exit_Program (E_Fatal);
337 end Exit_With_Error;
339 ------------------
340 -- Process_Args --
341 ------------------
343 procedure Process_Args is
344 Next_Arg : Integer;
346 Skip_Next : Boolean := False;
347 -- Set to true if the next argument is to be added into the list of
348 -- linker's argument without parsing it.
350 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
352 -- Start of processing for Process_Args
354 begin
355 -- First, check for --version and --help
357 Check_Version_And_Help ("GNATLINK", "1996");
359 -- Loop through arguments of gnatlink command
361 Next_Arg := 1;
362 loop
363 exit when Next_Arg > Argument_Count;
365 Process_One_Arg : declare
366 Arg : constant String := Argument (Next_Arg);
368 begin
369 -- Case of argument which is a switch
371 -- We definitely need section by section comments here ???
373 if Skip_Next then
375 -- This argument must not be parsed, just add it to the
376 -- list of linker's options.
378 Skip_Next := False;
380 Linker_Options.Increment_Last;
381 Linker_Options.Table (Linker_Options.Last) :=
382 new String'(Arg);
384 elsif Arg'Length /= 0 and then Arg (1) = '-' then
385 if Arg'Length > 4 and then Arg (2 .. 5) = "gnat" then
386 Exit_With_Error
387 ("invalid switch: """ & Arg & """ (gnat not needed here)");
388 end if;
390 if Arg = "-Xlinker" then
392 -- Next argument should be sent directly to the linker.
393 -- We do not want to parse it here.
395 Skip_Next := True;
397 Linker_Options.Increment_Last;
398 Linker_Options.Table (Linker_Options.Last) :=
399 new String'(Arg);
401 elsif Arg (2) = 'g'
402 and then (Arg'Length < 5 or else Arg (2 .. 5) /= "gnat")
403 then
404 Debug_Flag_Present := True;
406 Linker_Options.Increment_Last;
407 Linker_Options.Table (Linker_Options.Last) :=
408 new String'(Arg);
410 Binder_Options.Increment_Last;
411 Binder_Options.Table (Binder_Options.Last) :=
412 Linker_Options.Table (Linker_Options.Last);
414 elsif Arg'Length >= 3 and then Arg (2) = 'M' then
415 declare
416 Switches : String_List_Access;
418 begin
419 Convert (Map_File, Arg (3 .. Arg'Last), Switches);
421 if Switches /= null then
422 for J in Switches'Range loop
423 Linker_Options.Increment_Last;
424 Linker_Options.Table (Linker_Options.Last) :=
425 Switches (J);
426 end loop;
427 end if;
428 end;
430 elsif Arg'Length = 2 then
431 case Arg (2) is
432 when 'b' =>
433 Linker_Options.Increment_Last;
434 Linker_Options.Table (Linker_Options.Last) :=
435 new String'(Arg);
437 Binder_Options.Increment_Last;
438 Binder_Options.Table (Binder_Options.Last) :=
439 Linker_Options.Table (Linker_Options.Last);
441 Next_Arg := Next_Arg + 1;
443 if Next_Arg > Argument_Count then
444 Exit_With_Error ("Missing argument for -b");
445 end if;
447 Get_Machine_Name : declare
448 Name_Arg : constant String_Access :=
449 new String'(Argument (Next_Arg));
451 begin
452 Linker_Options.Increment_Last;
453 Linker_Options.Table (Linker_Options.Last) :=
454 Name_Arg;
456 Binder_Options.Increment_Last;
457 Binder_Options.Table (Binder_Options.Last) :=
458 Name_Arg;
460 end Get_Machine_Name;
462 when 'f' =>
463 if Object_List_File_Supported then
464 Object_List_File_Required := True;
465 else
466 Exit_With_Error
467 ("Object list file not supported on this target");
468 end if;
470 when 'M' =>
471 Create_Map_File := True;
473 when 'n' =>
474 Compile_Bind_File := False;
476 when 'o' =>
477 Next_Arg := Next_Arg + 1;
479 if Next_Arg > Argument_Count then
480 Exit_With_Error ("Missing argument for -o");
481 end if;
483 Output_File_Name :=
484 new String'(Executable_Name
485 (Argument (Next_Arg),
486 Only_If_No_Suffix => True));
488 when 'P' =>
489 Opt.CodePeer_Mode := True;
491 when 'R' =>
492 Opt.Run_Path_Option := False;
494 when 'v' =>
496 -- Support "double" verbose mode. Second -v
497 -- gets sent to the linker and binder phases.
499 if Verbose_Mode then
500 Very_Verbose_Mode := True;
502 Linker_Options.Increment_Last;
503 Linker_Options.Table (Linker_Options.Last) :=
504 new String'(Arg);
506 Binder_Options.Increment_Last;
507 Binder_Options.Table (Binder_Options.Last) :=
508 Linker_Options.Table (Linker_Options.Last);
510 else
511 Verbose_Mode := True;
513 end if;
515 when others =>
516 Linker_Options.Increment_Last;
517 Linker_Options.Table (Linker_Options.Last) :=
518 new String'(Arg);
520 end case;
522 elsif Arg (2) = 'B' then
523 Linker_Options.Increment_Last;
524 Linker_Options.Table (Linker_Options.Last) :=
525 new String'(Arg);
527 Binder_Options.Increment_Last;
528 Binder_Options.Table (Binder_Options.Last) :=
529 Linker_Options.Table (Linker_Options.Last);
531 elsif Arg'Length >= 7 and then Arg (1 .. 7) = "--LINK=" then
532 if Arg'Length = 7 then
533 Exit_With_Error ("Missing argument for --LINK=");
534 end if;
536 Linker_Path :=
537 System.OS_Lib.Locate_Exec_On_Path (Arg (8 .. Arg'Last));
539 if Linker_Path = null then
540 Exit_With_Error
541 ("Could not locate linker: " & Arg (8 .. Arg'Last));
542 end if;
544 elsif Arg'Length > 6 and then Arg (1 .. 6) = "--GCC=" then
545 declare
546 Program_Args : constant Argument_List_Access :=
547 Argument_String_To_List
548 (Arg (7 .. Arg'Last));
550 begin
551 if Program_Args.all (1).all /= Gcc.all then
552 Gcc := new String'(Program_Args.all (1).all);
553 Standard_Gcc := False;
554 end if;
556 -- Set appropriate flags for switches passed
558 for J in 2 .. Program_Args.all'Last loop
559 declare
560 Arg : constant String := Program_Args.all (J).all;
561 AF : constant Integer := Arg'First;
563 begin
564 if Arg'Length /= 0 and then Arg (AF) = '-' then
565 if Arg (AF + 1) = 'g'
566 and then (Arg'Length = 2
567 or else Arg (AF + 2) in '0' .. '3'
568 or else Arg (AF + 2 .. Arg'Last) = "coff")
569 then
570 Debug_Flag_Present := True;
571 end if;
572 end if;
574 -- Add directory to source search dirs so that
575 -- Get_Target_Parameters can find system.ads
577 if Arg (AF .. AF + 1) = "-I"
578 and then Arg'Length > 2
579 then
580 Add_Src_Search_Dir (Arg (AF + 2 .. Arg'Last));
581 end if;
583 -- Pass to gcc for compiling binder generated file
584 -- No use passing libraries, it will just generate
585 -- a warning
587 if not (Arg (AF .. AF + 1) = "-l"
588 or else Arg (AF .. AF + 1) = "-L")
589 then
590 Binder_Options.Increment_Last;
591 Binder_Options.Table (Binder_Options.Last) :=
592 new String'(Arg);
593 end if;
595 -- Pass to gcc for linking program
597 Gcc_Linker_Options.Increment_Last;
598 Gcc_Linker_Options.Table
599 (Gcc_Linker_Options.Last) := new String'(Arg);
600 end;
601 end loop;
602 end;
604 -- Send all multi-character switches not recognized as
605 -- a special case by gnatlink to the linker/loader stage.
607 else
608 Linker_Options.Increment_Last;
609 Linker_Options.Table (Linker_Options.Last) :=
610 new String'(Arg);
611 end if;
613 -- Here if argument is a file name rather than a switch
615 else
616 -- If explicit ali file, capture it
618 if Arg'Length > 4
619 and then Arg (Arg'Last - 3 .. Arg'Last) = ".ali"
620 then
621 if Ali_File_Name = null then
622 Ali_File_Name := new String'(Arg);
623 else
624 Exit_With_Error ("cannot handle more than one ALI file");
625 end if;
627 -- If target object file, record object file
629 elsif Arg'Length > Get_Target_Object_Suffix.all'Length
630 and then Arg
631 (Arg'Last -
632 Get_Target_Object_Suffix.all'Length + 1 .. Arg'Last)
633 = Get_Target_Object_Suffix.all
634 then
635 Linker_Objects.Increment_Last;
636 Linker_Objects.Table (Linker_Objects.Last) :=
637 new String'(Arg);
639 -- If host object file, record object file e.g. accept foo.o
640 -- as well as foo.obj on VMS target.
642 elsif Arg'Length > Get_Object_Suffix.all'Length
643 and then Arg
644 (Arg'Last - Get_Object_Suffix.all'Length + 1 .. Arg'Last)
645 = Get_Object_Suffix.all
646 then
647 Linker_Objects.Increment_Last;
648 Linker_Objects.Table (Linker_Objects.Last) :=
649 new String'(Arg);
651 -- If corresponding ali file exists, capture it
653 elsif Ali_File_Name = null
654 and then Is_Regular_File (Arg & ".ali")
655 then
656 Ali_File_Name := new String'(Arg & ".ali");
658 -- Otherwise assume this is a linker options entry, but
659 -- see below for interesting adjustment to this assumption.
661 else
662 Linker_Options.Increment_Last;
663 Linker_Options.Table (Linker_Options.Last) :=
664 new String'(Arg);
665 end if;
666 end if;
667 end Process_One_Arg;
669 Next_Arg := Next_Arg + 1;
670 end loop;
672 -- Compile the bind file with warnings suppressed, because
673 -- otherwise the with of the main program may cause junk warnings.
675 Binder_Options.Increment_Last;
676 Binder_Options.Table (Binder_Options.Last) := new String'("-gnatws");
678 -- If we did not get an ali file at all, and we had at least one
679 -- linker option, then assume that was the intended ali file after
680 -- all, so that we get a nicer message later on.
682 if Ali_File_Name = null
683 and then Linker_Options.Last >= Linker_Options.First
684 then
685 Ali_File_Name :=
686 new String'(Linker_Options.Table (Linker_Options.First).all
687 & ".ali");
688 end if;
689 end Process_Args;
691 -------------------------
692 -- Process_Binder_File --
693 -------------------------
695 procedure Process_Binder_File (Name : String) is
696 Fd : FILEs;
697 -- Binder file's descriptor
699 Link_Bytes : Integer := 0;
700 -- Projected number of bytes for the linker command line
702 Link_Max : Integer;
703 pragma Import (C, Link_Max, "__gnat_link_max");
704 -- Maximum number of bytes on the command line supported by the OS
705 -- linker. Passed this limit the response file mechanism must be used
706 -- if supported.
708 Next_Line : String (1 .. 1000);
709 -- Current line value
711 Nlast : Integer;
712 Nfirst : Integer;
713 -- Current line slice (the slice does not contain line terminator)
715 Last : Integer;
716 -- Current line last character for shared libraries (without version)
718 Objs_Begin : Integer := 0;
719 -- First object file index in Linker_Objects table
721 Objs_End : Integer := 0;
722 -- Last object file index in Linker_Objects table
724 Status : int;
725 pragma Warnings (Off, Status);
726 -- Used for various Interfaces.C_Streams calls
728 Closing_Status : Boolean;
729 pragma Warnings (Off, Closing_Status);
730 -- For call to Close
732 GNAT_Static : Boolean := False;
733 -- Save state of -static option
735 GNAT_Shared : Boolean := False;
736 -- Save state of -shared option
738 Xlinker_Was_Previous : Boolean := False;
739 -- Indicate that "-Xlinker" was the option preceding the current
740 -- option. If True, then the current option is never suppressed.
742 -- Rollback data
744 -- These data items are used to store current binder file context.
745 -- The context is composed of the file descriptor position and the
746 -- current line together with the slice indexes (first and last
747 -- position) for this line. The rollback data are used by the
748 -- Store_File_Context and Rollback_File_Context routines below.
749 -- The file context mechanism interact only with the Get_Next_Line
750 -- call. For example:
752 -- Store_File_Context;
753 -- Get_Next_Line;
754 -- Rollback_File_Context;
755 -- Get_Next_Line;
757 -- Both Get_Next_Line calls above will read the exact same data from
758 -- the file. In other words, Next_Line, Nfirst and Nlast variables
759 -- will be set with the exact same values.
761 RB_File_Pos : long; -- File position
762 RB_Next_Line : String (1 .. 1000); -- Current line content
763 RB_Nlast : Integer; -- Slice last index
764 RB_Nfirst : Integer; -- Slice first index
766 Run_Path_Option_Ptr : Interfaces.C.Strings.chars_ptr;
767 pragma Import (C, Run_Path_Option_Ptr, "__gnat_run_path_option");
768 -- Pointer to string representing the native linker option which
769 -- specifies the path where the dynamic loader should find shared
770 -- libraries. Equal to null string if this system doesn't support it.
772 Libgcc_Subdir_Ptr : Interfaces.C.Strings.chars_ptr;
773 pragma Import (C, Libgcc_Subdir_Ptr, "__gnat_default_libgcc_subdir");
774 -- Pointer to string indicating the installation subdirectory where
775 -- a default shared libgcc might be found.
777 Object_Library_Ext_Ptr : Interfaces.C.Strings.chars_ptr;
778 pragma Import
779 (C, Object_Library_Ext_Ptr, "__gnat_object_library_extension");
780 -- Pointer to string specifying the default extension for
781 -- object libraries, e.g. Unix uses ".a", VMS uses ".olb".
783 Separate_Run_Path_Options : Boolean;
784 for Separate_Run_Path_Options'Size use Character'Size;
785 pragma Import
786 (C, Separate_Run_Path_Options, "__gnat_separate_run_path_options");
787 -- Whether separate rpath options should be emitted for each directory
789 procedure Get_Next_Line;
790 -- Read the next line from the binder file without the line
791 -- terminator.
793 function Index (S, Pattern : String) return Natural;
794 -- Return the last occurrence of Pattern in S, or 0 if none
796 function Is_Option_Present (Opt : String) return Boolean;
797 -- Return true if the option Opt is already present in
798 -- Linker_Options table.
800 procedure Store_File_Context;
801 -- Store current file context, Fd position and current line data.
802 -- The file context is stored into the rollback data above (RB_*).
803 -- Store_File_Context can be called at any time, only the last call
804 -- will be used (i.e. this routine overwrites the file context).
806 procedure Rollback_File_Context;
807 -- Restore file context from rollback data. This routine must be called
808 -- after Store_File_Context. The binder file context will be restored
809 -- with the data stored by the last Store_File_Context call.
811 procedure Write_RF (S : String);
812 -- Write a string to the response file and check if it was successful.
813 -- Fail the program if it was not successful (disk full).
815 -------------------
816 -- Get_Next_Line --
817 -------------------
819 procedure Get_Next_Line is
820 Fchars : chars;
822 begin
823 Fchars := fgets (Next_Line'Address, Next_Line'Length, Fd);
825 if Fchars = System.Null_Address then
826 Exit_With_Error ("Error reading binder output");
827 end if;
829 Nfirst := Next_Line'First;
830 Nlast := Nfirst;
831 while Nlast <= Next_Line'Last
832 and then Next_Line (Nlast) /= ASCII.LF
833 and then Next_Line (Nlast) /= ASCII.CR
834 loop
835 Nlast := Nlast + 1;
836 end loop;
838 Nlast := Nlast - 1;
839 end Get_Next_Line;
841 -----------
842 -- Index --
843 -----------
845 function Index (S, Pattern : String) return Natural is
846 Len : constant Natural := Pattern'Length;
848 begin
849 for J in reverse S'First .. S'Last - Len + 1 loop
850 if Pattern = S (J .. J + Len - 1) then
851 return J;
852 end if;
853 end loop;
855 return 0;
856 end Index;
858 -----------------------
859 -- Is_Option_Present --
860 -----------------------
862 function Is_Option_Present (Opt : String) return Boolean is
863 begin
864 for I in 1 .. Linker_Options.Last loop
866 if Linker_Options.Table (I).all = Opt then
867 return True;
868 end if;
870 end loop;
872 return False;
873 end Is_Option_Present;
875 ---------------------------
876 -- Rollback_File_Context --
877 ---------------------------
879 procedure Rollback_File_Context is
880 begin
881 Next_Line := RB_Next_Line;
882 Nfirst := RB_Nfirst;
883 Nlast := RB_Nlast;
884 Status := fseek (Fd, RB_File_Pos, Interfaces.C_Streams.SEEK_SET);
886 if Status = -1 then
887 Exit_With_Error ("Error setting file position");
888 end if;
889 end Rollback_File_Context;
891 ------------------------
892 -- Store_File_Context --
893 ------------------------
895 procedure Store_File_Context is
896 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 -- Nlast - Nfirst + 1, for the size, plus one for the space between
999 -- each arguments.
1001 Link_Bytes := Link_Bytes + Nlast - Nfirst + 2;
1002 end loop;
1004 Objs_End := Linker_Objects.Last;
1006 -- Continue to compute the Link_Bytes, the linker options are part of
1007 -- command line length.
1009 Store_File_Context;
1011 while Next_Line (Nfirst .. Nlast) /= End_Info loop
1012 Link_Bytes := Link_Bytes + Nlast - Nfirst + 2;
1013 Get_Next_Line;
1014 end loop;
1016 Rollback_File_Context;
1018 -- On systems that have limitations on handling very long linker lines
1019 -- we make use of the system linker option which takes a list of object
1020 -- file names from a file instead of the command line itself. What we do
1021 -- is to replace the list of object files by the special linker option
1022 -- which then reads the object file list from a file instead. The option
1023 -- to read from a file instead of the command line is only triggered if
1024 -- a conservative threshold is passed.
1026 if Object_List_File_Required
1027 or else (Object_List_File_Supported
1028 and then Link_Bytes > Link_Max)
1029 then
1030 -- Create a temporary file containing the Ada user object files
1031 -- needed by the link. This list is taken from the bind file and is
1032 -- output one object per line for maximal compatibility with linkers
1033 -- supporting this option.
1035 Create_Temp_File (Tname_FD, Tname);
1037 -- ??? File descriptor should be checked to not be Invalid_FD.
1038 -- ??? Status of Write and Close operations should be checked, and
1039 -- failure should occur if a status is wrong.
1041 for J in Objs_Begin .. Objs_End loop
1042 Write_RF (Linker_Objects.Table (J).all);
1044 Response_File_Objects.Increment_Last;
1045 Response_File_Objects.Table (Response_File_Objects.Last) :=
1046 Linker_Objects.Table (J);
1047 end loop;
1049 Close (Tname_FD, Closing_Status);
1051 -- Add the special objects list file option together with the name
1052 -- of the temporary file (removing the null character) to the objects
1053 -- file table.
1055 Linker_Objects.Table (Objs_Begin) :=
1056 new String'(Object_File_Option &
1057 Tname (Tname'First .. Tname'Last - 1));
1059 -- The slots containing these object file names are then removed
1060 -- from the objects table so they do not appear in the link. They are
1061 -- removed by moving up the linker options and non-Ada object files
1062 -- appearing after the Ada object list in the table.
1064 declare
1065 N : Integer;
1067 begin
1068 N := Objs_End - Objs_Begin + 1;
1070 for J in Objs_End + 1 .. Linker_Objects.Last loop
1071 Linker_Objects.Table (J - N + 1) := Linker_Objects.Table (J);
1072 end loop;
1074 Linker_Objects.Set_Last (Linker_Objects.Last - N + 1);
1075 end;
1076 end if;
1078 -- Process switches and options
1080 if Next_Line (Nfirst .. Nlast) /= End_Info then
1081 Xlinker_Was_Previous := False;
1083 loop
1084 if Xlinker_Was_Previous
1085 or else Next_Line (Nfirst .. Nlast) = "-Xlinker"
1086 then
1087 Linker_Options.Increment_Last;
1088 Linker_Options.Table (Linker_Options.Last) :=
1089 new String'(Next_Line (Nfirst .. Nlast));
1091 elsif Next_Line (Nfirst .. Nlast) = "-static" then
1092 GNAT_Static := True;
1094 elsif Next_Line (Nfirst .. Nlast) = "-shared" then
1095 GNAT_Shared := True;
1097 -- Add binder options only if not already set on the command line.
1098 -- This rule is a way to control the linker options order.
1100 -- The following test needs comments, why is it VMS specific.
1101 -- The above comment looks out of date ???
1103 elsif not (OpenVMS_On_Target
1104 and then
1105 Is_Option_Present (Next_Line (Nfirst .. Nlast)))
1106 then
1107 if Nlast > Nfirst + 2 and then
1108 Next_Line (Nfirst .. Nfirst + 1) = "-L"
1109 then
1110 -- Construct a library search path for use later to locate
1111 -- static gnatlib libraries.
1113 if Libpath.Last > 1 then
1114 Libpath.Increment_Last;
1115 Libpath.Table (Libpath.Last) := Path_Separator;
1116 end if;
1118 for I in Nfirst + 2 .. Nlast loop
1119 Libpath.Increment_Last;
1120 Libpath.Table (Libpath.Last) := Next_Line (I);
1121 end loop;
1123 Linker_Options.Increment_Last;
1125 Linker_Options.Table (Linker_Options.Last) :=
1126 new String'(Next_Line (Nfirst .. Nlast));
1128 elsif Next_Line (Nfirst .. Nlast) = "-ldecgnat"
1129 or else Next_Line (Nfirst .. Nlast) = "-lgnarl"
1130 or else Next_Line (Nfirst .. Nlast) = "-lgnat"
1131 or else
1132 Next_Line
1133 (1 .. Natural'Min (Nlast, 8 + Library_Version'Length)) =
1134 Shared_Lib ("gnarl")
1135 or else
1136 Next_Line
1137 (1 .. Natural'Min (Nlast, 7 + Library_Version'Length)) =
1138 Shared_Lib ("gnat")
1139 then
1140 -- If it is a shared library, remove the library version.
1141 -- We will be looking for the static version of the library
1142 -- as it is in the same directory as the shared version.
1144 if Next_Line (Nlast - Library_Version'Length + 1 .. Nlast) =
1145 Library_Version
1146 then
1147 -- Set Last to point to last character before the
1148 -- library version.
1150 Last := Nlast - Library_Version'Length - 1;
1151 else
1152 Last := Nlast;
1153 end if;
1155 -- Given a Gnat standard library, search the library path to
1156 -- find the library location.
1158 -- Shouldn't we abstract a proc here, we are getting awfully
1159 -- heavily nested ???
1161 declare
1162 File_Path : String_Access;
1164 Object_Lib_Extension : constant String :=
1165 Value (Object_Library_Ext_Ptr);
1167 File_Name : constant String := "lib" &
1168 Next_Line (Nfirst + 2 .. Last) & Object_Lib_Extension;
1170 Run_Path_Opt : constant String :=
1171 Value (Run_Path_Option_Ptr);
1173 GCC_Index : Natural;
1174 Run_Path_Opt_Index : Natural := 0;
1176 begin
1177 File_Path :=
1178 Locate_Regular_File (File_Name,
1179 String (Libpath.Table (1 .. Libpath.Last)));
1181 if File_Path /= null then
1182 if GNAT_Static then
1184 -- If static gnatlib found, explicitly specify to
1185 -- overcome possible linker default usage of shared
1186 -- version.
1188 Linker_Options.Increment_Last;
1190 Linker_Options.Table (Linker_Options.Last) :=
1191 new String'(File_Path.all);
1193 elsif GNAT_Shared then
1194 if Opt.Run_Path_Option then
1196 -- If shared gnatlib desired, add appropriate
1197 -- system specific switch so that it can be
1198 -- located at runtime.
1200 if Run_Path_Opt'Length /= 0 then
1202 -- Output the system specific linker command
1203 -- that allows the image activator to find
1204 -- the shared library at runtime. Also add
1205 -- path to find libgcc_s.so, if relevant.
1207 declare
1208 Path : String (1 .. File_Path'Length + 15);
1210 Path_Last : constant Natural :=
1211 File_Path'Length;
1213 begin
1214 Path (1 .. File_Path'Length) :=
1215 File_Path.all;
1217 -- To find the location of the shared version
1218 -- of libgcc, we look for "gcc-lib" in the
1219 -- path of the library. However, this
1220 -- subdirectory is no longer present in
1221 -- recent versions of GCC. So, we look for
1222 -- the last subdirectory "lib" in the path.
1224 GCC_Index :=
1225 Index (Path (1 .. Path_Last), "gcc-lib");
1227 if GCC_Index /= 0 then
1229 -- The shared version of libgcc is
1230 -- located in the parent directory.
1232 GCC_Index := GCC_Index - 1;
1234 else
1235 GCC_Index :=
1236 Index
1237 (Path (1 .. Path_Last),
1238 "/lib/");
1240 if GCC_Index = 0 then
1241 GCC_Index :=
1242 Index (Path (1 .. Path_Last),
1243 Directory_Separator &
1244 "lib" &
1245 Directory_Separator);
1246 end if;
1248 -- If we have found a "lib" subdir in
1249 -- the path to libgnat, the possible
1250 -- shared libgcc of interest by default
1251 -- is in libgcc_subdir at the same
1252 -- level.
1254 if GCC_Index /= 0 then
1255 declare
1256 Subdir : constant String :=
1257 Value (Libgcc_Subdir_Ptr);
1258 begin
1259 Path
1260 (GCC_Index + 1 ..
1261 GCC_Index + Subdir'Length) :=
1262 Subdir;
1263 GCC_Index :=
1264 GCC_Index + Subdir'Length;
1265 end;
1266 end if;
1267 end if;
1269 -- Look for an eventual run_path_option in
1270 -- the linker switches.
1272 if Separate_Run_Path_Options then
1273 Linker_Options.Increment_Last;
1274 Linker_Options.Table
1275 (Linker_Options.Last) :=
1276 new String'
1277 (Run_Path_Opt
1278 & File_Path
1279 (1 .. File_Path'Length
1280 - File_Name'Length));
1282 if GCC_Index /= 0 then
1283 Linker_Options.Increment_Last;
1284 Linker_Options.Table
1285 (Linker_Options.Last) :=
1286 new String'
1287 (Run_Path_Opt
1288 & Path (1 .. GCC_Index));
1289 end if;
1291 else
1292 for J in reverse
1293 1 .. Linker_Options.Last
1294 loop
1295 if Linker_Options.Table (J) /= null
1296 and then
1297 Linker_Options.Table (J)'Length
1298 > Run_Path_Opt'Length
1299 and then
1300 Linker_Options.Table (J)
1301 (1 .. Run_Path_Opt'Length) =
1302 Run_Path_Opt
1303 then
1304 -- We have found an already
1305 -- specified run_path_option:
1306 -- we will add to this
1307 -- switch, because only one
1308 -- run_path_option should be
1309 -- specified.
1311 Run_Path_Opt_Index := J;
1312 exit;
1313 end if;
1314 end loop;
1316 -- If there is no run_path_option, we
1317 -- need to add one.
1319 if Run_Path_Opt_Index = 0 then
1320 Linker_Options.Increment_Last;
1321 end if;
1323 if GCC_Index = 0 then
1324 if Run_Path_Opt_Index = 0 then
1325 Linker_Options.Table
1326 (Linker_Options.Last) :=
1327 new String'
1328 (Run_Path_Opt
1329 & File_Path
1330 (1 .. File_Path'Length
1331 - File_Name'Length));
1333 else
1334 Linker_Options.Table
1335 (Run_Path_Opt_Index) :=
1336 new String'
1337 (Linker_Options.Table
1338 (Run_Path_Opt_Index).all
1339 & Path_Separator
1340 & File_Path
1341 (1 .. File_Path'Length
1342 - File_Name'Length));
1343 end if;
1345 else
1346 if Run_Path_Opt_Index = 0 then
1347 Linker_Options.Table
1348 (Linker_Options.Last) :=
1349 new String'
1350 (Run_Path_Opt
1351 & File_Path
1352 (1 .. File_Path'Length
1353 - File_Name'Length)
1354 & Path_Separator
1355 & Path (1 .. GCC_Index));
1357 else
1358 Linker_Options.Table
1359 (Run_Path_Opt_Index) :=
1360 new String'
1361 (Linker_Options.Table
1362 (Run_Path_Opt_Index).all
1363 & Path_Separator
1364 & File_Path
1365 (1 .. File_Path'Length
1366 - File_Name'Length)
1367 & Path_Separator
1368 & Path (1 .. GCC_Index));
1369 end if;
1370 end if;
1371 end if;
1372 end;
1373 end if;
1374 end if;
1376 -- Then we add the appropriate -l switch
1378 Linker_Options.Increment_Last;
1379 Linker_Options.Table (Linker_Options.Last) :=
1380 new String'(Next_Line (Nfirst .. Nlast));
1381 end if;
1383 else
1384 -- If gnatlib library not found, then add it anyway in
1385 -- case some other mechanism may find it.
1387 Linker_Options.Increment_Last;
1388 Linker_Options.Table (Linker_Options.Last) :=
1389 new String'(Next_Line (Nfirst .. Nlast));
1390 end if;
1391 end;
1392 else
1393 Linker_Options.Increment_Last;
1394 Linker_Options.Table (Linker_Options.Last) :=
1395 new String'(Next_Line (Nfirst .. Nlast));
1396 end if;
1397 end if;
1399 Xlinker_Was_Previous := Next_Line (Nfirst .. Nlast) = "-Xlinker";
1401 Get_Next_Line;
1402 exit when Next_Line (Nfirst .. Nlast) = End_Info;
1404 Next_Line (Nfirst .. Nlast - 8) := Next_Line (Nfirst + 8 .. Nlast);
1405 Nlast := Nlast - 8;
1406 end loop;
1407 end if;
1409 -- If -shared was specified, invoke gcc with -shared-libgcc
1411 if GNAT_Shared then
1412 Linker_Options.Increment_Last;
1413 Linker_Options.Table (Linker_Options.Last) := Shared_Libgcc;
1414 end if;
1416 Status := fclose (Fd);
1417 end Process_Binder_File;
1419 --------------
1420 -- To_Lower --
1421 --------------
1423 function To_Lower (A : Character) return Character is
1424 A_Val : constant Natural := Character'Pos (A);
1426 begin
1427 if A in 'A' .. 'Z'
1428 or else A_Val in 16#C0# .. 16#D6#
1429 or else A_Val in 16#D8# .. 16#DE#
1430 then
1431 return Character'Val (A_Val + 16#20#);
1432 else
1433 return A;
1434 end if;
1435 end To_Lower;
1437 procedure To_Lower (A : in out String) is
1438 begin
1439 for J in A'Range loop
1440 A (J) := To_Lower (A (J));
1441 end loop;
1442 end To_Lower;
1444 -----------
1445 -- Usage --
1446 -----------
1448 procedure Usage is
1449 begin
1450 Write_Str ("Usage: ");
1451 Write_Str (Base_Command_Name.all);
1452 Write_Str (" switches mainprog.ali [non-Ada-objects] [linker-options]");
1453 Write_Eol;
1454 Write_Eol;
1455 Write_Line (" mainprog.ali the ALI file of the main program");
1456 Write_Eol;
1457 Write_Eol;
1458 Display_Usage_Version_And_Help;
1459 Write_Line (" -f Force object file list to be generated");
1460 Write_Line (" -g Compile binder source file with debug information");
1461 Write_Line (" -n Do not compile the binder source file");
1462 Write_Line (" -P Process files for use by CodePeer");
1463 Write_Line (" -R Do not use a run_path_option");
1464 Write_Line (" -v Verbose mode");
1465 Write_Line (" -v -v Very verbose mode");
1466 Write_Eol;
1467 Write_Line (" -o nam Use 'nam' as the name of the executable");
1468 Write_Line (" -b target Compile the binder source to run on target");
1469 Write_Line (" -Bdir Load compiler executables from dir");
1471 if Is_Supported (Map_File) then
1472 Write_Line (" -Mmap Create map file map");
1473 Write_Line (" -M Create map file mainprog.map");
1474 end if;
1476 Write_Line (" --GCC=comp Use comp as the compiler");
1477 Write_Line (" --LINK=nam Use 'nam' for the linking rather than 'gcc'");
1478 Write_Eol;
1479 Write_Line (" [non-Ada-objects] list of non Ada object files");
1480 Write_Line (" [linker-options] other options for the linker");
1481 end Usage;
1483 ------------------
1484 -- Write_Header --
1485 ------------------
1487 procedure Write_Header is
1488 begin
1489 if Verbose_Mode then
1490 Write_Eol;
1491 Display_Version ("GNATLINK", "1995");
1492 end if;
1493 end Write_Header;
1495 -----------------
1496 -- Write_Usage --
1497 -----------------
1499 procedure Write_Usage is
1500 begin
1501 Write_Header;
1502 Usage;
1503 end Write_Usage;
1505 -- Start of processing for Gnatlink
1507 begin
1508 -- Add the directory where gnatlink is invoked in front of the path, if
1509 -- gnatlink is invoked with directory information. Only do this if the
1510 -- platform is not VMS, where the notion of path does not really exist.
1512 if not Hostparm.OpenVMS then
1513 declare
1514 Command : constant String := Command_Name;
1516 begin
1517 for Index in reverse Command'Range loop
1518 if Command (Index) = Directory_Separator then
1519 declare
1520 Absolute_Dir : constant String :=
1521 Normalize_Pathname
1522 (Command (Command'First .. Index));
1524 PATH : constant String :=
1525 Absolute_Dir &
1526 Path_Separator &
1527 Getenv ("PATH").all;
1529 begin
1530 Setenv ("PATH", PATH);
1531 end;
1533 exit;
1534 end if;
1535 end loop;
1536 end;
1537 end if;
1539 Base_Command_Name := new String'(Base_Name (Command_Name));
1541 -- Fold to lower case "GNATLINK" on VMS to be consistent with output
1542 -- from other GNAT utilities.
1544 if Hostparm.OpenVMS then
1545 To_Lower (Base_Command_Name.all);
1546 end if;
1548 Process_Args;
1550 if Argument_Count = 0
1551 or else (Verbose_Mode and then Argument_Count = 1)
1552 then
1553 Write_Usage;
1554 Exit_Program (E_Fatal);
1555 end if;
1557 -- Initialize packages to be used
1559 Csets.Initialize;
1560 Snames.Initialize;
1562 -- We always compile with -c
1564 Binder_Options_From_ALI.Increment_Last;
1565 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1566 new String'("-c");
1568 if Ali_File_Name = null then
1569 Exit_With_Error ("no ali file given for link");
1570 end if;
1572 if not Is_Regular_File (Ali_File_Name.all) then
1573 Exit_With_Error (Ali_File_Name.all & " not found");
1574 end if;
1576 -- Read the ALI file of the main subprogram if the binder generated file
1577 -- needs to be compiled and no --GCC= switch has been specified. Fetch the
1578 -- back end switches from this ALI file and use these switches to compile
1579 -- the binder generated file
1581 if Compile_Bind_File and then Standard_Gcc then
1582 Initialize_ALI;
1583 Name_Len := Ali_File_Name'Length;
1584 Name_Buffer (1 .. Name_Len) := Ali_File_Name.all;
1586 declare
1587 use Types;
1588 F : constant File_Name_Type := Name_Find;
1589 T : Text_Buffer_Ptr;
1590 A : ALI_Id;
1592 begin
1593 -- Load the ALI file
1595 T := Read_Library_Info (F, True);
1597 -- Read it. Note that we ignore errors, since we only want very
1598 -- limited information from the ali file, and likely a slightly
1599 -- wrong version will be just fine, though in normal operation
1600 -- we don't expect this to happen!
1602 A := Scan_ALI
1605 Ignore_ED => False,
1606 Err => False,
1607 Ignore_Errors => True);
1609 if A /= No_ALI_Id then
1611 Index in Units.Table (ALIs.Table (A).First_Unit).First_Arg ..
1612 Units.Table (ALIs.Table (A).First_Unit).Last_Arg
1613 loop
1614 -- Do not compile with the front end switches. However, --RTS
1615 -- is to be dealt with specially because it needs to be passed
1616 -- if the binder-generated file is in Ada and may also be used
1617 -- to drive the linker.
1619 declare
1620 Arg : String_Ptr renames Args.Table (Index);
1621 begin
1622 if not Is_Front_End_Switch (Arg.all) then
1623 Binder_Options_From_ALI.Increment_Last;
1624 Binder_Options_From_ALI.Table
1625 (Binder_Options_From_ALI.Last) := String_Access (Arg);
1627 elsif Arg'Length > 5
1628 and then Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
1629 then
1630 Binder_Options_From_ALI.Increment_Last;
1631 Binder_Options_From_ALI.Table
1632 (Binder_Options_From_ALI.Last) := String_Access (Arg);
1634 -- Set the RTS_*_Path_Name variables, so that
1635 -- the correct directories will be set when
1636 -- Osint.Add_Default_Search_Dirs will be called later.
1638 Opt.RTS_Src_Path_Name :=
1639 Get_RTS_Search_Dir
1640 (Arg (Arg'First + 6 .. Arg'Last), Include);
1642 Opt.RTS_Lib_Path_Name :=
1643 Get_RTS_Search_Dir
1644 (Arg (Arg'First + 6 .. Arg'Last), Objects);
1646 -- GNAT doesn't support the GCC multilib mechanism.
1647 -- This means that, when a multilib switch is used
1648 -- to request a particular compilation mode, the
1649 -- corresponding runtime switch (--RTS) must also be
1650 -- specified. The long-term goal is to fully support the
1651 -- multilib mechanism; however, in the meantime, it is
1652 -- convenient to eliminate the redundancy by keying the
1653 -- compilation mode on a single switch, namely --RTS.
1655 -- Pass -mrtp to the linker if --RTS=rtp was passed
1657 if Arg'Length > 8
1658 and then
1659 (Arg (Arg'First + 6 .. Arg'First + 8) = "rtp"
1660 or else Arg (Arg'Last - 2 .. Arg'Last) = "rtp")
1661 then
1662 Linker_Options.Increment_Last;
1663 Linker_Options.Table (Linker_Options.Last) :=
1664 new String'("-mrtp");
1665 end if;
1666 end if;
1667 end;
1668 end loop;
1669 end if;
1670 end;
1671 end if;
1673 -- Get target parameters
1675 Osint.Add_Default_Search_Dirs;
1676 Targparm.Get_Target_Parameters;
1678 if VM_Target /= No_VM then
1679 case VM_Target is
1680 when JVM_Target => Gcc := new String'("jvm-gnatcompile");
1681 when CLI_Target => Gcc := new String'("dotnet-gnatcompile");
1682 when No_VM => raise Program_Error;
1683 end case;
1684 end if;
1686 -- Compile the bind file with the following switches:
1688 -- -gnatA stops reading gnat.adc, since we don't know what
1689 -- pragmas would work, and we do not need it anyway.
1691 -- -gnatWb allows brackets coding for wide characters
1693 -- -gnatiw allows wide characters in identifiers. This is needed
1694 -- because bindgen uses brackets encoding for all upper
1695 -- half and wide characters in identifier names.
1697 -- In addition, in CodePeer mode compile with -x adascil -gnatcC
1699 Binder_Options_From_ALI.Increment_Last;
1700 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1701 new String'("-gnatA");
1702 Binder_Options_From_ALI.Increment_Last;
1703 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1704 new String'("-gnatWb");
1705 Binder_Options_From_ALI.Increment_Last;
1706 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1707 new String'("-gnatiw");
1709 if Opt.CodePeer_Mode then
1710 Binder_Options_From_ALI.Increment_Last;
1711 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1712 new String'("-x");
1713 Binder_Options_From_ALI.Increment_Last;
1714 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1715 new String'("adascil");
1716 Binder_Options_From_ALI.Increment_Last;
1717 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
1718 new String'("-gnatcC");
1719 end if;
1721 -- Locate all the necessary programs and verify required files are present
1723 Gcc_Path := System.OS_Lib.Locate_Exec_On_Path (Gcc.all);
1725 if Gcc_Path = null then
1726 Exit_With_Error ("Couldn't locate " & Gcc.all);
1727 end if;
1729 if Linker_Path = null then
1730 if VM_Target = CLI_Target then
1731 Linker_Path := System.OS_Lib.Locate_Exec_On_Path ("dotnet-ld");
1733 if Linker_Path = null then
1734 Exit_With_Error ("Couldn't locate dotnet-ld");
1735 end if;
1737 elsif RTX_RTSS_Kernel_Module_On_Target then
1739 -- Use Microsoft linker for RTSS modules
1741 Linker_Path := System.OS_Lib.Locate_Exec_On_Path ("link");
1743 if Linker_Path = null then
1744 Exit_With_Error ("Couldn't locate link");
1745 end if;
1747 else
1748 Linker_Path := Gcc_Path;
1749 end if;
1750 end if;
1752 Write_Header;
1754 -- If no output name specified, then use the base name of .ali file name
1756 if Output_File_Name = null then
1757 Output_File_Name :=
1758 new String'(Base_Name (Ali_File_Name.all)
1759 & Get_Target_Debuggable_Suffix.all);
1760 end if;
1762 if RTX_RTSS_Kernel_Module_On_Target then
1763 Linker_Options.Increment_Last;
1764 Linker_Options.Table (Linker_Options.Last) :=
1765 new String'("/OUT:" & Output_File_Name.all);
1767 else
1768 Linker_Options.Increment_Last;
1769 Linker_Options.Table (Linker_Options.Last) := new String'("-o");
1771 Linker_Options.Increment_Last;
1772 Linker_Options.Table (Linker_Options.Last) :=
1773 new String'(Output_File_Name.all);
1774 end if;
1776 Check_Existing_Executable (Output_File_Name.all);
1778 -- Warn if main program is called "test", as that may be a built-in command
1779 -- on Unix. On non-Unix systems executables have a suffix, so the warning
1780 -- will not appear. However, do not warn in the case of a cross compiler.
1782 -- Assume this is a cross tool if the executable name is not gnatlink
1784 if Base_Command_Name.all = "gnatlink"
1785 and then Output_File_Name.all = "test"
1786 then
1787 Error_Msg ("warning: executable name """ & Output_File_Name.all
1788 & """ may conflict with shell command");
1789 end if;
1791 -- If -M switch was specified, add the switches to create the map file
1793 if Create_Map_File then
1794 declare
1795 Map_Name : constant String := Base_Name (Ali_File_Name.all) & ".map";
1796 Switches : String_List_Access;
1798 begin
1799 Convert (Map_File, Map_Name, Switches);
1801 if Switches /= null then
1802 for J in Switches'Range loop
1803 Linker_Options.Increment_Last;
1804 Linker_Options.Table (Linker_Options.Last) := Switches (J);
1805 end loop;
1806 end if;
1807 end;
1808 end if;
1810 -- Perform consistency checks
1812 -- Transform the .ali file name into the binder output file name
1814 Make_Binder_File_Names : declare
1815 Fname : constant String := Base_Name (Ali_File_Name.all);
1816 Fname_Len : Integer := Fname'Length;
1818 function Get_Maximum_File_Name_Length return Integer;
1819 pragma Import (C, Get_Maximum_File_Name_Length,
1820 "__gnat_get_maximum_file_name_length");
1822 Maximum_File_Name_Length : constant Integer :=
1823 Get_Maximum_File_Name_Length;
1825 Bind_File_Prefix : Types.String_Ptr;
1826 -- Contains prefix used for bind files
1828 begin
1829 -- Set prefix
1831 if OpenVMS_On_Target then
1832 Bind_File_Prefix := new String'("b__");
1833 else
1834 Bind_File_Prefix := new String'("b~");
1835 end if;
1837 -- If the length of the binder file becomes too long due to
1838 -- the addition of the "b?" prefix, then truncate it.
1840 if Maximum_File_Name_Length > 0 then
1841 while Fname_Len >
1842 Maximum_File_Name_Length - Bind_File_Prefix.all'Length
1843 loop
1844 Fname_Len := Fname_Len - 1;
1845 end loop;
1846 end if;
1848 declare
1849 Fnam : constant String :=
1850 Bind_File_Prefix.all &
1851 Fname (Fname'First .. Fname'First + Fname_Len - 1);
1853 begin
1854 Binder_Spec_Src_File := new String'(Fnam & ".ads");
1855 Binder_Body_Src_File := new String'(Fnam & ".adb");
1856 Binder_Ali_File := new String'(Fnam & ".ali");
1858 Binder_Obj_File := new String'(Fnam & Get_Target_Object_Suffix.all);
1859 end;
1861 if Fname_Len /= Fname'Length then
1862 Binder_Options.Increment_Last;
1863 Binder_Options.Table (Binder_Options.Last) := new String'("-o");
1864 Binder_Options.Increment_Last;
1865 Binder_Options.Table (Binder_Options.Last) := Binder_Obj_File;
1866 end if;
1867 end Make_Binder_File_Names;
1869 Process_Binder_File (Binder_Body_Src_File.all & ASCII.NUL);
1871 -- Compile the binder file. This is fast, so we always do it, unless
1872 -- specifically told not to by the -n switch
1874 if Compile_Bind_File then
1875 Bind_Step : declare
1876 Success : Boolean;
1878 Args : Argument_List
1879 (1 .. Binder_Options_From_ALI.Last + Binder_Options.Last + 1);
1881 begin
1882 for J in 1 .. Binder_Options_From_ALI.Last loop
1883 Args (J) := Binder_Options_From_ALI.Table (J);
1884 end loop;
1886 for J in 1 .. Binder_Options.Last loop
1887 Args (Binder_Options_From_ALI.Last + J) :=
1888 Binder_Options.Table (J);
1889 end loop;
1891 -- Use the full path of the binder generated source, so that it is
1892 -- guaranteed that the debugger will find this source, even with
1893 -- STABS.
1895 Args (Args'Last) :=
1896 new String'(Normalize_Pathname (Binder_Body_Src_File.all));
1898 if Verbose_Mode then
1899 Write_Str (Base_Name (Gcc_Path.all));
1901 for J in Args'Range loop
1902 Write_Str (" ");
1903 Write_Str (Args (J).all);
1904 end loop;
1906 Write_Eol;
1907 end if;
1909 System.OS_Lib.Spawn (Gcc_Path.all, Args, Success);
1911 if not Success then
1912 Exit_Program (E_Fatal);
1913 end if;
1914 end Bind_Step;
1915 end if;
1917 -- In CodePeer mode, there's nothing left to do after the binder file has
1918 -- been compiled.
1920 if Opt.CodePeer_Mode then
1921 return;
1922 end if;
1924 -- Now, actually link the program
1926 -- Skip this step for now on JVM since the Java interpreter will do
1927 -- the actual link at run time. We might consider packing all class files
1928 -- in a .zip file during this step.
1930 if VM_Target /= JVM_Target then
1931 Link_Step : declare
1932 Num_Args : Natural :=
1933 (Linker_Options.Last - Linker_Options.First + 1) +
1934 (Gcc_Linker_Options.Last - Gcc_Linker_Options.First + 1) +
1935 (Linker_Objects.Last - Linker_Objects.First + 1);
1936 Stack_Op : Boolean := False;
1937 IDENT_Op : Boolean := False;
1939 begin
1940 if AAMP_On_Target then
1942 -- Remove extraneous flags not relevant for AAMP
1944 for J in reverse Linker_Options.First .. Linker_Options.Last loop
1945 if Linker_Options.Table (J)'Length = 0
1946 or else Linker_Options.Table (J) (1 .. 3) = "-Wl"
1947 or else Linker_Options.Table (J) (1 .. 3) = "-sh"
1948 or else Linker_Options.Table (J) (1 .. 2) = "-O"
1949 or else Linker_Options.Table (J) (1 .. 2) = "-g"
1950 then
1951 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
1952 Linker_Options.Table (J + 1 .. Linker_Options.Last);
1953 Linker_Options.Decrement_Last;
1954 Num_Args := Num_Args - 1;
1955 end if;
1956 end loop;
1958 elsif RTX_RTSS_Kernel_Module_On_Target then
1960 -- Remove irrelevant flags for Microsoft linker, adapt some others
1962 for J in reverse Linker_Options.First .. Linker_Options.Last loop
1964 -- Remove flags that are not accepted
1966 if Linker_Options.Table (J)'Length = 0
1967 or else Linker_Options.Table (J) (1 .. 2) = "-l"
1968 or else Linker_Options.Table (J) (1 .. 3) = "-Wl"
1969 or else Linker_Options.Table (J) (1 .. 3) = "-sh"
1970 or else Linker_Options.Table (J) (1 .. 2) = "-O"
1971 or else Linker_Options.Table (J) (1 .. 8) = "-Xlinker"
1972 or else Linker_Options.Table (J) (1 .. 9) = "-mthreads"
1973 then
1974 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
1975 Linker_Options.Table (J + 1 .. Linker_Options.Last);
1976 Linker_Options.Decrement_Last;
1977 Num_Args := Num_Args - 1;
1979 -- Replace "-L" by its counterpart "/LIBPATH:" and UNIX "/" by
1980 -- Windows "\".
1982 elsif Linker_Options.Table (J) (1 .. 2) = "-L" then
1983 declare
1984 Libpath_Option : constant String_Access := new String'
1985 ("/LIBPATH:" &
1986 Linker_Options.Table
1987 (J) (3 .. Linker_Options.Table (J).all'Last));
1988 begin
1989 for Index in 10 .. Libpath_Option'Last loop
1990 if Libpath_Option (Index) = '/' then
1991 Libpath_Option (Index) := '\';
1992 end if;
1993 end loop;
1995 Linker_Options.Table (J) := Libpath_Option;
1996 end;
1998 -- Replace "-g" by "/DEBUG"
2000 elsif Linker_Options.Table (J) (1 .. 2) = "-g" then
2001 Linker_Options.Table (J) := new String'("/DEBUG");
2003 -- Replace "-o" by "/OUT:"
2005 elsif Linker_Options.Table (J) (1 .. 2) = "-o" then
2006 Linker_Options.Table (J + 1) := new String'
2007 ("/OUT:" & Linker_Options.Table (J + 1).all);
2009 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2010 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2011 Linker_Options.Decrement_Last;
2012 Num_Args := Num_Args - 1;
2014 -- Replace "--stack=" by "/STACK:"
2016 elsif Linker_Options.Table (J) (1 .. 8) = "--stack=" then
2017 Linker_Options.Table (J) := new String'
2018 ("/STACK:" &
2019 Linker_Options.Table (J)
2020 (9 .. Linker_Options.Table (J).all'Last));
2022 -- Replace "-v" by its counterpart "/VERBOSE"
2024 elsif Linker_Options.Table (J) (1 .. 2) = "-v" then
2025 Linker_Options.Table (J) := new String'("/VERBOSE");
2026 end if;
2027 end loop;
2029 -- Add some required flags to create RTSS modules
2031 declare
2032 Flags_For_Linker : constant array (1 .. 17) of String_Access :=
2033 (new String'("/NODEFAULTLIB"),
2034 new String'("/INCREMENTAL:NO"),
2035 new String'("/NOLOGO"),
2036 new String'("/DRIVER"),
2037 new String'("/ALIGN:0x20"),
2038 new String'("/SUBSYSTEM:NATIVE"),
2039 new String'("/ENTRY:_RtapiProcessEntryCRT@8"),
2040 new String'("/RELEASE"),
2041 new String'("startupCRT.obj"),
2042 new String'("rtxlibcmt.lib"),
2043 new String'("oldnames.lib"),
2044 new String'("rtapi_rtss.lib"),
2045 new String'("Rtx_Rtss.lib"),
2046 new String'("libkernel32.a"),
2047 new String'("libws2_32.a"),
2048 new String'("libmswsock.a"),
2049 new String'("libadvapi32.a"));
2050 -- These flags need to be passed to Microsoft linker. They
2051 -- come from the RTX documentation.
2053 Gcc_Lib_Path : constant String_Access := new String'
2054 ("/LIBPATH:" & Include_Dir_Default_Prefix & "\..\");
2055 -- Place to look for gcc related libraries, such as libgcc
2057 begin
2058 -- Replace UNIX "/" by Windows "\" in the path
2060 for Index in 10 .. Gcc_Lib_Path.all'Last loop
2061 if Gcc_Lib_Path (Index) = '/' then
2062 Gcc_Lib_Path (Index) := '\';
2063 end if;
2064 end loop;
2066 Linker_Options.Increment_Last;
2067 Linker_Options.Table (Linker_Options.Last) := Gcc_Lib_Path;
2068 Num_Args := Num_Args + 1;
2070 for Index in Flags_For_Linker'Range loop
2071 Linker_Options.Increment_Last;
2072 Linker_Options.Table (Linker_Options.Last) :=
2073 Flags_For_Linker (Index);
2074 Num_Args := Num_Args + 1;
2075 end loop;
2076 end;
2077 end if;
2079 -- Remove duplicate stack size setting from the Linker_Options table.
2080 -- The stack setting option "-Xlinker --stack=R,C" can be found
2081 -- in one line when set by a pragma Linker_Options or in two lines
2082 -- ("-Xlinker" then "--stack=R,C") when set on the command line. We
2083 -- also check for the "-Wl,--stack=R" style option.
2085 -- We must remove the second stack setting option instance because
2086 -- the one on the command line will always be the first one. And any
2087 -- subsequent stack setting option will overwrite the previous one.
2088 -- This is done especially for GNAT/NT where we set the stack size
2089 -- for tasking programs by a pragma in the NT specific tasking
2090 -- package System.Task_Primitives.Operations.
2092 -- Note: This is not a FOR loop that runs from Linker_Options.First
2093 -- to Linker_Options.Last, since operations within the loop can
2094 -- modify the length of the table.
2096 Clean_Link_Option_Set : declare
2097 J : Natural;
2098 Shared_Libgcc_Seen : Boolean := False;
2100 begin
2101 J := Linker_Options.First;
2102 while J <= Linker_Options.Last loop
2103 if Linker_Options.Table (J).all = "-Xlinker"
2104 and then J < Linker_Options.Last
2105 and then Linker_Options.Table (J + 1)'Length > 8
2106 and then Linker_Options.Table (J + 1) (1 .. 8) = "--stack="
2107 then
2108 if Stack_Op then
2109 Linker_Options.Table (J .. Linker_Options.Last - 2) :=
2110 Linker_Options.Table (J + 2 .. Linker_Options.Last);
2111 Linker_Options.Decrement_Last;
2112 Linker_Options.Decrement_Last;
2113 Num_Args := Num_Args - 2;
2115 else
2116 Stack_Op := True;
2117 end if;
2118 end if;
2120 -- Remove duplicate -shared-libgcc switch
2122 if Linker_Options.Table (J).all = Shared_Libgcc_String then
2123 if Shared_Libgcc_Seen then
2124 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2125 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2126 Linker_Options.Decrement_Last;
2127 Num_Args := Num_Args - 1;
2129 else
2130 Shared_Libgcc_Seen := True;
2131 end if;
2132 end if;
2134 -- Here we just check for a canonical form that matches the
2135 -- pragma Linker_Options set in the NT runtime.
2137 if (Linker_Options.Table (J)'Length > 17
2138 and then Linker_Options.Table (J) (1 .. 17) =
2139 "-Xlinker --stack=")
2140 or else
2141 (Linker_Options.Table (J)'Length > 12
2142 and then Linker_Options.Table (J) (1 .. 12) =
2143 "-Wl,--stack=")
2144 then
2145 if Stack_Op then
2146 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2147 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2148 Linker_Options.Decrement_Last;
2149 Num_Args := Num_Args - 1;
2151 else
2152 Stack_Op := True;
2153 end if;
2154 end if;
2156 -- Remove duplicate IDENTIFICATION directives (VMS)
2158 if Linker_Options.Table (J)'Length > 29
2159 and then Linker_Options.Table (J) (1 .. 30) =
2160 "--for-linker=--identification="
2161 then
2162 if IDENT_Op then
2163 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
2164 Linker_Options.Table (J + 1 .. Linker_Options.Last);
2165 Linker_Options.Decrement_Last;
2166 Num_Args := Num_Args - 1;
2168 else
2169 IDENT_Op := True;
2170 end if;
2171 end if;
2173 J := J + 1;
2174 end loop;
2176 if Linker_Path = Gcc_Path and then VM_Target = No_VM then
2178 -- For systems where the default is to link statically with
2179 -- libgcc, if gcc is not called with -shared-libgcc, call it
2180 -- with -static-libgcc, as there are some platforms where one
2181 -- of these two switches is compulsory to link.
2183 if Shared_Libgcc_Default = 'T'
2184 and then not Shared_Libgcc_Seen
2185 then
2186 Linker_Options.Increment_Last;
2187 Linker_Options.Table (Linker_Options.Last) := Static_Libgcc;
2188 Num_Args := Num_Args + 1;
2189 end if;
2191 elsif RTX_RTSS_Kernel_Module_On_Target then
2193 -- Force the use of the static libgcc for RTSS modules
2195 Linker_Options.Increment_Last;
2196 Linker_Options.Table (Linker_Options.Last) :=
2197 new String'("libgcc.a");
2198 Num_Args := Num_Args + 1;
2199 end if;
2201 end Clean_Link_Option_Set;
2203 -- Prepare arguments for call to linker
2205 Call_Linker : declare
2206 Success : Boolean;
2207 Args : Argument_List (1 .. Num_Args + 1);
2208 Index : Integer := Args'First;
2210 begin
2211 Args (Index) := Binder_Obj_File;
2213 -- Add the object files and any -largs libraries
2215 for J in Linker_Objects.First .. Linker_Objects.Last loop
2216 Index := Index + 1;
2217 Args (Index) := Linker_Objects.Table (J);
2218 end loop;
2220 -- Add the linker options from the binder file
2222 for J in Linker_Options.First .. Linker_Options.Last loop
2223 Index := Index + 1;
2224 Args (Index) := Linker_Options.Table (J);
2225 end loop;
2227 -- Finally add the libraries from the --GCC= switch
2229 for J in Gcc_Linker_Options.First .. Gcc_Linker_Options.Last loop
2230 Index := Index + 1;
2231 Args (Index) := Gcc_Linker_Options.Table (J);
2232 end loop;
2234 if Verbose_Mode then
2235 Write_Str (Linker_Path.all);
2237 for J in Args'Range loop
2238 Write_Str (" ");
2239 Write_Str (Args (J).all);
2240 end loop;
2242 Write_Eol;
2244 -- If we are on very verbose mode (-v -v) and a response file
2245 -- is used we display its content.
2247 if Very_Verbose_Mode and then Tname_FD /= Invalid_FD then
2248 Write_Eol;
2249 Write_Str ("Response file (" &
2250 Tname (Tname'First .. Tname'Last - 1) &
2251 ") content : ");
2252 Write_Eol;
2254 for J in
2255 Response_File_Objects.First .. Response_File_Objects.Last
2256 loop
2257 Write_Str (Response_File_Objects.Table (J).all);
2258 Write_Eol;
2259 end loop;
2261 Write_Eol;
2262 end if;
2263 end if;
2265 System.OS_Lib.Spawn (Linker_Path.all, Args, Success);
2267 if Success then
2269 -- Delete the temporary file used in conjunction with linking
2270 -- if one was created. See Process_Bind_File for details.
2272 if Tname_FD /= Invalid_FD then
2273 Delete (Tname);
2274 end if;
2276 else
2277 Error_Msg ("error when calling " & Linker_Path.all);
2278 Exit_Program (E_Fatal);
2279 end if;
2280 end Call_Linker;
2281 end Link_Step;
2282 end if;
2284 -- Only keep the binder output file and it's associated object
2285 -- file if compiling with the -g option. These files are only
2286 -- useful if debugging.
2288 if not Debug_Flag_Present then
2289 Delete (Binder_Ali_File.all & ASCII.NUL);
2290 Delete (Binder_Spec_Src_File.all & ASCII.NUL);
2291 Delete (Binder_Body_Src_File.all & ASCII.NUL);
2293 if VM_Target = No_VM then
2294 Delete (Binder_Obj_File.all & ASCII.NUL);
2295 end if;
2296 end if;
2298 Exit_Program (E_Success);
2300 exception
2301 when X : others =>
2302 Write_Line (Exception_Information (X));
2303 Exit_With_Error ("INTERNAL ERROR. Please report");
2304 end Gnatlink;