annotate gcc/ada/gnatlink.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- G N A T L I N K --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1996-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- Gnatlink usage: please consult the gnat documentation
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 with ALI; use ALI;
kono
parents:
diff changeset
29 with Csets;
kono
parents:
diff changeset
30 with Gnatvsn; use Gnatvsn;
kono
parents:
diff changeset
31 with Indepsw; use Indepsw;
kono
parents:
diff changeset
32 with Namet; use Namet;
kono
parents:
diff changeset
33 with Opt;
kono
parents:
diff changeset
34 with Osint; use Osint;
kono
parents:
diff changeset
35 with Output; use Output;
kono
parents:
diff changeset
36 with Snames;
kono
parents:
diff changeset
37 with Switch; use Switch;
kono
parents:
diff changeset
38 with System; use System;
kono
parents:
diff changeset
39 with Table;
kono
parents:
diff changeset
40 with Targparm;
kono
parents:
diff changeset
41 with Types;
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 with Ada.Command_Line; use Ada.Command_Line;
kono
parents:
diff changeset
44 with Ada.Exceptions; use Ada.Exceptions;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 with System.OS_Lib; use System.OS_Lib;
kono
parents:
diff changeset
47 with System.CRTL;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 with Interfaces.C_Streams; use Interfaces.C_Streams;
kono
parents:
diff changeset
50 with Interfaces.C.Strings; use Interfaces.C.Strings;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 procedure Gnatlink is
kono
parents:
diff changeset
53 pragma Ident (Gnatvsn.Gnat_Static_Version_String);
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 Shared_Libgcc_String : constant String := "-shared-libgcc";
kono
parents:
diff changeset
56 Shared_Libgcc : constant String_Access :=
kono
parents:
diff changeset
57 new String'(Shared_Libgcc_String);
kono
parents:
diff changeset
58 -- Used to invoke gcc when the binder is invoked with -shared
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 Static_Libgcc_String : constant String := "-static-libgcc";
kono
parents:
diff changeset
61 Static_Libgcc : constant String_Access :=
kono
parents:
diff changeset
62 new String'(Static_Libgcc_String);
kono
parents:
diff changeset
63 -- Used to invoke gcc when shared libs are not used
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 package Gcc_Linker_Options is new Table.Table (
kono
parents:
diff changeset
66 Table_Component_Type => String_Access,
kono
parents:
diff changeset
67 Table_Index_Type => Integer,
kono
parents:
diff changeset
68 Table_Low_Bound => 1,
kono
parents:
diff changeset
69 Table_Initial => 20,
kono
parents:
diff changeset
70 Table_Increment => 100,
kono
parents:
diff changeset
71 Table_Name => "Gnatlink.Gcc_Linker_Options");
kono
parents:
diff changeset
72 -- Comments needed ???
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 package Libpath is new Table.Table (
kono
parents:
diff changeset
75 Table_Component_Type => Character,
kono
parents:
diff changeset
76 Table_Index_Type => Integer,
kono
parents:
diff changeset
77 Table_Low_Bound => 1,
kono
parents:
diff changeset
78 Table_Initial => 4096,
kono
parents:
diff changeset
79 Table_Increment => 100,
kono
parents:
diff changeset
80 Table_Name => "Gnatlink.Libpath");
kono
parents:
diff changeset
81 -- Comments needed ???
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 package Linker_Options is new Table.Table (
kono
parents:
diff changeset
84 Table_Component_Type => String_Access,
kono
parents:
diff changeset
85 Table_Index_Type => Integer,
kono
parents:
diff changeset
86 Table_Low_Bound => 1,
kono
parents:
diff changeset
87 Table_Initial => 20,
kono
parents:
diff changeset
88 Table_Increment => 100,
kono
parents:
diff changeset
89 Table_Name => "Gnatlink.Linker_Options");
kono
parents:
diff changeset
90 -- Comments needed ???
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 package Linker_Objects is new Table.Table (
kono
parents:
diff changeset
93 Table_Component_Type => String_Access,
kono
parents:
diff changeset
94 Table_Index_Type => Integer,
kono
parents:
diff changeset
95 Table_Low_Bound => 1,
kono
parents:
diff changeset
96 Table_Initial => 20,
kono
parents:
diff changeset
97 Table_Increment => 100,
kono
parents:
diff changeset
98 Table_Name => "Gnatlink.Linker_Objects");
kono
parents:
diff changeset
99 -- This table collects the objects file to be passed to the linker. In the
kono
parents:
diff changeset
100 -- case where the linker command line is too long then programs objects
kono
parents:
diff changeset
101 -- are put on the Response_File_Objects table. Note that the binder object
kono
parents:
diff changeset
102 -- file and the user's objects remain in this table. This is very
kono
parents:
diff changeset
103 -- important because on the GNU linker command line the -L switch is not
kono
parents:
diff changeset
104 -- used to look for objects files but -L switch is used to look for
kono
parents:
diff changeset
105 -- objects listed in the response file. This is not a problem with the
kono
parents:
diff changeset
106 -- applications objects as they are specified with a full name.
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 package Response_File_Objects is new Table.Table (
kono
parents:
diff changeset
109 Table_Component_Type => String_Access,
kono
parents:
diff changeset
110 Table_Index_Type => Integer,
kono
parents:
diff changeset
111 Table_Low_Bound => 1,
kono
parents:
diff changeset
112 Table_Initial => 20,
kono
parents:
diff changeset
113 Table_Increment => 100,
kono
parents:
diff changeset
114 Table_Name => "Gnatlink.Response_File_Objects");
kono
parents:
diff changeset
115 -- This table collects the objects file that are to be put in the response
kono
parents:
diff changeset
116 -- file. Only application objects are collected there (see details in
kono
parents:
diff changeset
117 -- Linker_Objects table comments)
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 package Binder_Options_From_ALI is new Table.Table (
kono
parents:
diff changeset
120 Table_Component_Type => String_Access,
kono
parents:
diff changeset
121 Table_Index_Type => Integer,
kono
parents:
diff changeset
122 Table_Low_Bound => 1, -- equals low bound of Argument_List for Spawn
kono
parents:
diff changeset
123 Table_Initial => 20,
kono
parents:
diff changeset
124 Table_Increment => 100,
kono
parents:
diff changeset
125 Table_Name => "Gnatlink.Binder_Options_From_ALI");
kono
parents:
diff changeset
126 -- This table collects the switches from the ALI file of the main
kono
parents:
diff changeset
127 -- subprogram.
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 package Binder_Options is new Table.Table (
kono
parents:
diff changeset
130 Table_Component_Type => String_Access,
kono
parents:
diff changeset
131 Table_Index_Type => Integer,
kono
parents:
diff changeset
132 Table_Low_Bound => 1, -- equals low bound of Argument_List for Spawn
kono
parents:
diff changeset
133 Table_Initial => 20,
kono
parents:
diff changeset
134 Table_Increment => 100,
kono
parents:
diff changeset
135 Table_Name => "Gnatlink.Binder_Options");
kono
parents:
diff changeset
136 -- This table collects the arguments to be passed to compile the binder
kono
parents:
diff changeset
137 -- generated file.
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 Gcc : String_Access := Program_Name ("gcc", "gnatlink");
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 Read_Mode : constant String := "r" & ASCII.NUL;
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 Begin_Info : constant String := "-- BEGIN Object file/option list";
kono
parents:
diff changeset
144 End_Info : constant String := "-- END Object file/option list ";
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 Gcc_Path : String_Access;
kono
parents:
diff changeset
147 Linker_Path : String_Access;
kono
parents:
diff changeset
148 Output_File_Name : String_Access;
kono
parents:
diff changeset
149 Ali_File_Name : String_Access;
kono
parents:
diff changeset
150 Binder_Spec_Src_File : String_Access;
kono
parents:
diff changeset
151 Binder_Body_Src_File : String_Access;
kono
parents:
diff changeset
152 Binder_Ali_File : String_Access;
kono
parents:
diff changeset
153 Binder_Obj_File : String_Access;
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 Base_Command_Name : String_Access;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 Target_Debuggable_Suffix : String_Access;
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 Tname : Temp_File_Name;
kono
parents:
diff changeset
160 Tname_FD : File_Descriptor := Invalid_FD;
kono
parents:
diff changeset
161 -- Temporary file used by linker to pass list of object files on
kono
parents:
diff changeset
162 -- certain systems with limitations on size of arguments.
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 Debug_Flag_Present : Boolean := False;
kono
parents:
diff changeset
165 Verbose_Mode : Boolean := False;
kono
parents:
diff changeset
166 Very_Verbose_Mode : Boolean := False;
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 Standard_Gcc : Boolean := True;
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 Compile_Bind_File : Boolean := True;
kono
parents:
diff changeset
171 -- Set to False if bind file is not to be compiled
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 Create_Map_File : Boolean := False;
kono
parents:
diff changeset
174 -- Set to True by switch -M. The map file name is derived from
kono
parents:
diff changeset
175 -- the ALI file name (mainprog.ali => mainprog.map).
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 Object_List_File_Supported : Boolean;
kono
parents:
diff changeset
178 for Object_List_File_Supported'Size use Character'Size;
kono
parents:
diff changeset
179 pragma Import
kono
parents:
diff changeset
180 (C, Object_List_File_Supported, "__gnat_objlist_file_supported");
kono
parents:
diff changeset
181 -- Predicate indicating whether the linker has an option whereby the
kono
parents:
diff changeset
182 -- names of object files can be passed to the linker in a file.
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 Object_File_Option_Ptr : Interfaces.C.Strings.chars_ptr;
kono
parents:
diff changeset
185 pragma Import (C, Object_File_Option_Ptr, "__gnat_object_file_option");
kono
parents:
diff changeset
186 -- Pointer to a string representing the linker option which specifies
kono
parents:
diff changeset
187 -- the response file.
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 Object_File_Option : constant String := Value (Object_File_Option_Ptr);
kono
parents:
diff changeset
190 -- The linker option which specifies the response file as a string
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 Using_GNU_response_file : constant Boolean :=
kono
parents:
diff changeset
193 Object_File_Option'Length > 0
kono
parents:
diff changeset
194 and then Object_File_Option (Object_File_Option'Last) = '@';
kono
parents:
diff changeset
195 -- Whether a GNU response file is used
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 Object_List_File_Required : Boolean := False;
kono
parents:
diff changeset
198 -- Set to True to force generation of a response file
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 Shared_Libgcc_Default : Character;
kono
parents:
diff changeset
201 for Shared_Libgcc_Default'Size use Character'Size;
kono
parents:
diff changeset
202 pragma Import
kono
parents:
diff changeset
203 (C, Shared_Libgcc_Default, "__gnat_shared_libgcc_default");
kono
parents:
diff changeset
204 -- Indicates wether libgcc should be statically linked (use 'T') or
kono
parents:
diff changeset
205 -- dynamically linked (use 'H') by default.
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 function Base_Name (File_Name : String) return String;
kono
parents:
diff changeset
208 -- Return just the file name part without the extension (if present)
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 procedure Check_Existing_Executable (File_Name : String);
kono
parents:
diff changeset
211 -- Delete any existing executable to avoid accidentally updating the target
kono
parents:
diff changeset
212 -- of a symbolic link, but produce a Fatail_Error if File_Name matches any
kono
parents:
diff changeset
213 -- of the source file names. This avoids overwriting of extensionless
kono
parents:
diff changeset
214 -- source files by accident on systems where executables do not have
kono
parents:
diff changeset
215 -- extensions.
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 procedure Delete (Name : String);
kono
parents:
diff changeset
218 -- Wrapper to unlink as status is ignored by this application
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 procedure Error_Msg (Message : String);
kono
parents:
diff changeset
221 -- Output the error or warning Message
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 procedure Exit_With_Error (Error : String);
kono
parents:
diff changeset
224 -- Output Error and exit program with a fatal condition
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 procedure Process_Args;
kono
parents:
diff changeset
227 -- Go through all the arguments and build option tables
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 procedure Process_Binder_File (Name : String);
kono
parents:
diff changeset
230 -- Reads the binder file and extracts linker arguments
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 procedure Usage;
kono
parents:
diff changeset
233 -- Display usage
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 procedure Write_Header;
kono
parents:
diff changeset
236 -- Show user the program name, version and copyright
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 procedure Write_Usage;
kono
parents:
diff changeset
239 -- Show user the program options
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 ---------------
kono
parents:
diff changeset
242 -- Base_Name --
kono
parents:
diff changeset
243 ---------------
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 function Base_Name (File_Name : String) return String is
kono
parents:
diff changeset
246 Findex1 : Natural;
kono
parents:
diff changeset
247 Findex2 : Natural;
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 begin
kono
parents:
diff changeset
250 Findex1 := File_Name'First;
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 -- The file might be specified by a full path name. However,
kono
parents:
diff changeset
253 -- we want the path to be stripped away.
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 for J in reverse File_Name'Range loop
kono
parents:
diff changeset
256 if Is_Directory_Separator (File_Name (J)) then
kono
parents:
diff changeset
257 Findex1 := J + 1;
kono
parents:
diff changeset
258 exit;
kono
parents:
diff changeset
259 end if;
kono
parents:
diff changeset
260 end loop;
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 Findex2 := File_Name'Last;
kono
parents:
diff changeset
263 while Findex2 > Findex1 and then File_Name (Findex2) /= '.' loop
kono
parents:
diff changeset
264 Findex2 := Findex2 - 1;
kono
parents:
diff changeset
265 end loop;
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 if Findex2 = Findex1 then
kono
parents:
diff changeset
268 Findex2 := File_Name'Last + 1;
kono
parents:
diff changeset
269 end if;
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 return File_Name (Findex1 .. Findex2 - 1);
kono
parents:
diff changeset
272 end Base_Name;
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 -------------------------------
kono
parents:
diff changeset
275 -- Check_Existing_Executable --
kono
parents:
diff changeset
276 -------------------------------
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 procedure Check_Existing_Executable (File_Name : String) is
kono
parents:
diff changeset
279 Ename : String := File_Name;
kono
parents:
diff changeset
280 Efile : File_Name_Type;
kono
parents:
diff changeset
281 Sfile : File_Name_Type;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 begin
kono
parents:
diff changeset
284 Canonical_Case_File_Name (Ename);
kono
parents:
diff changeset
285 Name_Len := 0;
kono
parents:
diff changeset
286 Add_Str_To_Name_Buffer (Ename);
kono
parents:
diff changeset
287 Efile := Name_Find;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 for J in Units.Table'First .. Units.Last loop
kono
parents:
diff changeset
290 Sfile := Units.Table (J).Sfile;
kono
parents:
diff changeset
291 if Sfile = Efile then
kono
parents:
diff changeset
292 Exit_With_Error
kono
parents:
diff changeset
293 ("executable name """ & File_Name & """ matches "
kono
parents:
diff changeset
294 & "source file name """ & Get_Name_String (Sfile) & """");
kono
parents:
diff changeset
295 end if;
kono
parents:
diff changeset
296 end loop;
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 Delete (File_Name);
kono
parents:
diff changeset
299 end Check_Existing_Executable;
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 ------------
kono
parents:
diff changeset
302 -- Delete --
kono
parents:
diff changeset
303 ------------
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 procedure Delete (Name : String) is
kono
parents:
diff changeset
306 Status : int;
kono
parents:
diff changeset
307 pragma Unreferenced (Status);
kono
parents:
diff changeset
308 begin
kono
parents:
diff changeset
309 Status := unlink (Name'Address);
kono
parents:
diff changeset
310 -- Is it really right to ignore an error here ???
kono
parents:
diff changeset
311 end Delete;
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 ---------------
kono
parents:
diff changeset
314 -- Error_Msg --
kono
parents:
diff changeset
315 ---------------
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 procedure Error_Msg (Message : String) is
kono
parents:
diff changeset
318 begin
kono
parents:
diff changeset
319 Write_Str (Base_Command_Name.all);
kono
parents:
diff changeset
320 Write_Str (": ");
kono
parents:
diff changeset
321 Write_Str (Message);
kono
parents:
diff changeset
322 Write_Eol;
kono
parents:
diff changeset
323 end Error_Msg;
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 ---------------------
kono
parents:
diff changeset
326 -- Exit_With_Error --
kono
parents:
diff changeset
327 ---------------------
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 procedure Exit_With_Error (Error : String) is
kono
parents:
diff changeset
330 begin
kono
parents:
diff changeset
331 Error_Msg (Error);
kono
parents:
diff changeset
332 Exit_Program (E_Fatal);
kono
parents:
diff changeset
333 end Exit_With_Error;
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 ------------------
kono
parents:
diff changeset
336 -- Process_Args --
kono
parents:
diff changeset
337 ------------------
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 procedure Process_Args is
kono
parents:
diff changeset
340 Next_Arg : Integer;
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 Skip_Next : Boolean := False;
kono
parents:
diff changeset
343 -- Set to true if the next argument is to be added into the list of
kono
parents:
diff changeset
344 -- linker's argument without parsing it.
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 -- Start of processing for Process_Args
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 begin
kono
parents:
diff changeset
351 -- First, check for --version and --help
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 Check_Version_And_Help ("GNATLINK", "1996");
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 -- Loop through arguments of gnatlink command
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 Next_Arg := 1;
kono
parents:
diff changeset
358 loop
kono
parents:
diff changeset
359 exit when Next_Arg > Argument_Count;
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 Process_One_Arg : declare
kono
parents:
diff changeset
362 Arg : constant String := Argument (Next_Arg);
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 begin
kono
parents:
diff changeset
365 -- Case of argument which is a switch
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 -- We definitely need section by section comments here ???
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 if Skip_Next then
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 -- This argument must not be parsed, just add it to the
kono
parents:
diff changeset
372 -- list of linker's options.
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 Skip_Next := False;
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 Linker_Options.Increment_Last;
kono
parents:
diff changeset
377 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
378 new String'(Arg);
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 elsif Arg'Length /= 0 and then Arg (1) = '-' then
kono
parents:
diff changeset
381 if Arg'Length > 4 and then Arg (2 .. 5) = "gnat" then
kono
parents:
diff changeset
382 Exit_With_Error
kono
parents:
diff changeset
383 ("invalid switch: """ & Arg & """ (gnat not needed here)");
kono
parents:
diff changeset
384 end if;
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 if Arg = "-Xlinker" then
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 -- Next argument should be sent directly to the linker.
kono
parents:
diff changeset
389 -- We do not want to parse it here.
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 Skip_Next := True;
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 Linker_Options.Increment_Last;
kono
parents:
diff changeset
394 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
395 new String'(Arg);
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 elsif Arg (2) = 'g'
kono
parents:
diff changeset
398 and then (Arg'Length < 5 or else Arg (2 .. 5) /= "gnat")
kono
parents:
diff changeset
399 then
kono
parents:
diff changeset
400 Debug_Flag_Present := True;
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 Linker_Options.Increment_Last;
kono
parents:
diff changeset
403 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
404 new String'(Arg);
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 Binder_Options.Increment_Last;
kono
parents:
diff changeset
407 Binder_Options.Table (Binder_Options.Last) :=
kono
parents:
diff changeset
408 Linker_Options.Table (Linker_Options.Last);
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410 elsif Arg'Length >= 3 and then Arg (2) = 'M' then
kono
parents:
diff changeset
411 declare
kono
parents:
diff changeset
412 Switches : String_List_Access;
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 begin
kono
parents:
diff changeset
415 Convert (Map_File, Arg (3 .. Arg'Last), Switches);
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 if Switches /= null then
kono
parents:
diff changeset
418 for J in Switches'Range loop
kono
parents:
diff changeset
419 Linker_Options.Increment_Last;
kono
parents:
diff changeset
420 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
421 Switches (J);
kono
parents:
diff changeset
422 end loop;
kono
parents:
diff changeset
423 end if;
kono
parents:
diff changeset
424 end;
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 elsif Arg'Length = 2 then
kono
parents:
diff changeset
427 case Arg (2) is
kono
parents:
diff changeset
428 when 'f' =>
kono
parents:
diff changeset
429 if Object_List_File_Supported then
kono
parents:
diff changeset
430 Object_List_File_Required := True;
kono
parents:
diff changeset
431 else
kono
parents:
diff changeset
432 Exit_With_Error
kono
parents:
diff changeset
433 ("Object list file not supported on this target");
kono
parents:
diff changeset
434 end if;
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 when 'M' =>
kono
parents:
diff changeset
437 Create_Map_File := True;
kono
parents:
diff changeset
438
kono
parents:
diff changeset
439 when 'n' =>
kono
parents:
diff changeset
440 Compile_Bind_File := False;
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 when 'o' =>
kono
parents:
diff changeset
443 Next_Arg := Next_Arg + 1;
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 if Next_Arg > Argument_Count then
kono
parents:
diff changeset
446 Exit_With_Error ("Missing argument for -o");
kono
parents:
diff changeset
447 end if;
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 Output_File_Name :=
kono
parents:
diff changeset
450 new String'(Executable_Name
kono
parents:
diff changeset
451 (Argument (Next_Arg),
kono
parents:
diff changeset
452 Only_If_No_Suffix => True));
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 when 'P' =>
kono
parents:
diff changeset
455 Opt.CodePeer_Mode := True;
kono
parents:
diff changeset
456
kono
parents:
diff changeset
457 when 'R' =>
kono
parents:
diff changeset
458 Opt.Run_Path_Option := False;
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 when 'v' =>
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462 -- Support "double" verbose mode. Second -v
kono
parents:
diff changeset
463 -- gets sent to the linker and binder phases.
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 if Verbose_Mode then
kono
parents:
diff changeset
466 Very_Verbose_Mode := True;
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 Linker_Options.Increment_Last;
kono
parents:
diff changeset
469 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
470 new String'(Arg);
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 Binder_Options.Increment_Last;
kono
parents:
diff changeset
473 Binder_Options.Table (Binder_Options.Last) :=
kono
parents:
diff changeset
474 Linker_Options.Table (Linker_Options.Last);
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 else
kono
parents:
diff changeset
477 Verbose_Mode := True;
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 end if;
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 when others =>
kono
parents:
diff changeset
482 Linker_Options.Increment_Last;
kono
parents:
diff changeset
483 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
484 new String'(Arg);
kono
parents:
diff changeset
485
kono
parents:
diff changeset
486 end case;
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 elsif Arg (2) = 'B' then
kono
parents:
diff changeset
489 Linker_Options.Increment_Last;
kono
parents:
diff changeset
490 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
491 new String'(Arg);
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 Binder_Options.Increment_Last;
kono
parents:
diff changeset
494 Binder_Options.Table (Binder_Options.Last) :=
kono
parents:
diff changeset
495 Linker_Options.Table (Linker_Options.Last);
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 elsif Arg'Length >= 7 and then Arg (1 .. 7) = "--LINK=" then
kono
parents:
diff changeset
498 if Arg'Length = 7 then
kono
parents:
diff changeset
499 Exit_With_Error ("Missing argument for --LINK=");
kono
parents:
diff changeset
500 end if;
kono
parents:
diff changeset
501
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
502 declare
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
503 L_Args : constant Argument_List_Access :=
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
504 Argument_String_To_List (Arg (8 .. Arg'Last));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
505 begin
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
506 -- The linker program is the first argument
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
507
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
508 Linker_Path :=
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
509 System.OS_Lib.Locate_Exec_On_Path (L_Args.all (1).all);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
510
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
511 if Linker_Path = null then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
512 Exit_With_Error
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
513 ("Could not locate linker: " & L_Args.all (1).all);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
514 end if;
111
kono
parents:
diff changeset
515
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
516 -- The other arguments are passed as-is to the linker and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
517 -- override those coming from --GCC= if any.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
518
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
519 if L_Args.all'Last >= 2 then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
520 Gcc_Linker_Options.Set_Last (0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
521 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
522
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
523 for J in 2 .. L_Args.all'Last loop
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
524 Gcc_Linker_Options.Increment_Last;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
525 Gcc_Linker_Options.Table
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
526 (Gcc_Linker_Options.Last) :=
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
527 new String'(L_Args.all (J).all);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
528 end loop;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
529 end;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
530
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
531 elsif Arg'Length >= 6 and then Arg (1 .. 6) = "--GCC=" then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
532 if Arg'Length = 6 then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
533 Exit_With_Error ("Missing argument for --GCC=");
111
kono
parents:
diff changeset
534 end if;
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 declare
kono
parents:
diff changeset
537 Program_Args : constant Argument_List_Access :=
kono
parents:
diff changeset
538 Argument_String_To_List
kono
parents:
diff changeset
539 (Arg (7 .. Arg'Last));
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 begin
kono
parents:
diff changeset
542 if Program_Args.all (1).all /= Gcc.all then
kono
parents:
diff changeset
543 Gcc := new String'(Program_Args.all (1).all);
kono
parents:
diff changeset
544 Standard_Gcc := False;
kono
parents:
diff changeset
545 end if;
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 -- Set appropriate flags for switches passed
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 for J in 2 .. Program_Args.all'Last loop
kono
parents:
diff changeset
550 declare
kono
parents:
diff changeset
551 Arg : constant String := Program_Args.all (J).all;
kono
parents:
diff changeset
552 AF : constant Integer := Arg'First;
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 begin
kono
parents:
diff changeset
555 if Arg'Length /= 0 and then Arg (AF) = '-' then
kono
parents:
diff changeset
556 if Arg (AF + 1) = 'g'
kono
parents:
diff changeset
557 and then (Arg'Length = 2
kono
parents:
diff changeset
558 or else Arg (AF + 2) in '0' .. '3'
kono
parents:
diff changeset
559 or else Arg (AF + 2 .. Arg'Last) = "coff")
kono
parents:
diff changeset
560 then
kono
parents:
diff changeset
561 Debug_Flag_Present := True;
kono
parents:
diff changeset
562 end if;
kono
parents:
diff changeset
563 end if;
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 -- Add directory to source search dirs so that
kono
parents:
diff changeset
566 -- Get_Target_Parameters can find system.ads
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568 if Arg (AF .. AF + 1) = "-I"
kono
parents:
diff changeset
569 and then Arg'Length > 2
kono
parents:
diff changeset
570 then
kono
parents:
diff changeset
571 Add_Src_Search_Dir (Arg (AF + 2 .. Arg'Last));
kono
parents:
diff changeset
572 end if;
kono
parents:
diff changeset
573
kono
parents:
diff changeset
574 -- Pass to gcc for compiling binder generated file
kono
parents:
diff changeset
575 -- No use passing libraries, it will just generate
kono
parents:
diff changeset
576 -- a warning
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 if not (Arg (AF .. AF + 1) = "-l"
kono
parents:
diff changeset
579 or else Arg (AF .. AF + 1) = "-L")
kono
parents:
diff changeset
580 then
kono
parents:
diff changeset
581 Binder_Options.Increment_Last;
kono
parents:
diff changeset
582 Binder_Options.Table (Binder_Options.Last) :=
kono
parents:
diff changeset
583 new String'(Arg);
kono
parents:
diff changeset
584 end if;
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 -- Pass to gcc for linking program
kono
parents:
diff changeset
587
kono
parents:
diff changeset
588 Gcc_Linker_Options.Increment_Last;
kono
parents:
diff changeset
589 Gcc_Linker_Options.Table
kono
parents:
diff changeset
590 (Gcc_Linker_Options.Last) := new String'(Arg);
kono
parents:
diff changeset
591 end;
kono
parents:
diff changeset
592 end loop;
kono
parents:
diff changeset
593 end;
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 -- Send all multi-character switches not recognized as
kono
parents:
diff changeset
596 -- a special case by gnatlink to the linker/loader stage.
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 else
kono
parents:
diff changeset
599 Linker_Options.Increment_Last;
kono
parents:
diff changeset
600 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
601 new String'(Arg);
kono
parents:
diff changeset
602 end if;
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 -- Here if argument is a file name rather than a switch
kono
parents:
diff changeset
605
kono
parents:
diff changeset
606 else
kono
parents:
diff changeset
607 -- If explicit ali file, capture it
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 if Arg'Length > 4
kono
parents:
diff changeset
610 and then Arg (Arg'Last - 3 .. Arg'Last) = ".ali"
kono
parents:
diff changeset
611 then
kono
parents:
diff changeset
612 if Ali_File_Name = null then
kono
parents:
diff changeset
613 Ali_File_Name := new String'(Arg);
kono
parents:
diff changeset
614 else
kono
parents:
diff changeset
615 Exit_With_Error ("cannot handle more than one ALI file");
kono
parents:
diff changeset
616 end if;
kono
parents:
diff changeset
617
kono
parents:
diff changeset
618 -- If target object file, record object file
kono
parents:
diff changeset
619
kono
parents:
diff changeset
620 elsif Arg'Length > Get_Target_Object_Suffix.all'Length
kono
parents:
diff changeset
621 and then Arg
kono
parents:
diff changeset
622 (Arg'Last -
kono
parents:
diff changeset
623 Get_Target_Object_Suffix.all'Length + 1 .. Arg'Last)
kono
parents:
diff changeset
624 = Get_Target_Object_Suffix.all
kono
parents:
diff changeset
625 then
kono
parents:
diff changeset
626 Linker_Objects.Increment_Last;
kono
parents:
diff changeset
627 Linker_Objects.Table (Linker_Objects.Last) :=
kono
parents:
diff changeset
628 new String'(Arg);
kono
parents:
diff changeset
629
kono
parents:
diff changeset
630 -- If host object file, record object file
kono
parents:
diff changeset
631
kono
parents:
diff changeset
632 elsif Arg'Length > Get_Object_Suffix.all'Length
kono
parents:
diff changeset
633 and then Arg
kono
parents:
diff changeset
634 (Arg'Last - Get_Object_Suffix.all'Length + 1 .. Arg'Last)
kono
parents:
diff changeset
635 = Get_Object_Suffix.all
kono
parents:
diff changeset
636 then
kono
parents:
diff changeset
637 Linker_Objects.Increment_Last;
kono
parents:
diff changeset
638 Linker_Objects.Table (Linker_Objects.Last) :=
kono
parents:
diff changeset
639 new String'(Arg);
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 -- If corresponding ali file exists, capture it
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 elsif Ali_File_Name = null
kono
parents:
diff changeset
644 and then Is_Regular_File (Arg & ".ali")
kono
parents:
diff changeset
645 then
kono
parents:
diff changeset
646 Ali_File_Name := new String'(Arg & ".ali");
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 -- Otherwise assume this is a linker options entry, but
kono
parents:
diff changeset
649 -- see below for interesting adjustment to this assumption.
kono
parents:
diff changeset
650
kono
parents:
diff changeset
651 else
kono
parents:
diff changeset
652 Linker_Options.Increment_Last;
kono
parents:
diff changeset
653 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
654 new String'(Arg);
kono
parents:
diff changeset
655 end if;
kono
parents:
diff changeset
656 end if;
kono
parents:
diff changeset
657 end Process_One_Arg;
kono
parents:
diff changeset
658
kono
parents:
diff changeset
659 Next_Arg := Next_Arg + 1;
kono
parents:
diff changeset
660 end loop;
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 -- Compile the bind file with warnings suppressed, because
kono
parents:
diff changeset
663 -- otherwise the with of the main program may cause junk warnings.
kono
parents:
diff changeset
664
kono
parents:
diff changeset
665 Binder_Options.Increment_Last;
kono
parents:
diff changeset
666 Binder_Options.Table (Binder_Options.Last) := new String'("-gnatws");
kono
parents:
diff changeset
667
kono
parents:
diff changeset
668 -- If we did not get an ali file at all, and we had at least one
kono
parents:
diff changeset
669 -- linker option, then assume that was the intended ali file after
kono
parents:
diff changeset
670 -- all, so that we get a nicer message later on.
kono
parents:
diff changeset
671
kono
parents:
diff changeset
672 if Ali_File_Name = null
kono
parents:
diff changeset
673 and then Linker_Options.Last >= Linker_Options.First
kono
parents:
diff changeset
674 then
kono
parents:
diff changeset
675 Ali_File_Name :=
kono
parents:
diff changeset
676 new String'(Linker_Options.Table (Linker_Options.First).all
kono
parents:
diff changeset
677 & ".ali");
kono
parents:
diff changeset
678 end if;
kono
parents:
diff changeset
679 end Process_Args;
kono
parents:
diff changeset
680
kono
parents:
diff changeset
681 -------------------------
kono
parents:
diff changeset
682 -- Process_Binder_File --
kono
parents:
diff changeset
683 -------------------------
kono
parents:
diff changeset
684
kono
parents:
diff changeset
685 procedure Process_Binder_File (Name : String) is
kono
parents:
diff changeset
686 Fd : FILEs;
kono
parents:
diff changeset
687 -- Binder file's descriptor
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 Link_Bytes : Integer := 0;
kono
parents:
diff changeset
690 -- Projected number of bytes for the linker command line
kono
parents:
diff changeset
691
kono
parents:
diff changeset
692 Link_Max : Integer;
kono
parents:
diff changeset
693 pragma Import (C, Link_Max, "__gnat_link_max");
kono
parents:
diff changeset
694 -- Maximum number of bytes on the command line supported by the OS
kono
parents:
diff changeset
695 -- linker. Passed this limit the response file mechanism must be used
kono
parents:
diff changeset
696 -- if supported.
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 Next_Line : String (1 .. 1000);
kono
parents:
diff changeset
699 -- Current line value
kono
parents:
diff changeset
700
kono
parents:
diff changeset
701 Nlast : Integer;
kono
parents:
diff changeset
702 Nfirst : Integer;
kono
parents:
diff changeset
703 -- Current line slice (the slice does not contain line terminator)
kono
parents:
diff changeset
704
kono
parents:
diff changeset
705 Last : Integer;
kono
parents:
diff changeset
706 -- Current line last character for shared libraries (without version)
kono
parents:
diff changeset
707
kono
parents:
diff changeset
708 Objs_Begin : Integer := 0;
kono
parents:
diff changeset
709 -- First object file index in Linker_Objects table
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 Objs_End : Integer := 0;
kono
parents:
diff changeset
712 -- Last object file index in Linker_Objects table
kono
parents:
diff changeset
713
kono
parents:
diff changeset
714 Status : int;
kono
parents:
diff changeset
715 pragma Warnings (Off, Status);
kono
parents:
diff changeset
716 -- Used for various Interfaces.C_Streams calls
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 Closing_Status : Boolean;
kono
parents:
diff changeset
719 pragma Warnings (Off, Closing_Status);
kono
parents:
diff changeset
720 -- For call to Close
kono
parents:
diff changeset
721
kono
parents:
diff changeset
722 GNAT_Static : Boolean := False;
kono
parents:
diff changeset
723 -- Save state of -static option
kono
parents:
diff changeset
724
kono
parents:
diff changeset
725 GNAT_Shared : Boolean := False;
kono
parents:
diff changeset
726 -- Save state of -shared option
kono
parents:
diff changeset
727
kono
parents:
diff changeset
728 Xlinker_Was_Previous : Boolean := False;
kono
parents:
diff changeset
729 -- Indicate that "-Xlinker" was the option preceding the current option.
kono
parents:
diff changeset
730 -- If True, then the current option is never suppressed.
kono
parents:
diff changeset
731
kono
parents:
diff changeset
732 -- Rollback data
kono
parents:
diff changeset
733
kono
parents:
diff changeset
734 -- These data items are used to store current binder file context. The
kono
parents:
diff changeset
735 -- context is composed of the file descriptor position and the current
kono
parents:
diff changeset
736 -- line together with the slice indexes (first and last position) for
kono
parents:
diff changeset
737 -- this line. The rollback data are used by the Store_File_Context and
kono
parents:
diff changeset
738 -- Rollback_File_Context routines below. The file context mechanism
kono
parents:
diff changeset
739 -- interact only with the Get_Next_Line call. For example:
kono
parents:
diff changeset
740
kono
parents:
diff changeset
741 -- Store_File_Context;
kono
parents:
diff changeset
742 -- Get_Next_Line;
kono
parents:
diff changeset
743 -- Rollback_File_Context;
kono
parents:
diff changeset
744 -- Get_Next_Line;
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746 -- Both Get_Next_Line calls above will read the exact same data from
kono
parents:
diff changeset
747 -- the file. In other words, Next_Line, Nfirst and Nlast variables
kono
parents:
diff changeset
748 -- will be set with the exact same values.
kono
parents:
diff changeset
749
kono
parents:
diff changeset
750 RB_File_Pos : long; -- File position
kono
parents:
diff changeset
751 RB_Next_Line : String (1 .. 1000); -- Current line content
kono
parents:
diff changeset
752 RB_Nlast : Integer; -- Slice last index
kono
parents:
diff changeset
753 RB_Nfirst : Integer; -- Slice first index
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 Run_Path_Option_Ptr : Interfaces.C.Strings.chars_ptr;
kono
parents:
diff changeset
756 pragma Import (C, Run_Path_Option_Ptr, "__gnat_run_path_option");
kono
parents:
diff changeset
757 -- Pointer to string representing the native linker option which
kono
parents:
diff changeset
758 -- specifies the path where the dynamic loader should find shared
kono
parents:
diff changeset
759 -- libraries. Equal to null string if this system doesn't support it.
kono
parents:
diff changeset
760
kono
parents:
diff changeset
761 Libgcc_Subdir_Ptr : Interfaces.C.Strings.chars_ptr;
kono
parents:
diff changeset
762 pragma Import (C, Libgcc_Subdir_Ptr, "__gnat_default_libgcc_subdir");
kono
parents:
diff changeset
763 -- Pointer to string indicating the installation subdirectory where
kono
parents:
diff changeset
764 -- a default shared libgcc might be found.
kono
parents:
diff changeset
765
kono
parents:
diff changeset
766 Object_Library_Ext_Ptr : Interfaces.C.Strings.chars_ptr;
kono
parents:
diff changeset
767 pragma Import
kono
parents:
diff changeset
768 (C, Object_Library_Ext_Ptr, "__gnat_object_library_extension");
kono
parents:
diff changeset
769 -- Pointer to string specifying the default extension for
kono
parents:
diff changeset
770 -- object libraries, e.g. Unix uses ".a".
kono
parents:
diff changeset
771
kono
parents:
diff changeset
772 Separate_Run_Path_Options : Boolean;
kono
parents:
diff changeset
773 for Separate_Run_Path_Options'Size use Character'Size;
kono
parents:
diff changeset
774 pragma Import
kono
parents:
diff changeset
775 (C, Separate_Run_Path_Options, "__gnat_separate_run_path_options");
kono
parents:
diff changeset
776 -- Whether separate rpath options should be emitted for each directory
kono
parents:
diff changeset
777
kono
parents:
diff changeset
778 procedure Get_Next_Line;
kono
parents:
diff changeset
779 -- Read the next line from the binder file without the line
kono
parents:
diff changeset
780 -- terminator.
kono
parents:
diff changeset
781
kono
parents:
diff changeset
782 function Index (S, Pattern : String) return Natural;
kono
parents:
diff changeset
783 -- Return the last occurrence of Pattern in S, or 0 if none
kono
parents:
diff changeset
784
kono
parents:
diff changeset
785 procedure Store_File_Context;
kono
parents:
diff changeset
786 -- Store current file context, Fd position and current line data.
kono
parents:
diff changeset
787 -- The file context is stored into the rollback data above (RB_*).
kono
parents:
diff changeset
788 -- Store_File_Context can be called at any time, only the last call
kono
parents:
diff changeset
789 -- will be used (i.e. this routine overwrites the file context).
kono
parents:
diff changeset
790
kono
parents:
diff changeset
791 procedure Rollback_File_Context;
kono
parents:
diff changeset
792 -- Restore file context from rollback data. This routine must be called
kono
parents:
diff changeset
793 -- after Store_File_Context. The binder file context will be restored
kono
parents:
diff changeset
794 -- with the data stored by the last Store_File_Context call.
kono
parents:
diff changeset
795
kono
parents:
diff changeset
796 procedure Write_RF (S : String);
kono
parents:
diff changeset
797 -- Write a string to the response file and check if it was successful.
kono
parents:
diff changeset
798 -- Fail the program if it was not successful (disk full).
kono
parents:
diff changeset
799
kono
parents:
diff changeset
800 -------------------
kono
parents:
diff changeset
801 -- Get_Next_Line --
kono
parents:
diff changeset
802 -------------------
kono
parents:
diff changeset
803
kono
parents:
diff changeset
804 procedure Get_Next_Line is
kono
parents:
diff changeset
805 Fchars : chars;
kono
parents:
diff changeset
806
kono
parents:
diff changeset
807 begin
kono
parents:
diff changeset
808 Fchars := fgets (Next_Line'Address, Next_Line'Length, Fd);
kono
parents:
diff changeset
809
kono
parents:
diff changeset
810 if Fchars = System.Null_Address then
kono
parents:
diff changeset
811 Exit_With_Error ("Error reading binder output");
kono
parents:
diff changeset
812 end if;
kono
parents:
diff changeset
813
kono
parents:
diff changeset
814 Nfirst := Next_Line'First;
kono
parents:
diff changeset
815 Nlast := Nfirst;
kono
parents:
diff changeset
816 while Nlast <= Next_Line'Last
kono
parents:
diff changeset
817 and then Next_Line (Nlast) /= ASCII.LF
kono
parents:
diff changeset
818 and then Next_Line (Nlast) /= ASCII.CR
kono
parents:
diff changeset
819 loop
kono
parents:
diff changeset
820 Nlast := Nlast + 1;
kono
parents:
diff changeset
821 end loop;
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 Nlast := Nlast - 1;
kono
parents:
diff changeset
824 end Get_Next_Line;
kono
parents:
diff changeset
825
kono
parents:
diff changeset
826 -----------
kono
parents:
diff changeset
827 -- Index --
kono
parents:
diff changeset
828 -----------
kono
parents:
diff changeset
829
kono
parents:
diff changeset
830 function Index (S, Pattern : String) return Natural is
kono
parents:
diff changeset
831 Len : constant Natural := Pattern'Length;
kono
parents:
diff changeset
832
kono
parents:
diff changeset
833 begin
kono
parents:
diff changeset
834 for J in reverse S'First .. S'Last - Len + 1 loop
kono
parents:
diff changeset
835 if Pattern = S (J .. J + Len - 1) then
kono
parents:
diff changeset
836 return J;
kono
parents:
diff changeset
837 end if;
kono
parents:
diff changeset
838 end loop;
kono
parents:
diff changeset
839
kono
parents:
diff changeset
840 return 0;
kono
parents:
diff changeset
841 end Index;
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 ---------------------------
kono
parents:
diff changeset
844 -- Rollback_File_Context --
kono
parents:
diff changeset
845 ---------------------------
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 procedure Rollback_File_Context is
kono
parents:
diff changeset
848 begin
kono
parents:
diff changeset
849 Next_Line := RB_Next_Line;
kono
parents:
diff changeset
850 Nfirst := RB_Nfirst;
kono
parents:
diff changeset
851 Nlast := RB_Nlast;
kono
parents:
diff changeset
852 Status := fseek (Fd, RB_File_Pos, Interfaces.C_Streams.SEEK_SET);
kono
parents:
diff changeset
853
kono
parents:
diff changeset
854 if Status = -1 then
kono
parents:
diff changeset
855 Exit_With_Error ("Error setting file position");
kono
parents:
diff changeset
856 end if;
kono
parents:
diff changeset
857 end Rollback_File_Context;
kono
parents:
diff changeset
858
kono
parents:
diff changeset
859 ------------------------
kono
parents:
diff changeset
860 -- Store_File_Context --
kono
parents:
diff changeset
861 ------------------------
kono
parents:
diff changeset
862
kono
parents:
diff changeset
863 procedure Store_File_Context is
kono
parents:
diff changeset
864 use type System.CRTL.long;
kono
parents:
diff changeset
865
kono
parents:
diff changeset
866 begin
kono
parents:
diff changeset
867 RB_Next_Line := Next_Line;
kono
parents:
diff changeset
868 RB_Nfirst := Nfirst;
kono
parents:
diff changeset
869 RB_Nlast := Nlast;
kono
parents:
diff changeset
870 RB_File_Pos := ftell (Fd);
kono
parents:
diff changeset
871
kono
parents:
diff changeset
872 if RB_File_Pos = -1 then
kono
parents:
diff changeset
873 Exit_With_Error ("Error getting file position");
kono
parents:
diff changeset
874 end if;
kono
parents:
diff changeset
875 end Store_File_Context;
kono
parents:
diff changeset
876
kono
parents:
diff changeset
877 --------------
kono
parents:
diff changeset
878 -- Write_RF --
kono
parents:
diff changeset
879 --------------
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 procedure Write_RF (S : String) is
kono
parents:
diff changeset
882 Success : Boolean := True;
kono
parents:
diff changeset
883 Back_Slash : constant Character := '\';
kono
parents:
diff changeset
884
kono
parents:
diff changeset
885 begin
kono
parents:
diff changeset
886 -- If a GNU response file is used, space and backslash need to be
kono
parents:
diff changeset
887 -- escaped because they are interpreted as a string separator and
kono
parents:
diff changeset
888 -- an escape character respectively by the underlying mechanism.
kono
parents:
diff changeset
889 -- On the other hand, quote and double-quote are not escaped since
kono
parents:
diff changeset
890 -- they are interpreted as string delimiters on both sides.
kono
parents:
diff changeset
891
kono
parents:
diff changeset
892 if Using_GNU_response_file then
kono
parents:
diff changeset
893 for J in S'Range loop
kono
parents:
diff changeset
894 if S (J) = ' ' or else S (J) = '\' then
kono
parents:
diff changeset
895 if Write (Tname_FD, Back_Slash'Address, 1) /= 1 then
kono
parents:
diff changeset
896 Success := False;
kono
parents:
diff changeset
897 end if;
kono
parents:
diff changeset
898 end if;
kono
parents:
diff changeset
899
kono
parents:
diff changeset
900 if Write (Tname_FD, S (J)'Address, 1) /= 1 then
kono
parents:
diff changeset
901 Success := False;
kono
parents:
diff changeset
902 end if;
kono
parents:
diff changeset
903 end loop;
kono
parents:
diff changeset
904
kono
parents:
diff changeset
905 else
kono
parents:
diff changeset
906 if Write (Tname_FD, S'Address, S'Length) /= S'Length then
kono
parents:
diff changeset
907 Success := False;
kono
parents:
diff changeset
908 end if;
kono
parents:
diff changeset
909 end if;
kono
parents:
diff changeset
910
kono
parents:
diff changeset
911 if Write (Tname_FD, ASCII.LF'Address, 1) /= 1 then
kono
parents:
diff changeset
912 Success := False;
kono
parents:
diff changeset
913 end if;
kono
parents:
diff changeset
914
kono
parents:
diff changeset
915 if not Success then
kono
parents:
diff changeset
916 Exit_With_Error ("Error generating response file: disk full");
kono
parents:
diff changeset
917 end if;
kono
parents:
diff changeset
918 end Write_RF;
kono
parents:
diff changeset
919
kono
parents:
diff changeset
920 -- Start of processing for Process_Binder_File
kono
parents:
diff changeset
921
kono
parents:
diff changeset
922 begin
kono
parents:
diff changeset
923 Fd := fopen (Name'Address, Read_Mode'Address);
kono
parents:
diff changeset
924
kono
parents:
diff changeset
925 if Fd = NULL_Stream then
kono
parents:
diff changeset
926 Exit_With_Error ("Failed to open binder output");
kono
parents:
diff changeset
927 end if;
kono
parents:
diff changeset
928
kono
parents:
diff changeset
929 -- Skip up to the Begin Info line
kono
parents:
diff changeset
930
kono
parents:
diff changeset
931 loop
kono
parents:
diff changeset
932 Get_Next_Line;
kono
parents:
diff changeset
933 exit when Next_Line (Nfirst .. Nlast) = Begin_Info;
kono
parents:
diff changeset
934 end loop;
kono
parents:
diff changeset
935
kono
parents:
diff changeset
936 loop
kono
parents:
diff changeset
937 Get_Next_Line;
kono
parents:
diff changeset
938
kono
parents:
diff changeset
939 -- Go to end when end line is reached (this will happen in
kono
parents:
diff changeset
940 -- High_Integrity_Mode where no -L switches are generated)
kono
parents:
diff changeset
941
kono
parents:
diff changeset
942 exit when Next_Line (Nfirst .. Nlast) = End_Info;
kono
parents:
diff changeset
943
kono
parents:
diff changeset
944 Next_Line (Nfirst .. Nlast - 8) := Next_Line (Nfirst + 8 .. Nlast);
kono
parents:
diff changeset
945 Nlast := Nlast - 8;
kono
parents:
diff changeset
946
kono
parents:
diff changeset
947 -- Go to next section when switches are reached
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 exit when Next_Line (1) = '-';
kono
parents:
diff changeset
950
kono
parents:
diff changeset
951 -- Otherwise we have another object file to collect
kono
parents:
diff changeset
952
kono
parents:
diff changeset
953 Linker_Objects.Increment_Last;
kono
parents:
diff changeset
954
kono
parents:
diff changeset
955 -- Mark the positions of first and last object files in case they
kono
parents:
diff changeset
956 -- need to be placed with a named file on systems having linker
kono
parents:
diff changeset
957 -- line limitations.
kono
parents:
diff changeset
958
kono
parents:
diff changeset
959 if Objs_Begin = 0 then
kono
parents:
diff changeset
960 Objs_Begin := Linker_Objects.Last;
kono
parents:
diff changeset
961 end if;
kono
parents:
diff changeset
962
kono
parents:
diff changeset
963 Linker_Objects.Table (Linker_Objects.Last) :=
kono
parents:
diff changeset
964 new String'(Next_Line (Nfirst .. Nlast));
kono
parents:
diff changeset
965
kono
parents:
diff changeset
966 -- Nlast - Nfirst + 1, for the size, plus one for the space between
kono
parents:
diff changeset
967 -- each arguments.
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 Link_Bytes := Link_Bytes + Nlast - Nfirst + 2;
kono
parents:
diff changeset
970 end loop;
kono
parents:
diff changeset
971
kono
parents:
diff changeset
972 Objs_End := Linker_Objects.Last;
kono
parents:
diff changeset
973
kono
parents:
diff changeset
974 -- Continue to compute the Link_Bytes, the linker options are part of
kono
parents:
diff changeset
975 -- command line length.
kono
parents:
diff changeset
976
kono
parents:
diff changeset
977 Store_File_Context;
kono
parents:
diff changeset
978
kono
parents:
diff changeset
979 while Next_Line (Nfirst .. Nlast) /= End_Info loop
kono
parents:
diff changeset
980 Link_Bytes := Link_Bytes + Nlast - Nfirst + 2;
kono
parents:
diff changeset
981 Get_Next_Line;
kono
parents:
diff changeset
982 end loop;
kono
parents:
diff changeset
983
kono
parents:
diff changeset
984 Rollback_File_Context;
kono
parents:
diff changeset
985
kono
parents:
diff changeset
986 -- On systems that have limitations on handling very long linker lines
kono
parents:
diff changeset
987 -- we make use of the system linker option which takes a list of object
kono
parents:
diff changeset
988 -- file names from a file instead of the command line itself. What we do
kono
parents:
diff changeset
989 -- is to replace the list of object files by the special linker option
kono
parents:
diff changeset
990 -- which then reads the object file list from a file instead. The option
kono
parents:
diff changeset
991 -- to read from a file instead of the command line is only triggered if
kono
parents:
diff changeset
992 -- a conservative threshold is passed.
kono
parents:
diff changeset
993
kono
parents:
diff changeset
994 if Object_List_File_Required
kono
parents:
diff changeset
995 or else (Object_List_File_Supported
kono
parents:
diff changeset
996 and then Link_Bytes > Link_Max)
kono
parents:
diff changeset
997 then
kono
parents:
diff changeset
998 -- Create a temporary file containing the Ada user object files
kono
parents:
diff changeset
999 -- needed by the link. This list is taken from the bind file and is
kono
parents:
diff changeset
1000 -- output one object per line for maximal compatibility with linkers
kono
parents:
diff changeset
1001 -- supporting this option.
kono
parents:
diff changeset
1002
kono
parents:
diff changeset
1003 Create_Temp_File (Tname_FD, Tname);
kono
parents:
diff changeset
1004
kono
parents:
diff changeset
1005 -- ??? File descriptor should be checked to not be Invalid_FD.
kono
parents:
diff changeset
1006 -- ??? Status of Write and Close operations should be checked, and
kono
parents:
diff changeset
1007 -- failure should occur if a status is wrong.
kono
parents:
diff changeset
1008
kono
parents:
diff changeset
1009 for J in Objs_Begin .. Objs_End loop
kono
parents:
diff changeset
1010 Write_RF (Linker_Objects.Table (J).all);
kono
parents:
diff changeset
1011
kono
parents:
diff changeset
1012 Response_File_Objects.Increment_Last;
kono
parents:
diff changeset
1013 Response_File_Objects.Table (Response_File_Objects.Last) :=
kono
parents:
diff changeset
1014 Linker_Objects.Table (J);
kono
parents:
diff changeset
1015 end loop;
kono
parents:
diff changeset
1016
kono
parents:
diff changeset
1017 Close (Tname_FD, Closing_Status);
kono
parents:
diff changeset
1018
kono
parents:
diff changeset
1019 -- Add the special objects list file option together with the name
kono
parents:
diff changeset
1020 -- of the temporary file (removing the null character) to the objects
kono
parents:
diff changeset
1021 -- file table.
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 Linker_Objects.Table (Objs_Begin) :=
kono
parents:
diff changeset
1024 new String'(Object_File_Option &
kono
parents:
diff changeset
1025 Tname (Tname'First .. Tname'Last - 1));
kono
parents:
diff changeset
1026
kono
parents:
diff changeset
1027 -- The slots containing these object file names are then removed
kono
parents:
diff changeset
1028 -- from the objects table so they do not appear in the link. They are
kono
parents:
diff changeset
1029 -- removed by moving up the linker options and non-Ada object files
kono
parents:
diff changeset
1030 -- appearing after the Ada object list in the table.
kono
parents:
diff changeset
1031
kono
parents:
diff changeset
1032 declare
kono
parents:
diff changeset
1033 N : Integer;
kono
parents:
diff changeset
1034
kono
parents:
diff changeset
1035 begin
kono
parents:
diff changeset
1036 N := Objs_End - Objs_Begin + 1;
kono
parents:
diff changeset
1037
kono
parents:
diff changeset
1038 for J in Objs_End + 1 .. Linker_Objects.Last loop
kono
parents:
diff changeset
1039 Linker_Objects.Table (J - N + 1) := Linker_Objects.Table (J);
kono
parents:
diff changeset
1040 end loop;
kono
parents:
diff changeset
1041
kono
parents:
diff changeset
1042 Linker_Objects.Set_Last (Linker_Objects.Last - N + 1);
kono
parents:
diff changeset
1043 end;
kono
parents:
diff changeset
1044 end if;
kono
parents:
diff changeset
1045
kono
parents:
diff changeset
1046 -- Process switches and options
kono
parents:
diff changeset
1047
kono
parents:
diff changeset
1048 if Next_Line (Nfirst .. Nlast) /= End_Info then
kono
parents:
diff changeset
1049 Xlinker_Was_Previous := False;
kono
parents:
diff changeset
1050
kono
parents:
diff changeset
1051 loop
kono
parents:
diff changeset
1052 if Xlinker_Was_Previous
kono
parents:
diff changeset
1053 or else Next_Line (Nfirst .. Nlast) = "-Xlinker"
kono
parents:
diff changeset
1054 then
kono
parents:
diff changeset
1055 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1056 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
1057 new String'(Next_Line (Nfirst .. Nlast));
kono
parents:
diff changeset
1058
kono
parents:
diff changeset
1059 elsif Next_Line (Nfirst .. Nlast) = "-static" then
kono
parents:
diff changeset
1060 GNAT_Static := True;
kono
parents:
diff changeset
1061
kono
parents:
diff changeset
1062 elsif Next_Line (Nfirst .. Nlast) = "-shared" then
kono
parents:
diff changeset
1063 GNAT_Shared := True;
kono
parents:
diff changeset
1064
kono
parents:
diff changeset
1065 -- Add binder options only if not already set on the command line.
kono
parents:
diff changeset
1066 -- This rule is a way to control the linker options order.
kono
parents:
diff changeset
1067
kono
parents:
diff changeset
1068 else
kono
parents:
diff changeset
1069 if Nlast > Nfirst + 2 and then
kono
parents:
diff changeset
1070 Next_Line (Nfirst .. Nfirst + 1) = "-L"
kono
parents:
diff changeset
1071 then
kono
parents:
diff changeset
1072 -- Construct a library search path for use later to locate
kono
parents:
diff changeset
1073 -- static gnatlib libraries.
kono
parents:
diff changeset
1074
kono
parents:
diff changeset
1075 if Libpath.Last > 1 then
kono
parents:
diff changeset
1076 Libpath.Increment_Last;
kono
parents:
diff changeset
1077 Libpath.Table (Libpath.Last) := Path_Separator;
kono
parents:
diff changeset
1078 end if;
kono
parents:
diff changeset
1079
kono
parents:
diff changeset
1080 for I in Nfirst + 2 .. Nlast loop
kono
parents:
diff changeset
1081 Libpath.Increment_Last;
kono
parents:
diff changeset
1082 Libpath.Table (Libpath.Last) := Next_Line (I);
kono
parents:
diff changeset
1083 end loop;
kono
parents:
diff changeset
1084
kono
parents:
diff changeset
1085 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1086
kono
parents:
diff changeset
1087 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
1088 new String'(Next_Line (Nfirst .. Nlast));
kono
parents:
diff changeset
1089
kono
parents:
diff changeset
1090 elsif Next_Line (Nfirst .. Nlast) = "-lgnarl"
kono
parents:
diff changeset
1091 or else Next_Line (Nfirst .. Nlast) = "-lgnat"
kono
parents:
diff changeset
1092 or else
kono
parents:
diff changeset
1093 Next_Line
kono
parents:
diff changeset
1094 (1 .. Natural'Min (Nlast, 8 + Library_Version'Length)) =
kono
parents:
diff changeset
1095 Shared_Lib ("gnarl")
kono
parents:
diff changeset
1096 or else
kono
parents:
diff changeset
1097 Next_Line
kono
parents:
diff changeset
1098 (1 .. Natural'Min (Nlast, 7 + Library_Version'Length)) =
kono
parents:
diff changeset
1099 Shared_Lib ("gnat")
kono
parents:
diff changeset
1100 then
kono
parents:
diff changeset
1101 -- If it is a shared library, remove the library version.
kono
parents:
diff changeset
1102 -- We will be looking for the static version of the library
kono
parents:
diff changeset
1103 -- as it is in the same directory as the shared version.
kono
parents:
diff changeset
1104
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1105 if Nlast >= Library_Version'Length
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1106 and then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1107 Next_Line (Nlast - Library_Version'Length + 1 .. Nlast) =
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1108 Library_Version
111
kono
parents:
diff changeset
1109 then
kono
parents:
diff changeset
1110 -- Set Last to point to last character before the
kono
parents:
diff changeset
1111 -- library version.
kono
parents:
diff changeset
1112
kono
parents:
diff changeset
1113 Last := Nlast - Library_Version'Length - 1;
kono
parents:
diff changeset
1114 else
kono
parents:
diff changeset
1115 Last := Nlast;
kono
parents:
diff changeset
1116 end if;
kono
parents:
diff changeset
1117
kono
parents:
diff changeset
1118 -- Given a Gnat standard library, search the library path to
kono
parents:
diff changeset
1119 -- find the library location.
kono
parents:
diff changeset
1120
kono
parents:
diff changeset
1121 -- Shouldn't we abstract a proc here, we are getting awfully
kono
parents:
diff changeset
1122 -- heavily nested ???
kono
parents:
diff changeset
1123
kono
parents:
diff changeset
1124 declare
kono
parents:
diff changeset
1125 File_Path : String_Access;
kono
parents:
diff changeset
1126
kono
parents:
diff changeset
1127 Object_Lib_Extension : constant String :=
kono
parents:
diff changeset
1128 Value (Object_Library_Ext_Ptr);
kono
parents:
diff changeset
1129
kono
parents:
diff changeset
1130 File_Name : constant String := "lib" &
kono
parents:
diff changeset
1131 Next_Line (Nfirst + 2 .. Last) & Object_Lib_Extension;
kono
parents:
diff changeset
1132
kono
parents:
diff changeset
1133 Run_Path_Opt : constant String :=
kono
parents:
diff changeset
1134 Value (Run_Path_Option_Ptr);
kono
parents:
diff changeset
1135
kono
parents:
diff changeset
1136 GCC_Index : Natural;
kono
parents:
diff changeset
1137 Run_Path_Opt_Index : Natural := 0;
kono
parents:
diff changeset
1138
kono
parents:
diff changeset
1139 begin
kono
parents:
diff changeset
1140 File_Path :=
kono
parents:
diff changeset
1141 Locate_Regular_File (File_Name,
kono
parents:
diff changeset
1142 String (Libpath.Table (1 .. Libpath.Last)));
kono
parents:
diff changeset
1143
kono
parents:
diff changeset
1144 if File_Path /= null then
kono
parents:
diff changeset
1145 if GNAT_Static then
kono
parents:
diff changeset
1146
kono
parents:
diff changeset
1147 -- If static gnatlib found, explicitly specify to
kono
parents:
diff changeset
1148 -- overcome possible linker default usage of shared
kono
parents:
diff changeset
1149 -- version.
kono
parents:
diff changeset
1150
kono
parents:
diff changeset
1151 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1152
kono
parents:
diff changeset
1153 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
1154 new String'(File_Path.all);
kono
parents:
diff changeset
1155
kono
parents:
diff changeset
1156 elsif GNAT_Shared then
kono
parents:
diff changeset
1157 if Opt.Run_Path_Option then
kono
parents:
diff changeset
1158
kono
parents:
diff changeset
1159 -- If shared gnatlib desired, add appropriate
kono
parents:
diff changeset
1160 -- system specific switch so that it can be
kono
parents:
diff changeset
1161 -- located at runtime.
kono
parents:
diff changeset
1162
kono
parents:
diff changeset
1163 if Run_Path_Opt'Length /= 0 then
kono
parents:
diff changeset
1164
kono
parents:
diff changeset
1165 -- Output the system specific linker command
kono
parents:
diff changeset
1166 -- that allows the image activator to find
kono
parents:
diff changeset
1167 -- the shared library at runtime. Also add
kono
parents:
diff changeset
1168 -- path to find libgcc_s.so, if relevant.
kono
parents:
diff changeset
1169
kono
parents:
diff changeset
1170 declare
kono
parents:
diff changeset
1171 Path : String (1 .. File_Path'Length + 15);
kono
parents:
diff changeset
1172
kono
parents:
diff changeset
1173 Path_Last : constant Natural :=
kono
parents:
diff changeset
1174 File_Path'Length;
kono
parents:
diff changeset
1175
kono
parents:
diff changeset
1176 begin
kono
parents:
diff changeset
1177 Path (1 .. File_Path'Length) :=
kono
parents:
diff changeset
1178 File_Path.all;
kono
parents:
diff changeset
1179
kono
parents:
diff changeset
1180 -- To find the location of the shared version
kono
parents:
diff changeset
1181 -- of libgcc, we look for "gcc-lib" in the
kono
parents:
diff changeset
1182 -- path of the library. However, this
kono
parents:
diff changeset
1183 -- subdirectory is no longer present in
kono
parents:
diff changeset
1184 -- recent versions of GCC. So, we look for
kono
parents:
diff changeset
1185 -- the last subdirectory "lib" in the path.
kono
parents:
diff changeset
1186
kono
parents:
diff changeset
1187 GCC_Index :=
kono
parents:
diff changeset
1188 Index (Path (1 .. Path_Last), "gcc-lib");
kono
parents:
diff changeset
1189
kono
parents:
diff changeset
1190 if GCC_Index /= 0 then
kono
parents:
diff changeset
1191
kono
parents:
diff changeset
1192 -- The shared version of libgcc is
kono
parents:
diff changeset
1193 -- located in the parent directory.
kono
parents:
diff changeset
1194
kono
parents:
diff changeset
1195 GCC_Index := GCC_Index - 1;
kono
parents:
diff changeset
1196
kono
parents:
diff changeset
1197 else
kono
parents:
diff changeset
1198 GCC_Index :=
kono
parents:
diff changeset
1199 Index
kono
parents:
diff changeset
1200 (Path (1 .. Path_Last),
kono
parents:
diff changeset
1201 "/lib/");
kono
parents:
diff changeset
1202
kono
parents:
diff changeset
1203 if GCC_Index = 0 then
kono
parents:
diff changeset
1204 GCC_Index :=
kono
parents:
diff changeset
1205 Index (Path (1 .. Path_Last),
kono
parents:
diff changeset
1206 Directory_Separator & "lib"
kono
parents:
diff changeset
1207 & Directory_Separator);
kono
parents:
diff changeset
1208 end if;
kono
parents:
diff changeset
1209
kono
parents:
diff changeset
1210 -- If we have found a "lib" subdir in
kono
parents:
diff changeset
1211 -- the path to libgnat, the possible
kono
parents:
diff changeset
1212 -- shared libgcc of interest by default
kono
parents:
diff changeset
1213 -- is in libgcc_subdir at the same
kono
parents:
diff changeset
1214 -- level.
kono
parents:
diff changeset
1215
kono
parents:
diff changeset
1216 if GCC_Index /= 0 then
kono
parents:
diff changeset
1217 declare
kono
parents:
diff changeset
1218 Subdir : constant String :=
kono
parents:
diff changeset
1219 Value (Libgcc_Subdir_Ptr);
kono
parents:
diff changeset
1220 begin
kono
parents:
diff changeset
1221 Path
kono
parents:
diff changeset
1222 (GCC_Index + 1 ..
kono
parents:
diff changeset
1223 GCC_Index + Subdir'Length) :=
kono
parents:
diff changeset
1224 Subdir;
kono
parents:
diff changeset
1225 GCC_Index :=
kono
parents:
diff changeset
1226 GCC_Index + Subdir'Length;
kono
parents:
diff changeset
1227 end;
kono
parents:
diff changeset
1228 end if;
kono
parents:
diff changeset
1229 end if;
kono
parents:
diff changeset
1230
kono
parents:
diff changeset
1231 -- Look for an eventual run_path_option in
kono
parents:
diff changeset
1232 -- the linker switches.
kono
parents:
diff changeset
1233
kono
parents:
diff changeset
1234 if Separate_Run_Path_Options then
kono
parents:
diff changeset
1235 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1236 Linker_Options.Table
kono
parents:
diff changeset
1237 (Linker_Options.Last) :=
kono
parents:
diff changeset
1238 new String'
kono
parents:
diff changeset
1239 (Run_Path_Opt
kono
parents:
diff changeset
1240 & File_Path
kono
parents:
diff changeset
1241 (1 .. File_Path'Length
kono
parents:
diff changeset
1242 - File_Name'Length));
kono
parents:
diff changeset
1243
kono
parents:
diff changeset
1244 if GCC_Index /= 0 then
kono
parents:
diff changeset
1245 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1246 Linker_Options.Table
kono
parents:
diff changeset
1247 (Linker_Options.Last) :=
kono
parents:
diff changeset
1248 new String'
kono
parents:
diff changeset
1249 (Run_Path_Opt
kono
parents:
diff changeset
1250 & Path (1 .. GCC_Index));
kono
parents:
diff changeset
1251 end if;
kono
parents:
diff changeset
1252
kono
parents:
diff changeset
1253 else
kono
parents:
diff changeset
1254 for J in reverse
kono
parents:
diff changeset
1255 1 .. Linker_Options.Last
kono
parents:
diff changeset
1256 loop
kono
parents:
diff changeset
1257 if Linker_Options.Table (J) /= null
kono
parents:
diff changeset
1258 and then
kono
parents:
diff changeset
1259 Linker_Options.Table (J)'Length
kono
parents:
diff changeset
1260 > Run_Path_Opt'Length
kono
parents:
diff changeset
1261 and then
kono
parents:
diff changeset
1262 Linker_Options.Table (J)
kono
parents:
diff changeset
1263 (1 .. Run_Path_Opt'Length) =
kono
parents:
diff changeset
1264 Run_Path_Opt
kono
parents:
diff changeset
1265 then
kono
parents:
diff changeset
1266 -- We have found an already
kono
parents:
diff changeset
1267 -- specified run_path_option:
kono
parents:
diff changeset
1268 -- we will add to this
kono
parents:
diff changeset
1269 -- switch, because only one
kono
parents:
diff changeset
1270 -- run_path_option should be
kono
parents:
diff changeset
1271 -- specified.
kono
parents:
diff changeset
1272
kono
parents:
diff changeset
1273 Run_Path_Opt_Index := J;
kono
parents:
diff changeset
1274 exit;
kono
parents:
diff changeset
1275 end if;
kono
parents:
diff changeset
1276 end loop;
kono
parents:
diff changeset
1277
kono
parents:
diff changeset
1278 -- If there is no run_path_option, we
kono
parents:
diff changeset
1279 -- need to add one.
kono
parents:
diff changeset
1280
kono
parents:
diff changeset
1281 if Run_Path_Opt_Index = 0 then
kono
parents:
diff changeset
1282 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1283 end if;
kono
parents:
diff changeset
1284
kono
parents:
diff changeset
1285 if GCC_Index = 0 then
kono
parents:
diff changeset
1286 if Run_Path_Opt_Index = 0 then
kono
parents:
diff changeset
1287 Linker_Options.Table
kono
parents:
diff changeset
1288 (Linker_Options.Last) :=
kono
parents:
diff changeset
1289 new String'
kono
parents:
diff changeset
1290 (Run_Path_Opt
kono
parents:
diff changeset
1291 & File_Path
kono
parents:
diff changeset
1292 (1 .. File_Path'Length
kono
parents:
diff changeset
1293 - File_Name'Length));
kono
parents:
diff changeset
1294
kono
parents:
diff changeset
1295 else
kono
parents:
diff changeset
1296 Linker_Options.Table
kono
parents:
diff changeset
1297 (Run_Path_Opt_Index) :=
kono
parents:
diff changeset
1298 new String'
kono
parents:
diff changeset
1299 (Linker_Options.Table
kono
parents:
diff changeset
1300 (Run_Path_Opt_Index).all
kono
parents:
diff changeset
1301 & Path_Separator
kono
parents:
diff changeset
1302 & File_Path
kono
parents:
diff changeset
1303 (1 .. File_Path'Length
kono
parents:
diff changeset
1304 - File_Name'Length));
kono
parents:
diff changeset
1305 end if;
kono
parents:
diff changeset
1306
kono
parents:
diff changeset
1307 else
kono
parents:
diff changeset
1308 if Run_Path_Opt_Index = 0 then
kono
parents:
diff changeset
1309 Linker_Options.Table
kono
parents:
diff changeset
1310 (Linker_Options.Last) :=
kono
parents:
diff changeset
1311 new String'
kono
parents:
diff changeset
1312 (Run_Path_Opt
kono
parents:
diff changeset
1313 & File_Path
kono
parents:
diff changeset
1314 (1 .. File_Path'Length
kono
parents:
diff changeset
1315 - File_Name'Length)
kono
parents:
diff changeset
1316 & Path_Separator
kono
parents:
diff changeset
1317 & Path (1 .. GCC_Index));
kono
parents:
diff changeset
1318
kono
parents:
diff changeset
1319 else
kono
parents:
diff changeset
1320 Linker_Options.Table
kono
parents:
diff changeset
1321 (Run_Path_Opt_Index) :=
kono
parents:
diff changeset
1322 new String'
kono
parents:
diff changeset
1323 (Linker_Options.Table
kono
parents:
diff changeset
1324 (Run_Path_Opt_Index).all
kono
parents:
diff changeset
1325 & Path_Separator
kono
parents:
diff changeset
1326 & File_Path
kono
parents:
diff changeset
1327 (1 .. File_Path'Length
kono
parents:
diff changeset
1328 - File_Name'Length)
kono
parents:
diff changeset
1329 & Path_Separator
kono
parents:
diff changeset
1330 & Path (1 .. GCC_Index));
kono
parents:
diff changeset
1331 end if;
kono
parents:
diff changeset
1332 end if;
kono
parents:
diff changeset
1333 end if;
kono
parents:
diff changeset
1334 end;
kono
parents:
diff changeset
1335 end if;
kono
parents:
diff changeset
1336 end if;
kono
parents:
diff changeset
1337
kono
parents:
diff changeset
1338 -- Then we add the appropriate -l switch
kono
parents:
diff changeset
1339
kono
parents:
diff changeset
1340 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1341 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
1342 new String'(Next_Line (Nfirst .. Nlast));
kono
parents:
diff changeset
1343 end if;
kono
parents:
diff changeset
1344
kono
parents:
diff changeset
1345 else
kono
parents:
diff changeset
1346 -- If gnatlib library not found, then add it anyway in
kono
parents:
diff changeset
1347 -- case some other mechanism may find it.
kono
parents:
diff changeset
1348
kono
parents:
diff changeset
1349 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1350 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
1351 new String'(Next_Line (Nfirst .. Nlast));
kono
parents:
diff changeset
1352 end if;
kono
parents:
diff changeset
1353 end;
kono
parents:
diff changeset
1354 else
kono
parents:
diff changeset
1355 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1356 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
1357 new String'(Next_Line (Nfirst .. Nlast));
kono
parents:
diff changeset
1358 end if;
kono
parents:
diff changeset
1359 end if;
kono
parents:
diff changeset
1360
kono
parents:
diff changeset
1361 Xlinker_Was_Previous := Next_Line (Nfirst .. Nlast) = "-Xlinker";
kono
parents:
diff changeset
1362
kono
parents:
diff changeset
1363 Get_Next_Line;
kono
parents:
diff changeset
1364 exit when Next_Line (Nfirst .. Nlast) = End_Info;
kono
parents:
diff changeset
1365
kono
parents:
diff changeset
1366 Next_Line (Nfirst .. Nlast - 8) := Next_Line (Nfirst + 8 .. Nlast);
kono
parents:
diff changeset
1367 Nlast := Nlast - 8;
kono
parents:
diff changeset
1368 end loop;
kono
parents:
diff changeset
1369 end if;
kono
parents:
diff changeset
1370
kono
parents:
diff changeset
1371 -- If -shared was specified, invoke gcc with -shared-libgcc
kono
parents:
diff changeset
1372
kono
parents:
diff changeset
1373 if GNAT_Shared then
kono
parents:
diff changeset
1374 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1375 Linker_Options.Table (Linker_Options.Last) := Shared_Libgcc;
kono
parents:
diff changeset
1376 end if;
kono
parents:
diff changeset
1377
kono
parents:
diff changeset
1378 Status := fclose (Fd);
kono
parents:
diff changeset
1379 end Process_Binder_File;
kono
parents:
diff changeset
1380
kono
parents:
diff changeset
1381 -----------
kono
parents:
diff changeset
1382 -- Usage --
kono
parents:
diff changeset
1383 -----------
kono
parents:
diff changeset
1384
kono
parents:
diff changeset
1385 procedure Usage is
kono
parents:
diff changeset
1386 begin
kono
parents:
diff changeset
1387 Write_Str ("Usage: ");
kono
parents:
diff changeset
1388 Write_Str (Base_Command_Name.all);
kono
parents:
diff changeset
1389 Write_Str (" switches mainprog.ali [non-Ada-objects] [linker-options]");
kono
parents:
diff changeset
1390 Write_Eol;
kono
parents:
diff changeset
1391 Write_Eol;
kono
parents:
diff changeset
1392 Write_Line (" mainprog.ali the ALI file of the main program");
kono
parents:
diff changeset
1393 Write_Eol;
kono
parents:
diff changeset
1394 Write_Eol;
kono
parents:
diff changeset
1395 Display_Usage_Version_And_Help;
kono
parents:
diff changeset
1396 Write_Line (" -f Force object file list to be generated");
kono
parents:
diff changeset
1397 Write_Line (" -g Compile binder source file with debug information");
kono
parents:
diff changeset
1398 Write_Line (" -n Do not compile the binder source file");
kono
parents:
diff changeset
1399 Write_Line (" -P Process files for use by CodePeer");
kono
parents:
diff changeset
1400 Write_Line (" -R Do not use a run_path_option");
kono
parents:
diff changeset
1401 Write_Line (" -v Verbose mode");
kono
parents:
diff changeset
1402 Write_Line (" -v -v Very verbose mode");
kono
parents:
diff changeset
1403 Write_Eol;
kono
parents:
diff changeset
1404 Write_Line (" -o nam Use 'nam' as the name of the executable");
kono
parents:
diff changeset
1405 Write_Line (" -Bdir Load compiler executables from dir");
kono
parents:
diff changeset
1406
kono
parents:
diff changeset
1407 if Is_Supported (Map_File) then
kono
parents:
diff changeset
1408 Write_Line (" -Mmap Create map file map");
kono
parents:
diff changeset
1409 Write_Line (" -M Create map file mainprog.map");
kono
parents:
diff changeset
1410 end if;
kono
parents:
diff changeset
1411
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1412 Write_Line (" --GCC=comp Use 'comp' as the compiler rather than 'gcc'");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1413 Write_Line (" --LINK=lnk Use 'lnk' as the linker rather than 'gcc'");
111
kono
parents:
diff changeset
1414 Write_Eol;
kono
parents:
diff changeset
1415 Write_Line (" [non-Ada-objects] list of non Ada object files");
kono
parents:
diff changeset
1416 Write_Line (" [linker-options] other options for the linker");
kono
parents:
diff changeset
1417 end Usage;
kono
parents:
diff changeset
1418
kono
parents:
diff changeset
1419 ------------------
kono
parents:
diff changeset
1420 -- Write_Header --
kono
parents:
diff changeset
1421 ------------------
kono
parents:
diff changeset
1422
kono
parents:
diff changeset
1423 procedure Write_Header is
kono
parents:
diff changeset
1424 begin
kono
parents:
diff changeset
1425 if Verbose_Mode then
kono
parents:
diff changeset
1426 Write_Eol;
kono
parents:
diff changeset
1427 Display_Version ("GNATLINK", "1995");
kono
parents:
diff changeset
1428 end if;
kono
parents:
diff changeset
1429 end Write_Header;
kono
parents:
diff changeset
1430
kono
parents:
diff changeset
1431 -----------------
kono
parents:
diff changeset
1432 -- Write_Usage --
kono
parents:
diff changeset
1433 -----------------
kono
parents:
diff changeset
1434
kono
parents:
diff changeset
1435 procedure Write_Usage is
kono
parents:
diff changeset
1436 begin
kono
parents:
diff changeset
1437 Write_Header;
kono
parents:
diff changeset
1438 Usage;
kono
parents:
diff changeset
1439 end Write_Usage;
kono
parents:
diff changeset
1440
kono
parents:
diff changeset
1441 -- Start of processing for Gnatlink
kono
parents:
diff changeset
1442
kono
parents:
diff changeset
1443 begin
kono
parents:
diff changeset
1444 -- Add the directory where gnatlink is invoked in front of the path, if
kono
parents:
diff changeset
1445 -- gnatlink is invoked with directory information.
kono
parents:
diff changeset
1446
kono
parents:
diff changeset
1447 declare
kono
parents:
diff changeset
1448 Command : constant String := Command_Name;
kono
parents:
diff changeset
1449 begin
kono
parents:
diff changeset
1450 for Index in reverse Command'Range loop
kono
parents:
diff changeset
1451 if Command (Index) = Directory_Separator then
kono
parents:
diff changeset
1452 declare
kono
parents:
diff changeset
1453 Absolute_Dir : constant String :=
kono
parents:
diff changeset
1454 Normalize_Pathname
kono
parents:
diff changeset
1455 (Command (Command'First .. Index));
kono
parents:
diff changeset
1456
kono
parents:
diff changeset
1457 PATH : constant String :=
kono
parents:
diff changeset
1458 Absolute_Dir &
kono
parents:
diff changeset
1459 Path_Separator &
kono
parents:
diff changeset
1460 Getenv ("PATH").all;
kono
parents:
diff changeset
1461
kono
parents:
diff changeset
1462 begin
kono
parents:
diff changeset
1463 Setenv ("PATH", PATH);
kono
parents:
diff changeset
1464 end;
kono
parents:
diff changeset
1465
kono
parents:
diff changeset
1466 exit;
kono
parents:
diff changeset
1467 end if;
kono
parents:
diff changeset
1468 end loop;
kono
parents:
diff changeset
1469 end;
kono
parents:
diff changeset
1470
kono
parents:
diff changeset
1471 Base_Command_Name := new String'(Base_Name (Command_Name));
kono
parents:
diff changeset
1472 Process_Args;
kono
parents:
diff changeset
1473
kono
parents:
diff changeset
1474 if Argument_Count = 0
kono
parents:
diff changeset
1475 or else (Verbose_Mode and then Argument_Count = 1)
kono
parents:
diff changeset
1476 then
kono
parents:
diff changeset
1477 Write_Usage;
kono
parents:
diff changeset
1478 Exit_Program (E_Fatal);
kono
parents:
diff changeset
1479 end if;
kono
parents:
diff changeset
1480
kono
parents:
diff changeset
1481 -- Initialize packages to be used
kono
parents:
diff changeset
1482
kono
parents:
diff changeset
1483 Csets.Initialize;
kono
parents:
diff changeset
1484 Snames.Initialize;
kono
parents:
diff changeset
1485
kono
parents:
diff changeset
1486 -- We always compile with -c
kono
parents:
diff changeset
1487
kono
parents:
diff changeset
1488 Binder_Options_From_ALI.Increment_Last;
kono
parents:
diff changeset
1489 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
kono
parents:
diff changeset
1490 new String'("-c");
kono
parents:
diff changeset
1491
kono
parents:
diff changeset
1492 if Ali_File_Name = null then
kono
parents:
diff changeset
1493 Exit_With_Error ("no ali file given for link");
kono
parents:
diff changeset
1494 end if;
kono
parents:
diff changeset
1495
kono
parents:
diff changeset
1496 if not Is_Regular_File (Ali_File_Name.all) then
kono
parents:
diff changeset
1497 Exit_With_Error (Ali_File_Name.all & " not found");
kono
parents:
diff changeset
1498 end if;
kono
parents:
diff changeset
1499
kono
parents:
diff changeset
1500 -- Read the ALI file of the main subprogram if the binder generated file
kono
parents:
diff changeset
1501 -- needs to be compiled and no --GCC= switch has been specified. Fetch the
kono
parents:
diff changeset
1502 -- back end switches from this ALI file and use these switches to compile
kono
parents:
diff changeset
1503 -- the binder generated file
kono
parents:
diff changeset
1504
kono
parents:
diff changeset
1505 if Compile_Bind_File and then Standard_Gcc then
kono
parents:
diff changeset
1506 Initialize_ALI;
kono
parents:
diff changeset
1507 Name_Len := Ali_File_Name'Length;
kono
parents:
diff changeset
1508 Name_Buffer (1 .. Name_Len) := Ali_File_Name.all;
kono
parents:
diff changeset
1509
kono
parents:
diff changeset
1510 declare
kono
parents:
diff changeset
1511 use Types;
kono
parents:
diff changeset
1512 F : constant File_Name_Type := Name_Find;
kono
parents:
diff changeset
1513 T : Text_Buffer_Ptr;
kono
parents:
diff changeset
1514 A : ALI_Id;
kono
parents:
diff changeset
1515
kono
parents:
diff changeset
1516 begin
kono
parents:
diff changeset
1517 -- Load the ALI file
kono
parents:
diff changeset
1518
kono
parents:
diff changeset
1519 T := Read_Library_Info (F, True);
kono
parents:
diff changeset
1520
kono
parents:
diff changeset
1521 -- Read it. Note that we ignore errors, since we only want very
kono
parents:
diff changeset
1522 -- limited information from the ali file, and likely a slightly
kono
parents:
diff changeset
1523 -- wrong version will be just fine, though in normal operation
kono
parents:
diff changeset
1524 -- we don't expect this to happen.
kono
parents:
diff changeset
1525
kono
parents:
diff changeset
1526 A := Scan_ALI
kono
parents:
diff changeset
1527 (F,
kono
parents:
diff changeset
1528 T,
kono
parents:
diff changeset
1529 Ignore_ED => False,
kono
parents:
diff changeset
1530 Err => False,
kono
parents:
diff changeset
1531 Ignore_Errors => True);
kono
parents:
diff changeset
1532
kono
parents:
diff changeset
1533 if A /= No_ALI_Id then
kono
parents:
diff changeset
1534 for
kono
parents:
diff changeset
1535 Index in Units.Table (ALIs.Table (A).First_Unit).First_Arg ..
kono
parents:
diff changeset
1536 Units.Table (ALIs.Table (A).First_Unit).Last_Arg
kono
parents:
diff changeset
1537 loop
kono
parents:
diff changeset
1538 -- Do not compile with the front end switches. However, --RTS
kono
parents:
diff changeset
1539 -- is to be dealt with specially because it needs to be passed
kono
parents:
diff changeset
1540 -- to compile the file generated by the binder.
kono
parents:
diff changeset
1541
kono
parents:
diff changeset
1542 declare
kono
parents:
diff changeset
1543 Arg : String_Ptr renames Args.Table (Index);
kono
parents:
diff changeset
1544 begin
kono
parents:
diff changeset
1545 if not Is_Front_End_Switch (Arg.all) then
kono
parents:
diff changeset
1546 Binder_Options_From_ALI.Increment_Last;
kono
parents:
diff changeset
1547 Binder_Options_From_ALI.Table
kono
parents:
diff changeset
1548 (Binder_Options_From_ALI.Last) := String_Access (Arg);
kono
parents:
diff changeset
1549
kono
parents:
diff changeset
1550 -- GNAT doesn't support GCC's multilib mechanism when it
kono
parents:
diff changeset
1551 -- is configured with --disable-libada. This means that,
kono
parents:
diff changeset
1552 -- when a multilib switch is used to request a particular
kono
parents:
diff changeset
1553 -- compilation mode, the corresponding --RTS switch must
kono
parents:
diff changeset
1554 -- also be specified. It is convenient to eliminate the
kono
parents:
diff changeset
1555 -- redundancy by keying the compilation mode on a single
kono
parents:
diff changeset
1556 -- switch, namely --RTS, and have the compiler reinstate
kono
parents:
diff changeset
1557 -- the multilib switch (see gcc-interface/lang-specs.h).
kono
parents:
diff changeset
1558 -- This switch must be passed to the driver at link time.
kono
parents:
diff changeset
1559
kono
parents:
diff changeset
1560 if Arg'Length = 5
kono
parents:
diff changeset
1561 and then Arg (Arg'First + 1 .. Arg'First + 4) = "mrtp"
kono
parents:
diff changeset
1562 then
kono
parents:
diff changeset
1563 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1564 Linker_Options.Table
kono
parents:
diff changeset
1565 (Linker_Options.Last) := String_Access (Arg);
kono
parents:
diff changeset
1566 end if;
kono
parents:
diff changeset
1567
kono
parents:
diff changeset
1568 elsif Arg'Length > 5
kono
parents:
diff changeset
1569 and then Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
kono
parents:
diff changeset
1570 then
kono
parents:
diff changeset
1571 Binder_Options_From_ALI.Increment_Last;
kono
parents:
diff changeset
1572 Binder_Options_From_ALI.Table
kono
parents:
diff changeset
1573 (Binder_Options_From_ALI.Last) := String_Access (Arg);
kono
parents:
diff changeset
1574
kono
parents:
diff changeset
1575 -- Set the RTS_*_Path_Name variables, so that
kono
parents:
diff changeset
1576 -- the correct directories will be set when
kono
parents:
diff changeset
1577 -- Osint.Add_Default_Search_Dirs will be called later.
kono
parents:
diff changeset
1578
kono
parents:
diff changeset
1579 Opt.RTS_Src_Path_Name :=
kono
parents:
diff changeset
1580 Get_RTS_Search_Dir
kono
parents:
diff changeset
1581 (Arg (Arg'First + 6 .. Arg'Last), Include);
kono
parents:
diff changeset
1582
kono
parents:
diff changeset
1583 Opt.RTS_Lib_Path_Name :=
kono
parents:
diff changeset
1584 Get_RTS_Search_Dir
kono
parents:
diff changeset
1585 (Arg (Arg'First + 6 .. Arg'Last), Objects);
kono
parents:
diff changeset
1586 end if;
kono
parents:
diff changeset
1587 end;
kono
parents:
diff changeset
1588 end loop;
kono
parents:
diff changeset
1589 end if;
kono
parents:
diff changeset
1590 end;
kono
parents:
diff changeset
1591 end if;
kono
parents:
diff changeset
1592
kono
parents:
diff changeset
1593 -- Get target parameters
kono
parents:
diff changeset
1594
kono
parents:
diff changeset
1595 Osint.Add_Default_Search_Dirs;
kono
parents:
diff changeset
1596 Targparm.Get_Target_Parameters;
kono
parents:
diff changeset
1597
kono
parents:
diff changeset
1598 -- Compile the bind file with the following switches:
kono
parents:
diff changeset
1599
kono
parents:
diff changeset
1600 -- -gnatA stops reading gnat.adc, since we don't know what
kono
parents:
diff changeset
1601 -- pragmas would work, and we do not need it anyway.
kono
parents:
diff changeset
1602
kono
parents:
diff changeset
1603 -- -gnatWb allows brackets coding for wide characters
kono
parents:
diff changeset
1604
kono
parents:
diff changeset
1605 -- -gnatiw allows wide characters in identifiers. This is needed
kono
parents:
diff changeset
1606 -- because bindgen uses brackets encoding for all upper
kono
parents:
diff changeset
1607 -- half and wide characters in identifier names.
kono
parents:
diff changeset
1608
kono
parents:
diff changeset
1609 -- In addition, in CodePeer mode compile with -x adascil -gnatcC
kono
parents:
diff changeset
1610
kono
parents:
diff changeset
1611 Binder_Options_From_ALI.Increment_Last;
kono
parents:
diff changeset
1612 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
kono
parents:
diff changeset
1613 new String'("-gnatA");
kono
parents:
diff changeset
1614 Binder_Options_From_ALI.Increment_Last;
kono
parents:
diff changeset
1615 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
kono
parents:
diff changeset
1616 new String'("-gnatWb");
kono
parents:
diff changeset
1617 Binder_Options_From_ALI.Increment_Last;
kono
parents:
diff changeset
1618 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
kono
parents:
diff changeset
1619 new String'("-gnatiw");
kono
parents:
diff changeset
1620
kono
parents:
diff changeset
1621 if Opt.CodePeer_Mode then
kono
parents:
diff changeset
1622 Binder_Options_From_ALI.Increment_Last;
kono
parents:
diff changeset
1623 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
kono
parents:
diff changeset
1624 new String'("-x");
kono
parents:
diff changeset
1625 Binder_Options_From_ALI.Increment_Last;
kono
parents:
diff changeset
1626 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
kono
parents:
diff changeset
1627 new String'("adascil");
kono
parents:
diff changeset
1628 Binder_Options_From_ALI.Increment_Last;
kono
parents:
diff changeset
1629 Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=
kono
parents:
diff changeset
1630 new String'("-gnatcC");
kono
parents:
diff changeset
1631 end if;
kono
parents:
diff changeset
1632
kono
parents:
diff changeset
1633 -- Locate all the necessary programs and verify required files are present
kono
parents:
diff changeset
1634
kono
parents:
diff changeset
1635 Gcc_Path := System.OS_Lib.Locate_Exec_On_Path (Gcc.all);
kono
parents:
diff changeset
1636
kono
parents:
diff changeset
1637 if Gcc_Path = null then
kono
parents:
diff changeset
1638 Exit_With_Error ("Couldn't locate " & Gcc.all);
kono
parents:
diff changeset
1639 end if;
kono
parents:
diff changeset
1640
kono
parents:
diff changeset
1641 if Linker_Path = null then
kono
parents:
diff changeset
1642 Linker_Path := Gcc_Path;
kono
parents:
diff changeset
1643 end if;
kono
parents:
diff changeset
1644
kono
parents:
diff changeset
1645 Write_Header;
kono
parents:
diff changeset
1646
kono
parents:
diff changeset
1647 Target_Debuggable_Suffix := Get_Target_Debuggable_Suffix;
kono
parents:
diff changeset
1648
kono
parents:
diff changeset
1649 -- If no output name specified, then use the base name of .ali file name
kono
parents:
diff changeset
1650
kono
parents:
diff changeset
1651 if Output_File_Name = null then
kono
parents:
diff changeset
1652 Output_File_Name :=
kono
parents:
diff changeset
1653 new String'(Base_Name (Ali_File_Name.all)
kono
parents:
diff changeset
1654 & Target_Debuggable_Suffix.all);
kono
parents:
diff changeset
1655 end if;
kono
parents:
diff changeset
1656
kono
parents:
diff changeset
1657 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1658 Linker_Options.Table (Linker_Options.Last) := new String'("-o");
kono
parents:
diff changeset
1659
kono
parents:
diff changeset
1660 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1661 Linker_Options.Table (Linker_Options.Last) :=
kono
parents:
diff changeset
1662 new String'(Output_File_Name.all);
kono
parents:
diff changeset
1663
kono
parents:
diff changeset
1664 Check_Existing_Executable (Output_File_Name.all);
kono
parents:
diff changeset
1665
kono
parents:
diff changeset
1666 -- Warn if main program is called "test", as that may be a built-in command
kono
parents:
diff changeset
1667 -- on Unix. On non-Unix systems executables have a suffix, so the warning
kono
parents:
diff changeset
1668 -- will not appear. However, do not warn in the case of a cross compiler.
kono
parents:
diff changeset
1669
kono
parents:
diff changeset
1670 -- Assume this is a cross tool if the executable name is not gnatlink.
kono
parents:
diff changeset
1671 -- Note that the executable name is also gnatlink on windows, but in that
kono
parents:
diff changeset
1672 -- case the output file name will be test.exe rather than test.
kono
parents:
diff changeset
1673
kono
parents:
diff changeset
1674 if Base_Command_Name.all = "gnatlink"
kono
parents:
diff changeset
1675 and then Output_File_Name.all = "test"
kono
parents:
diff changeset
1676 then
kono
parents:
diff changeset
1677 Error_Msg ("warning: executable name """ & Output_File_Name.all
kono
parents:
diff changeset
1678 & """ may conflict with shell command");
kono
parents:
diff changeset
1679 end if;
kono
parents:
diff changeset
1680
kono
parents:
diff changeset
1681 -- Special warnings for worrisome file names on windows
kono
parents:
diff changeset
1682
kono
parents:
diff changeset
1683 -- Recent versions of Windows by default cause privilege escalation if an
kono
parents:
diff changeset
1684 -- executable file name contains substrings "install", "setup", "update"
kono
parents:
diff changeset
1685 -- or "patch". A console application will typically fail to load as a
kono
parents:
diff changeset
1686 -- result, so we should warn the user.
kono
parents:
diff changeset
1687
kono
parents:
diff changeset
1688 Bad_File_Names_On_Windows : declare
kono
parents:
diff changeset
1689 FN : String := Output_File_Name.all;
kono
parents:
diff changeset
1690
kono
parents:
diff changeset
1691 procedure Check_File_Name (S : String);
kono
parents:
diff changeset
1692 -- Warn if file name has the substring S
kono
parents:
diff changeset
1693
kono
parents:
diff changeset
1694 procedure Check_File_Name (S : String) is
kono
parents:
diff changeset
1695 begin
kono
parents:
diff changeset
1696 for J in 1 .. FN'Length - (S'Length - 1) loop
kono
parents:
diff changeset
1697 if FN (J .. J + (S'Length - 1)) = S then
kono
parents:
diff changeset
1698 Error_Msg
kono
parents:
diff changeset
1699 ("warning: executable file name """ & Output_File_Name.all
kono
parents:
diff changeset
1700 & """ contains substring """ & S & '"');
kono
parents:
diff changeset
1701 Error_Msg
kono
parents:
diff changeset
1702 ("admin privileges may be required to run this file");
kono
parents:
diff changeset
1703 end if;
kono
parents:
diff changeset
1704 end loop;
kono
parents:
diff changeset
1705 end Check_File_Name;
kono
parents:
diff changeset
1706
kono
parents:
diff changeset
1707 -- Start of processing for Bad_File_Names_On_Windows
kono
parents:
diff changeset
1708
kono
parents:
diff changeset
1709 begin
kono
parents:
diff changeset
1710 for J in FN'Range loop
kono
parents:
diff changeset
1711 FN (J) := Csets.Fold_Lower (FN (J));
kono
parents:
diff changeset
1712 end loop;
kono
parents:
diff changeset
1713
kono
parents:
diff changeset
1714 -- For now we detect Windows by its executable suffix of .exe
kono
parents:
diff changeset
1715
kono
parents:
diff changeset
1716 if Target_Debuggable_Suffix.all = ".exe" then
kono
parents:
diff changeset
1717 Check_File_Name ("install");
kono
parents:
diff changeset
1718 Check_File_Name ("setup");
kono
parents:
diff changeset
1719 Check_File_Name ("update");
kono
parents:
diff changeset
1720 Check_File_Name ("patch");
kono
parents:
diff changeset
1721 end if;
kono
parents:
diff changeset
1722 end Bad_File_Names_On_Windows;
kono
parents:
diff changeset
1723
kono
parents:
diff changeset
1724 -- If -M switch was specified, add the switches to create the map file
kono
parents:
diff changeset
1725
kono
parents:
diff changeset
1726 if Create_Map_File then
kono
parents:
diff changeset
1727 declare
kono
parents:
diff changeset
1728 Map_Name : constant String := Base_Name (Ali_File_Name.all) & ".map";
kono
parents:
diff changeset
1729 Switches : String_List_Access;
kono
parents:
diff changeset
1730
kono
parents:
diff changeset
1731 begin
kono
parents:
diff changeset
1732 Convert (Map_File, Map_Name, Switches);
kono
parents:
diff changeset
1733
kono
parents:
diff changeset
1734 if Switches /= null then
kono
parents:
diff changeset
1735 for J in Switches'Range loop
kono
parents:
diff changeset
1736 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1737 Linker_Options.Table (Linker_Options.Last) := Switches (J);
kono
parents:
diff changeset
1738 end loop;
kono
parents:
diff changeset
1739 end if;
kono
parents:
diff changeset
1740 end;
kono
parents:
diff changeset
1741 end if;
kono
parents:
diff changeset
1742
kono
parents:
diff changeset
1743 -- Perform consistency checks
kono
parents:
diff changeset
1744
kono
parents:
diff changeset
1745 -- Transform the .ali file name into the binder output file name
kono
parents:
diff changeset
1746
kono
parents:
diff changeset
1747 Make_Binder_File_Names : declare
kono
parents:
diff changeset
1748 Fname : constant String := Base_Name (Ali_File_Name.all);
kono
parents:
diff changeset
1749 Fname_Len : Integer := Fname'Length;
kono
parents:
diff changeset
1750
kono
parents:
diff changeset
1751 function Get_Maximum_File_Name_Length return Integer;
kono
parents:
diff changeset
1752 pragma Import (C, Get_Maximum_File_Name_Length,
kono
parents:
diff changeset
1753 "__gnat_get_maximum_file_name_length");
kono
parents:
diff changeset
1754
kono
parents:
diff changeset
1755 Maximum_File_Name_Length : constant Integer :=
kono
parents:
diff changeset
1756 Get_Maximum_File_Name_Length;
kono
parents:
diff changeset
1757
kono
parents:
diff changeset
1758 Bind_File_Prefix : Types.String_Ptr;
kono
parents:
diff changeset
1759 -- Contains prefix used for bind files
kono
parents:
diff changeset
1760
kono
parents:
diff changeset
1761 begin
kono
parents:
diff changeset
1762 -- Set prefix
kono
parents:
diff changeset
1763
kono
parents:
diff changeset
1764 Bind_File_Prefix := new String'("b~");
kono
parents:
diff changeset
1765
kono
parents:
diff changeset
1766 -- If the length of the binder file becomes too long due to
kono
parents:
diff changeset
1767 -- the addition of the "b?" prefix, then truncate it.
kono
parents:
diff changeset
1768
kono
parents:
diff changeset
1769 if Maximum_File_Name_Length > 0 then
kono
parents:
diff changeset
1770 while Fname_Len >
kono
parents:
diff changeset
1771 Maximum_File_Name_Length - Bind_File_Prefix.all'Length
kono
parents:
diff changeset
1772 loop
kono
parents:
diff changeset
1773 Fname_Len := Fname_Len - 1;
kono
parents:
diff changeset
1774 end loop;
kono
parents:
diff changeset
1775 end if;
kono
parents:
diff changeset
1776
kono
parents:
diff changeset
1777 declare
kono
parents:
diff changeset
1778 Fnam : constant String :=
kono
parents:
diff changeset
1779 Bind_File_Prefix.all &
kono
parents:
diff changeset
1780 Fname (Fname'First .. Fname'First + Fname_Len - 1);
kono
parents:
diff changeset
1781
kono
parents:
diff changeset
1782 begin
kono
parents:
diff changeset
1783 Binder_Spec_Src_File := new String'(Fnam & ".ads");
kono
parents:
diff changeset
1784 Binder_Body_Src_File := new String'(Fnam & ".adb");
kono
parents:
diff changeset
1785 Binder_Ali_File := new String'(Fnam & ".ali");
kono
parents:
diff changeset
1786
kono
parents:
diff changeset
1787 Binder_Obj_File := new String'(Fnam & Get_Target_Object_Suffix.all);
kono
parents:
diff changeset
1788 end;
kono
parents:
diff changeset
1789
kono
parents:
diff changeset
1790 if Fname_Len /= Fname'Length then
kono
parents:
diff changeset
1791 Binder_Options.Increment_Last;
kono
parents:
diff changeset
1792 Binder_Options.Table (Binder_Options.Last) := new String'("-o");
kono
parents:
diff changeset
1793 Binder_Options.Increment_Last;
kono
parents:
diff changeset
1794 Binder_Options.Table (Binder_Options.Last) := Binder_Obj_File;
kono
parents:
diff changeset
1795 end if;
kono
parents:
diff changeset
1796 end Make_Binder_File_Names;
kono
parents:
diff changeset
1797
kono
parents:
diff changeset
1798 Process_Binder_File (Binder_Body_Src_File.all & ASCII.NUL);
kono
parents:
diff changeset
1799
kono
parents:
diff changeset
1800 -- Compile the binder file. This is fast, so we always do it, unless
kono
parents:
diff changeset
1801 -- specifically told not to by the -n switch
kono
parents:
diff changeset
1802
kono
parents:
diff changeset
1803 if Compile_Bind_File then
kono
parents:
diff changeset
1804 Bind_Step : declare
kono
parents:
diff changeset
1805 Success : Boolean;
kono
parents:
diff changeset
1806
kono
parents:
diff changeset
1807 Args : Argument_List
kono
parents:
diff changeset
1808 (1 .. Binder_Options_From_ALI.Last + Binder_Options.Last + 1);
kono
parents:
diff changeset
1809
kono
parents:
diff changeset
1810 begin
kono
parents:
diff changeset
1811 for J in 1 .. Binder_Options_From_ALI.Last loop
kono
parents:
diff changeset
1812 Args (J) := Binder_Options_From_ALI.Table (J);
kono
parents:
diff changeset
1813 end loop;
kono
parents:
diff changeset
1814
kono
parents:
diff changeset
1815 for J in 1 .. Binder_Options.Last loop
kono
parents:
diff changeset
1816 Args (Binder_Options_From_ALI.Last + J) :=
kono
parents:
diff changeset
1817 Binder_Options.Table (J);
kono
parents:
diff changeset
1818 end loop;
kono
parents:
diff changeset
1819
kono
parents:
diff changeset
1820 -- Use the full path of the binder generated source, so that it is
kono
parents:
diff changeset
1821 -- guaranteed that the debugger will find this source, even with
kono
parents:
diff changeset
1822 -- STABS.
kono
parents:
diff changeset
1823
kono
parents:
diff changeset
1824 Args (Args'Last) :=
kono
parents:
diff changeset
1825 new String'(Normalize_Pathname (Binder_Body_Src_File.all));
kono
parents:
diff changeset
1826
kono
parents:
diff changeset
1827 if Verbose_Mode then
kono
parents:
diff changeset
1828 Write_Str (Base_Name (Gcc_Path.all));
kono
parents:
diff changeset
1829
kono
parents:
diff changeset
1830 for J in Args'Range loop
kono
parents:
diff changeset
1831 Write_Str (" ");
kono
parents:
diff changeset
1832 Write_Str (Args (J).all);
kono
parents:
diff changeset
1833 end loop;
kono
parents:
diff changeset
1834
kono
parents:
diff changeset
1835 Write_Eol;
kono
parents:
diff changeset
1836 end if;
kono
parents:
diff changeset
1837
kono
parents:
diff changeset
1838 System.OS_Lib.Spawn (Gcc_Path.all, Args, Success);
kono
parents:
diff changeset
1839
kono
parents:
diff changeset
1840 if not Success then
kono
parents:
diff changeset
1841 Exit_Program (E_Fatal);
kono
parents:
diff changeset
1842 end if;
kono
parents:
diff changeset
1843 end Bind_Step;
kono
parents:
diff changeset
1844 end if;
kono
parents:
diff changeset
1845
kono
parents:
diff changeset
1846 -- In CodePeer mode, there's nothing left to do after the binder file has
kono
parents:
diff changeset
1847 -- been compiled.
kono
parents:
diff changeset
1848
kono
parents:
diff changeset
1849 if Opt.CodePeer_Mode then
kono
parents:
diff changeset
1850 if Tname_FD /= Invalid_FD then
kono
parents:
diff changeset
1851 Delete (Tname);
kono
parents:
diff changeset
1852 end if;
kono
parents:
diff changeset
1853
kono
parents:
diff changeset
1854 return;
kono
parents:
diff changeset
1855 end if;
kono
parents:
diff changeset
1856
kono
parents:
diff changeset
1857 -- Now, actually link the program
kono
parents:
diff changeset
1858
kono
parents:
diff changeset
1859 Link_Step : declare
kono
parents:
diff changeset
1860 Num_Args : Natural :=
kono
parents:
diff changeset
1861 (Linker_Options.Last - Linker_Options.First + 1) +
kono
parents:
diff changeset
1862 (Gcc_Linker_Options.Last - Gcc_Linker_Options.First + 1) +
kono
parents:
diff changeset
1863 (Linker_Objects.Last - Linker_Objects.First + 1);
kono
parents:
diff changeset
1864 Stack_Op : Boolean := False;
kono
parents:
diff changeset
1865
kono
parents:
diff changeset
1866 begin
kono
parents:
diff changeset
1867 -- Remove duplicate stack size setting from the Linker_Options table.
kono
parents:
diff changeset
1868 -- The stack setting option "-Xlinker --stack=R,C" can be found
kono
parents:
diff changeset
1869 -- in one line when set by a pragma Linker_Options or in two lines
kono
parents:
diff changeset
1870 -- ("-Xlinker" then "--stack=R,C") when set on the command line. We
kono
parents:
diff changeset
1871 -- also check for the "-Wl,--stack=R" style option.
kono
parents:
diff changeset
1872
kono
parents:
diff changeset
1873 -- We must remove the second stack setting option instance because
kono
parents:
diff changeset
1874 -- the one on the command line will always be the first one. And any
kono
parents:
diff changeset
1875 -- subsequent stack setting option will overwrite the previous one.
kono
parents:
diff changeset
1876 -- This is done especially for GNAT/NT where we set the stack size
kono
parents:
diff changeset
1877 -- for tasking programs by a pragma in the NT specific tasking
kono
parents:
diff changeset
1878 -- package System.Task_Primitives.Operations.
kono
parents:
diff changeset
1879
kono
parents:
diff changeset
1880 -- Note: This is not a FOR loop that runs from Linker_Options.First
kono
parents:
diff changeset
1881 -- to Linker_Options.Last, since operations within the loop can
kono
parents:
diff changeset
1882 -- modify the length of the table.
kono
parents:
diff changeset
1883
kono
parents:
diff changeset
1884 Clean_Link_Option_Set : declare
kono
parents:
diff changeset
1885 J : Natural;
kono
parents:
diff changeset
1886 Shared_Libgcc_Seen : Boolean := False;
kono
parents:
diff changeset
1887
kono
parents:
diff changeset
1888 begin
kono
parents:
diff changeset
1889 J := Linker_Options.First;
kono
parents:
diff changeset
1890 while J <= Linker_Options.Last loop
kono
parents:
diff changeset
1891 if Linker_Options.Table (J).all = "-Xlinker"
kono
parents:
diff changeset
1892 and then J < Linker_Options.Last
kono
parents:
diff changeset
1893 and then Linker_Options.Table (J + 1)'Length > 8
kono
parents:
diff changeset
1894 and then Linker_Options.Table (J + 1) (1 .. 8) = "--stack="
kono
parents:
diff changeset
1895 then
kono
parents:
diff changeset
1896 if Stack_Op then
kono
parents:
diff changeset
1897 Linker_Options.Table (J .. Linker_Options.Last - 2) :=
kono
parents:
diff changeset
1898 Linker_Options.Table (J + 2 .. Linker_Options.Last);
kono
parents:
diff changeset
1899 Linker_Options.Decrement_Last;
kono
parents:
diff changeset
1900 Linker_Options.Decrement_Last;
kono
parents:
diff changeset
1901 Num_Args := Num_Args - 2;
kono
parents:
diff changeset
1902
kono
parents:
diff changeset
1903 else
kono
parents:
diff changeset
1904 Stack_Op := True;
kono
parents:
diff changeset
1905 end if;
kono
parents:
diff changeset
1906 end if;
kono
parents:
diff changeset
1907
kono
parents:
diff changeset
1908 -- Remove duplicate -shared-libgcc switch
kono
parents:
diff changeset
1909
kono
parents:
diff changeset
1910 if Linker_Options.Table (J).all = Shared_Libgcc_String then
kono
parents:
diff changeset
1911 if Shared_Libgcc_Seen then
kono
parents:
diff changeset
1912 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
kono
parents:
diff changeset
1913 Linker_Options.Table (J + 1 .. Linker_Options.Last);
kono
parents:
diff changeset
1914 Linker_Options.Decrement_Last;
kono
parents:
diff changeset
1915 Num_Args := Num_Args - 1;
kono
parents:
diff changeset
1916
kono
parents:
diff changeset
1917 else
kono
parents:
diff changeset
1918 Shared_Libgcc_Seen := True;
kono
parents:
diff changeset
1919 end if;
kono
parents:
diff changeset
1920 end if;
kono
parents:
diff changeset
1921
kono
parents:
diff changeset
1922 -- Here we just check for a canonical form that matches the
kono
parents:
diff changeset
1923 -- pragma Linker_Options set in the NT runtime.
kono
parents:
diff changeset
1924
kono
parents:
diff changeset
1925 if (Linker_Options.Table (J)'Length > 17
kono
parents:
diff changeset
1926 and then Linker_Options.Table (J) (1 .. 17) =
kono
parents:
diff changeset
1927 "-Xlinker --stack=")
kono
parents:
diff changeset
1928 or else
kono
parents:
diff changeset
1929 (Linker_Options.Table (J)'Length > 12
kono
parents:
diff changeset
1930 and then Linker_Options.Table (J) (1 .. 12) =
kono
parents:
diff changeset
1931 "-Wl,--stack=")
kono
parents:
diff changeset
1932 then
kono
parents:
diff changeset
1933 if Stack_Op then
kono
parents:
diff changeset
1934 Linker_Options.Table (J .. Linker_Options.Last - 1) :=
kono
parents:
diff changeset
1935 Linker_Options.Table (J + 1 .. Linker_Options.Last);
kono
parents:
diff changeset
1936 Linker_Options.Decrement_Last;
kono
parents:
diff changeset
1937 Num_Args := Num_Args - 1;
kono
parents:
diff changeset
1938
kono
parents:
diff changeset
1939 else
kono
parents:
diff changeset
1940 Stack_Op := True;
kono
parents:
diff changeset
1941 end if;
kono
parents:
diff changeset
1942 end if;
kono
parents:
diff changeset
1943
kono
parents:
diff changeset
1944 J := J + 1;
kono
parents:
diff changeset
1945 end loop;
kono
parents:
diff changeset
1946
kono
parents:
diff changeset
1947 if Linker_Path = Gcc_Path then
kono
parents:
diff changeset
1948
kono
parents:
diff changeset
1949 -- For systems where the default is to link statically with
kono
parents:
diff changeset
1950 -- libgcc, if gcc is not called with -shared-libgcc, call it
kono
parents:
diff changeset
1951 -- with -static-libgcc, as there are some platforms where one
kono
parents:
diff changeset
1952 -- of these two switches is compulsory to link.
kono
parents:
diff changeset
1953
kono
parents:
diff changeset
1954 if Shared_Libgcc_Default = 'T'
kono
parents:
diff changeset
1955 and then not Shared_Libgcc_Seen
kono
parents:
diff changeset
1956 then
kono
parents:
diff changeset
1957 Linker_Options.Increment_Last;
kono
parents:
diff changeset
1958 Linker_Options.Table (Linker_Options.Last) := Static_Libgcc;
kono
parents:
diff changeset
1959 Num_Args := Num_Args + 1;
kono
parents:
diff changeset
1960 end if;
kono
parents:
diff changeset
1961 end if;
kono
parents:
diff changeset
1962 end Clean_Link_Option_Set;
kono
parents:
diff changeset
1963
kono
parents:
diff changeset
1964 -- Prepare arguments for call to linker
kono
parents:
diff changeset
1965
kono
parents:
diff changeset
1966 Call_Linker : declare
kono
parents:
diff changeset
1967 Success : Boolean;
kono
parents:
diff changeset
1968 Args : Argument_List (1 .. Num_Args + 1);
kono
parents:
diff changeset
1969 Index : Integer := Args'First;
kono
parents:
diff changeset
1970
kono
parents:
diff changeset
1971 begin
kono
parents:
diff changeset
1972 Args (Index) := Binder_Obj_File;
kono
parents:
diff changeset
1973
kono
parents:
diff changeset
1974 -- Add the object files and any -largs libraries
kono
parents:
diff changeset
1975
kono
parents:
diff changeset
1976 for J in Linker_Objects.First .. Linker_Objects.Last loop
kono
parents:
diff changeset
1977 Index := Index + 1;
kono
parents:
diff changeset
1978 Args (Index) := Linker_Objects.Table (J);
kono
parents:
diff changeset
1979 end loop;
kono
parents:
diff changeset
1980
kono
parents:
diff changeset
1981 -- Add the linker options from the binder file
kono
parents:
diff changeset
1982
kono
parents:
diff changeset
1983 for J in Linker_Options.First .. Linker_Options.Last loop
kono
parents:
diff changeset
1984 Index := Index + 1;
kono
parents:
diff changeset
1985 Args (Index) := Linker_Options.Table (J);
kono
parents:
diff changeset
1986 end loop;
kono
parents:
diff changeset
1987
kono
parents:
diff changeset
1988 -- Finally add the libraries from the --GCC= switch
kono
parents:
diff changeset
1989
kono
parents:
diff changeset
1990 for J in Gcc_Linker_Options.First .. Gcc_Linker_Options.Last loop
kono
parents:
diff changeset
1991 Index := Index + 1;
kono
parents:
diff changeset
1992 Args (Index) := Gcc_Linker_Options.Table (J);
kono
parents:
diff changeset
1993 end loop;
kono
parents:
diff changeset
1994
kono
parents:
diff changeset
1995 if Verbose_Mode then
kono
parents:
diff changeset
1996 Write_Str (Linker_Path.all);
kono
parents:
diff changeset
1997
kono
parents:
diff changeset
1998 for J in Args'Range loop
kono
parents:
diff changeset
1999 Write_Str (" ");
kono
parents:
diff changeset
2000 Write_Str (Args (J).all);
kono
parents:
diff changeset
2001 end loop;
kono
parents:
diff changeset
2002
kono
parents:
diff changeset
2003 Write_Eol;
kono
parents:
diff changeset
2004
kono
parents:
diff changeset
2005 -- If we are on very verbose mode (-v -v) and a response file
kono
parents:
diff changeset
2006 -- is used we display its content.
kono
parents:
diff changeset
2007
kono
parents:
diff changeset
2008 if Very_Verbose_Mode and then Tname_FD /= Invalid_FD then
kono
parents:
diff changeset
2009 Write_Eol;
kono
parents:
diff changeset
2010 Write_Str ("Response file (" &
kono
parents:
diff changeset
2011 Tname (Tname'First .. Tname'Last - 1) &
kono
parents:
diff changeset
2012 ") content : ");
kono
parents:
diff changeset
2013 Write_Eol;
kono
parents:
diff changeset
2014
kono
parents:
diff changeset
2015 for J in
kono
parents:
diff changeset
2016 Response_File_Objects.First .. Response_File_Objects.Last
kono
parents:
diff changeset
2017 loop
kono
parents:
diff changeset
2018 Write_Str (Response_File_Objects.Table (J).all);
kono
parents:
diff changeset
2019 Write_Eol;
kono
parents:
diff changeset
2020 end loop;
kono
parents:
diff changeset
2021
kono
parents:
diff changeset
2022 Write_Eol;
kono
parents:
diff changeset
2023 end if;
kono
parents:
diff changeset
2024 end if;
kono
parents:
diff changeset
2025
kono
parents:
diff changeset
2026 System.OS_Lib.Spawn (Linker_Path.all, Args, Success);
kono
parents:
diff changeset
2027
kono
parents:
diff changeset
2028 -- Delete the temporary file used in conjunction with linking if one
kono
parents:
diff changeset
2029 -- was created. See Process_Bind_File for details.
kono
parents:
diff changeset
2030
kono
parents:
diff changeset
2031 if Tname_FD /= Invalid_FD then
kono
parents:
diff changeset
2032 Delete (Tname);
kono
parents:
diff changeset
2033 end if;
kono
parents:
diff changeset
2034
kono
parents:
diff changeset
2035 if not Success then
kono
parents:
diff changeset
2036 Error_Msg ("error when calling " & Linker_Path.all);
kono
parents:
diff changeset
2037 Exit_Program (E_Fatal);
kono
parents:
diff changeset
2038 end if;
kono
parents:
diff changeset
2039 end Call_Linker;
kono
parents:
diff changeset
2040 end Link_Step;
kono
parents:
diff changeset
2041
kono
parents:
diff changeset
2042 -- Only keep the binder output file and it's associated object
kono
parents:
diff changeset
2043 -- file if compiling with the -g option. These files are only
kono
parents:
diff changeset
2044 -- useful if debugging.
kono
parents:
diff changeset
2045
kono
parents:
diff changeset
2046 if not Debug_Flag_Present then
kono
parents:
diff changeset
2047 Delete (Binder_Ali_File.all & ASCII.NUL);
kono
parents:
diff changeset
2048 Delete (Binder_Spec_Src_File.all & ASCII.NUL);
kono
parents:
diff changeset
2049 Delete (Binder_Body_Src_File.all & ASCII.NUL);
kono
parents:
diff changeset
2050 Delete (Binder_Obj_File.all & ASCII.NUL);
kono
parents:
diff changeset
2051 end if;
kono
parents:
diff changeset
2052
kono
parents:
diff changeset
2053 Exit_Program (E_Success);
kono
parents:
diff changeset
2054
kono
parents:
diff changeset
2055 exception
kono
parents:
diff changeset
2056 when X : others =>
kono
parents:
diff changeset
2057 Write_Line (Exception_Information (X));
kono
parents:
diff changeset
2058 Exit_With_Error ("INTERNAL ERROR. Please report");
kono
parents:
diff changeset
2059 end Gnatlink;