1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2003-2005 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This is the VMS version of this package
29 with Ada
.Exceptions
; use Ada
.Exceptions
;
30 with Ada
.Sequential_IO
;
31 with Ada
.Text_IO
; use Ada
.Text_IO
;
33 package body Symbols
is
35 Case_Sensitive
: constant String := "case_sensitive=";
36 Symbol_Vector
: constant String := "SYMBOL_VECTOR=(";
37 Equal_Data
: constant String := "=DATA)";
38 Equal_Procedure
: constant String := "=PROCEDURE)";
39 Gsmatch
: constant String := "gsmatch=";
40 Gsmatch_Lequal
: constant String := "gsmatch=lequal,";
42 Symbol_File_Name
: String_Access
:= null;
43 -- Name of the symbol file
45 Sym_Policy
: Policy
:= Autonomous
;
46 -- The symbol policy. Set by Initialize
48 Major_ID
: Integer := 1;
49 -- The Major ID. May be modified by Initialize if Library_Version is
50 -- specified or if it is read from the reference symbol file.
52 Soft_Major_ID
: Boolean := True;
53 -- False if library version is specified in procedure Initialize.
54 -- When True, Major_ID may be modified if found in the reference symbol
57 Minor_ID
: Natural := 0;
58 -- The Minor ID. May be modified if read from the reference symbol file
60 Soft_Minor_ID
: Boolean := True;
61 -- False if symbol policy is Autonomous, if library version is specified
62 -- in procedure Initialize and is not the same as the major ID read from
63 -- the reference symbol file. When True, Minor_ID may be increased in
64 -- Compliant symbol policy.
66 subtype Byte
is Character;
67 -- Object files are stream of bytes, but some of these bytes, those for
68 -- the names of the symbols, are ASCII characters.
70 package Byte_IO
is new Ada
.Sequential_IO
(Byte
);
73 File
: Byte_IO
.File_Type
;
74 -- Each object file is read as a stream of bytes (characters)
76 function Equal
(Left
, Right
: Symbol_Data
) return Boolean;
77 -- Test for equality of symbols
79 function Image
(N
: Integer) return String;
80 -- Returns the image of N, without the initial space
86 function Equal
(Left
, Right
: Symbol_Data
) return Boolean is
88 return Left
.Name
/= null and then
89 Right
.Name
/= null and then
90 Left
.Name
.all = Right
.Name
.all and then
91 Left
.Kind
= Right
.Kind
and then
92 Left
.Present
= Right
.Present
;
99 function Image
(N
: Integer) return String is
100 Result
: constant String := N
'Img;
102 if Result
(Result
'First) = ' ' then
103 return Result
(Result
'First + 1 .. Result
'Last);
115 (Symbol_File
: String;
117 Symbol_Policy
: Policy
;
120 Success
: out Boolean)
122 File
: Ada
.Text_IO
.File_Type
;
123 Line
: String (1 .. 1_000
);
127 -- Record the symbol file name
129 Symbol_File_Name
:= new String'(Symbol_File);
133 Sym_Policy := Symbol_Policy;
135 -- Record the version (Major ID)
139 Soft_Major_ID := True;
143 Major_ID := Integer'Value (Version);
144 Soft_Major_ID := False;
146 if Major_ID <= 0 then
147 raise Constraint_Error;
151 when Constraint_Error =>
153 Put_Line ("Version """ & Version & """ is illegal.");
154 Put_Line ("On VMS, version must be a positive number");
163 Soft_Minor_ID := Sym_Policy /= Autonomous;
165 -- Empty the symbol tables
167 Symbol_Table.Set_Last (Original_Symbols, 0);
168 Symbol_Table.Set_Last (Complete_Symbols, 0);
170 -- Assume that everything will be fine
174 -- If policy is Compliant or Controlled, attempt to read the reference
175 -- file. If policy is Restricted, attempt to read the symbol file.
177 if Sym_Policy /= Autonomous then
182 when Compliant | Controlled =>
184 Open (File, In_File, Reference);
187 when Ada.Text_IO.Name_Error =>
193 Put_Line ("could not open """ & Reference & """");
194 Put_Line (Exception_Message (X));
203 Open (File, In_File, Symbol_File);
206 when Ada.Text_IO.Name_Error =>
212 Put_Line ("could not open """ & Symbol_File & """");
213 Put_Line (Exception_Message (X));
223 while not End_Of_File (File) loop
224 Get_Line (File, Line, Last);
226 -- Ignore empty lines
231 -- Ignore lines starting with "case_sensitive="
233 elsif Last > Case_Sensitive'Length
234 and then Line (1 .. Case_Sensitive'Length) = Case_Sensitive
238 -- Line starting with "SYMBOL_VECTOR=("
240 elsif Last > Symbol_Vector'Length
241 and then Line (1 .. Symbol_Vector'Length) = Symbol_Vector
244 -- SYMBOL_VECTOR=(<symbol>=DATA)
246 if Last > Symbol_Vector'Length + Equal_Data'Length and then
247 Line (Last - Equal_Data'Length + 1 .. Last) = Equal_Data
249 Symbol_Table.Increment_Last (Original_Symbols);
250 Original_Symbols.Table
251 (Symbol_Table.Last (Original_Symbols)) :=
253 new String'(Line
(Symbol_Vector
'Length + 1 ..
254 Last
- Equal_Data
'Length)),
258 -- SYMBOL_VECTOR=(<symbol>=PROCEDURE)
260 elsif Last
> Symbol_Vector
'Length + Equal_Procedure
'Length
262 Line
(Last
- Equal_Procedure
'Length + 1 .. Last
) =
265 Symbol_Table
.Increment_Last
(Original_Symbols
);
266 Original_Symbols
.Table
267 (Symbol_Table
.Last
(Original_Symbols
)) :=
269 new String'(Line (Symbol_Vector'Length + 1 ..
270 Last - Equal_Procedure'Length)),
274 -- Anything else is incorrectly formatted
278 Put_Line ("symbol file """ & Reference &
279 """ is incorrectly formatted:");
280 Put_Line ("""" & Line (1 .. Last) & """");
288 -- Lines with "gsmatch=lequal," or "gsmatch=equal,"
290 elsif Last > Gsmatch'Length
291 and then Line (1 .. Gsmatch'Length) = Gsmatch
294 Start : Positive := Gsmatch'Length + 1;
295 Finish : Positive := Start;
296 OK : Boolean := True;
300 -- First, look for the first coma
303 if Start >= Last - 1 then
307 elsif Line (Start) = ',' then
318 -- If the comma is found, get the Major and the Minor IDs
322 if Line (Finish) not in '0' .. '9'
323 or else Finish >= Last - 1
329 exit when Line (Finish + 1) = ',';
331 Finish := Finish + 1;
336 ID := Integer'Value (Line (Start .. Finish));
339 -- If Soft_Major_ID is True, it means that
340 -- Library_Version was not specified.
342 if Soft_Major_ID then
345 -- If the Major ID in the reference file is different
346 -- from the Library_Version, then the Minor ID will be 0
347 -- because there is no point in taking the Minor ID in
348 -- the reference file, or incrementing it. So, we set
349 -- Soft_Minor_ID to False, so that we don't modify
350 -- the Minor_ID later.
352 elsif Major_ID /= ID then
353 Soft_Minor_ID := False;
360 if Line (Finish) not in '0' .. '9' then
365 exit when Finish = Last;
367 Finish := Finish + 1;
370 -- Only set Minor_ID if Soft_Minor_ID is True (see above)
372 if OK and then Soft_Minor_ID then
373 Minor_ID := Integer'Value (Line (Start .. Finish));
377 -- If OK is not True, that means the line is not correctly
382 Put_Line ("symbol file """ & Reference &
383 """ is incorrectly formatted");
384 Put_Line ("""" & Line (1 .. Last) & """");
393 -- Anything else is incorrectly formatted
397 Put_Line ("unexpected line in symbol file """ &
399 Put_Line ("""" & Line (1 .. Last) & """");
416 package body Processing is separate;
424 Success : out Boolean)
426 File : Ada.Text_IO.File_Type;
429 S_Data : Symbol_Data;
433 -- Most probable index in the Complete_Symbols of the current symbol
434 -- in Original_Symbol.
439 -- Nothing to be done if Initialize has never been called
441 if Symbol_File_Name = null then
446 -- First find if the symbols in the reference symbol file are also
447 -- in the object files. Note that this is not done if the policy is
448 -- Autonomous, because no reference symbol file has been read.
450 -- Expect the first symbol in the symbol file to also be the first
451 -- in Complete_Symbols.
455 for Index_1 in 1 .. Symbol_Table.Last (Original_Symbols) loop
456 S_Data := Original_Symbols.Table (Index_1);
460 for Index_2 in Cur .. Symbol_Table.Last (Complete_Symbols) loop
461 if Equal (S_Data, Complete_Symbols.Table (Index_2)) then
463 Complete_Symbols.Table (Index_2).Present := False;
465 exit First_Object_Loop;
467 end loop First_Object_Loop;
469 -- If the symbol could not be found between Cur and Last, try
474 for Index_2 in 1 .. Cur - 1 loop
475 if Equal (S_Data, Complete_Symbols.Table (Index_2)) then
477 Complete_Symbols.Table (Index_2).Present := False;
479 exit Second_Object_Loop;
481 end loop Second_Object_Loop;
484 -- If the symbol is not found, mark it as such in the table
487 if (not Quiet) or else Sym_Policy = Controlled then
488 Put_Line ("symbol """ & S_Data.Name.all &
489 """ is no longer present in the object files");
492 if Sym_Policy = Controlled or else Sym_Policy = Restricted then
496 -- Any symbol that is undefined in the reference symbol file
497 -- triggers an increase of the Major ID, because the new
498 -- version of the library is no longer compatible with
499 -- existing executables.
501 elsif Soft_Major_ID then
502 Major_ID := Major_ID + 1;
504 Soft_Major_ID := False;
505 Soft_Minor_ID := False;
508 Original_Symbols.Table (Index_1).Present := False;
509 Free (Original_Symbols.Table (Index_1).Name);
511 if Soft_Minor_ID then
512 Minor_ID := Minor_ID + 1;
513 Soft_Minor_ID := False;
518 if Sym_Policy /= Restricted then
520 -- Append additional symbols, if any, to the Original_Symbols
523 for Index in 1 .. Symbol_Table.Last (Complete_Symbols) loop
524 S_Data := Complete_Symbols.Table (Index);
526 if S_Data.Present then
528 if Sym_Policy = Controlled then
529 Put_Line ("symbol """ & S_Data.Name.all &
530 """ is not in the reference symbol file");
534 elsif Soft_Minor_ID then
535 Minor_ID := Minor_ID + 1;
536 Soft_Minor_ID := False;
539 Symbol_Table.Increment_Last (Original_Symbols);
540 Original_Symbols.Table
541 (Symbol_Table.Last (Original_Symbols)) := S_Data;
542 Complete_Symbols.Table (Index).Present := False;
546 -- Create the symbol file
548 Create (File, Ada.Text_IO.Out_File, Symbol_File_Name.all);
550 Put (File, Case_Sensitive);
551 Put_Line (File, "yes");
553 -- Put a line in the symbol file for each symbol in symbol table
555 for Index in 1 .. Symbol_Table.Last (Original_Symbols) loop
556 if Original_Symbols.Table (Index).Present then
557 Put (File, Symbol_Vector);
558 Put (File, Original_Symbols.Table (Index).Name.all);
560 if Original_Symbols.Table (Index).Kind = Data then
561 Put_Line (File, Equal_Data);
564 Put_Line (File, Equal_Procedure);
567 Free (Original_Symbols.Table (Index).Name);
571 Put (File, Case_Sensitive);
572 Put_Line (File, "NO");
574 -- Put the version IDs
576 Put (File, Gsmatch_Lequal);
577 Put (File, Image (Major_ID));
579 Put_Line (File, Image (Minor_ID));
587 Symbol_Table.Set_Last (Original_Symbols, 0);
588 Symbol_Table.Set_Last (Complete_Symbols, 0);
590 -- Clear the symbol file name
592 Free (Symbol_File_Name);
600 Put_Line ("unexpected exception raised while finalizing """
601 & Symbol_File_Name.all & """");
602 Put_Line (Exception_Information (X));