comparison gcc/ada/vxlink-main.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- V X L I N K . M A I N --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2018, AdaCore --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 -- VxLink is a helper tool used as a wrapper around g++/gcc to build VxWorks
27 -- DKM (Downloadable Kernel Modules).
28 -- Such DKM is a partially linked object that contains entry points for
29 -- constructors and destructors. This tool thus uses g++ to generate an
30 -- intermediate partially linked object, retrieves the list of constructors
31 -- and destructors in it and produces a C file that lists those ctors/dtors
32 -- in a way that is understood be VxWorks kernel. It then links this file
33 -- with the intermediate object to produce a valid DKM.
34
35 pragma Ada_2012;
36
37 with GNAT.OS_Lib; use GNAT.OS_Lib;
38
39 with VxLink.Link; use VxLink.Link;
40 with VxLink.Bind; use VxLink.Bind;
41
42 procedure VxLink.Main is
43 Linker : VxLink_Linker;
44 Binder : VxLink_Binder;
45 VSB_Dir : String_Access := Getenv ("VSB_DIR");
46 begin
47 Initialize (Linker);
48
49 if Is_Error_State then
50 return;
51 end if;
52
53 Do_Initial_Link (Linker);
54
55 if Is_Error_State then
56 return;
57 end if;
58
59 if not Needs_CDtor (Linker) then
60 -- Initial link is enough, let's return
61 return;
62 end if;
63
64 if VSB_Dir /= null and then VSB_Dir'Length > 0 then
65 declare
66 DKM_Tag_File : constant String :=
67 Normalize_Pathname
68 ("krnl/tags/dkm.tags", VSB_Dir.all);
69 begin
70 if Is_Regular_File (DKM_Tag_File) then
71 Parse_Tag_File (Binder, DKM_Tag_File);
72 end if;
73 end;
74 end if;
75
76 Initialize (Binder, Object_File => Partial_Object (Linker));
77 Emit_CTDT (Binder, Namespace => Namespace (Linker));
78
79 Do_Final_Link (Linker, CTDT_File (Binder));
80 Free (VSB_Dir);
81 end VxLink.Main;