[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Library support in gnat-4.6.3?

Svante Signell wrote:
Sorry to bother you but when building gnat-4.6.2-3 building of
libraries was supported. However, when building gnat-4.6.3-2 with
the previous version library support was disabled. Where it that
setting controlled?

In debian/patches/ada-libgnatprj.diff(src/libgnatprj/configure.ac) but
to understand how it works, read on.

The configuration for GNU/Hurd was approximately the same:
ifeq ($(strip $(filter-out %86 gnu%,$(arch) $(osys))),)
  a-intnam.ads<a-intnam-freebsd.ads \
  a-numaux.adb<a-numaux-x86.adb \
  a-numaux.ads<a-numaux-x86.ads \
  s-inmaop.adb<s-inmaop-posix.adb \
  s-intman.adb<s-intman-posix.adb \
  s-osinte.adb<s-osinte-kfreebsd-gnu.adb \
  s-osinte.ads<s-osinte-kfreebsd-gnu.ads \
  s-osprim.adb<s-osprim-posix.adb \
  s-taprop.adb<s-taprop-posix.adb \
  s-taspri.ads<s-taspri-posix-noaltstack.ads \
  s-tpopsp.adb<s-tpopsp-posix-foreign.adb \

    mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb \

These two variables establish a mapping from canonical file names
(left of '<') to actual file names (right of '<'); the actual file
names vary between targets. Here, GNAT knows that the package body
Mlib.Target.Specific, which should normally be in
mlib-tgt-specific.adb, is actually in mlib-tgt-specific-linux.adb.
Both files exist but only one is compiled.

  THREADSLIB = -lpthread
  GNATLIB_SHARED = gnatlib-shared-dual
  GMEM_LIB = gmemlib

mlib-tgt-specific-linux.adb does not specify
Library_Support but mlib-tgt.adb does??
   function Support_For_Libraries_Default return Library_Support is
      return Full;
   end Support_For_Libraries_Default;

and mlib-tgt.adb is the same in both versions!


Start by reading mlib-tgt.ads and mlib-tgt.adb: these provide the spec
and body for the package Mlib.Tgt which is the same across all targets.
You will see that function Mlib.Tgt.Support_For_Libraries uses an
indirection: it calls another function through an access value:

491 	function Support_For_Libraries return Library_Support is
492 	begin
493 	return Support_For_Libraries_Ptr.all;
494 	end Support_For_Libraries;

The access value, Support_For_Libraries_Ptr, is defined in the private
part of the spec in mlib-tgt.ads:

256 	function Support_For_Libraries_Default return Library_Support;
257 	Support_For_Libraries_Ptr : Library_Support_Function :=
258 	Support_For_Libraries_Default'Access;

Now, mlib-tgt.adb also contains a line "with Mlib.Tgt.Specific" which
brings the second package into the picture.  The file
mlib-tgt-specific.adb overrides Mlib.Tgt.Support_For_Libraries_Ptr

29 	package body MLib.Tgt.Specific is
31 	-- By default, libraries are not supported at all
33 	function Support_For_Libraries return Library_Support;
34 	-- Function indicating if libraries are supported
36 	---------------------------
37 	-- Support_For_Libraries --
38 	---------------------------
40 	function Support_For_Libraries return Library_Support is
41 	begin
42 	return None;
43 	end Support_For_Libraries;
45 	begin
46 	Support_For_Libraries_Ptr := Support_For_Libraries'Access;
47 	end MLib.Tgt.Specific;

(the block in lines 45..47 is executed during elaboration of the
program, i.e. before the main procedure starts).  Therefore, by
default, library support is None on all targets.  However, targets that


in their TOOLS_TARGET_PAIRS will not use mlib-tgt-specific.adb but
mlib-tgt-specific-linux.adb instead.  mlib-tgt-specific-linux.adb does
not override Support_For_Libraries_Ptr, therefore Library_Support
returns Full.

Library_Support does not affect the compiler (gnat1) or the compiler
driver (gcc) but only gnatmake and other tools that understand project
files; that is why the filename mapping is in TOOLS_TARGET_PAIRS
(affecting the "tools" like gnatmake) and not in LIBGNAT_TARGET_PAIRS
(affecting libgnat and libgnarl).  In the upstream sources, the
packages Mlib.Tgt and Mlib.Tgt.Specific are statically linked into
gnatmake and TOOLS_TARGET_PAIRS is defined in

In Debian, the packages Mlib.Tgt and Mlib.Tgt.Specific are part of
libgnatprj and are dynamically linked into gnatmake; TOOLS_TARGET_PAIRS
is not defined in gcc/ada/gcc-interface/Makefile.in but in
src/libgnatprj/Makefile.in instead.  src/libgnatprj/Makefile.in is
generated by src/libgnatprj/configure, which is generated by
src/libgnatprj/configure.ac, which is generated by


(I did not invent any of this and it took me quite a few hours to
understand the sources, several years ago.)

Ludovic Brenta.

Reply to: