annotate gcc/ada/gnatlink.adb @ 111:04ced10e8804

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