Porting the GNAT RTS

I decided to split this into it’s own thread.

I’ve just taken a look, it’s changed a lot since I last looked, around gcc-4.x

The Makefile.rtl is back and is now where the target-name<source-name.ad[sb] lists are. It’s also where the filter expressions to determine which target you are building for lives.

So, for a new target, that file is where you add it, and you need to add the relevent runtime source file pairs to build your libgnarl (low level) and libgnat (high level) runtime libs.

Best thing is to find something that is close to what you’re aiming for, copy and modify.

In the version I’m looking at currently, 15.2.0, the first line where the platform specifics start is line 1095 which contains the comment:

# PowerPC VxWorks6 and VxWorks7

Each of these sections contain a filter line with things to filter out of the $(target_cpu) $(target_vendor) $(target_os) variables, the result has all spaces stripped so it can be checked if the result is empty and if it is, a platform match is made.

1 Like

Example:

# x86 Linux
ifeq ($(SELECTED_PAIRS),PAIRS_NONE)
ifeq ($(strip $(filter-out %86 linux%,$(target_cpu) $(target_os))),)

  SELECTED_PAIRS=x86-linux

  LIBGNAT_TARGET_PAIRS = \
  a-intnam.ads<libgnarl/a-intnam__linux.ads \
  a-synbar.adb<libgnarl/a-synbar__posix.adb \
  a-synbar.ads<libgnarl/a-synbar__posix.ads \
  s-inmaop.adb<libgnarl/s-inmaop__posix.adb \
  s-intman.adb<libgnarl/s-intman__posix.adb \
  s-tpopsp.adb<libgnarl/s-tpopsp__tls.adb \
  $(TRASYM_DWARF_UNIX_PAIRS) \
  s-tsmona.adb<libgnat/s-tsmona__linux.adb \
  a-exetim.adb<libgnarl/a-exetim__posix.adb \
  a-exetim.ads<libgnarl/a-exetim__default.ads \
  s-linux.ads<libgnarl/s-linux.ads \
  s-osinte.adb<libgnarl/s-osinte__posix.adb \
  $(ATOMICS_TARGET_PAIRS) \
  system.ads<libgnat/system-linux-x86.ads

  ifeq ($(strip $(MULTISUBDIR)),/64)
    LIBGNAT_TARGET_PAIRS += $(X86_64_TARGET_PAIRS)
    LIBGNAT_TARGET_PAIRS += $(GNATRTL_128BIT_PAIRS)
    EXTRA_GNATRTL_NONTASKING_OBJS += $(GNATRTL_128BIT_OBJS)
  else
    LIBGNAT_TARGET_PAIRS += $(X86_TARGET_PAIRS)
  endif

  LIBGNAT_TARGET_PAIRS += \
  s-mudido.adb<libgnarl/s-mudido__affinity.adb \
  s-osinte.ads<libgnarl/s-osinte__linux.ads \
  s-oslock.ads<libgnat/s-oslock__posix.ads \
  s-osprim.adb<libgnat/s-osprim__posix.adb \
  s-taprop.adb<libgnarl/s-taprop__linux.adb \
  s-tasinf.ads<libgnarl/s-tasinf__linux.ads \
  s-tasinf.adb<libgnarl/s-tasinf__linux.adb \
  s-taspri.ads<libgnarl/s-taspri__posix.ads

  EH_MECHANISM=-gcc
  THREADSLIB = -lpthread -lrt
  EXTRA_GNATRTL_NONTASKING_OBJS += g-sse.o g-ssvety.o
  EXTRA_GNATRTL_NONTASKING_OBJS += $(TRASYM_DWARF_UNIX_OBJS)
  EXTRA_GNATRTL_TASKING_OBJS=s-linux.o a-exetim.o

  TOOLS_TARGET_PAIRS = indepsw.adb<indepsw-gnu.adb

  GNATLIB_SHARED = gnatlib-shared-dual
  MISCLIB = -ldl
  GMEM_LIB = gmemlib
  LIBRARY_VERSION := $(LIB_VERSION)

  GNATLIBCFLAGS_FOR_GCCSJLJ+=-fno-omit-frame-pointer -momit-leaf-frame-pointer
endif
endif

The SELECTED_PAIRS variable is set before the first match of PowerPC mentioned above to PAIRS_NONE, so should always get through this test.

Filter based on anything with 86 and linux in the name. Result should be the empty string.

SELECTED_PAIRS isn’t used anywhere else, except to test and set it inside the matched block. :woman_shrugging:

LIBGNAT_TARGET_PAIRS defines a list of filename pairs in the format of link name<original filename, there is a section somewhere else, the main makefile I think which creates links to these files inside the build directory. This is all using filename trickery to make sure the files match the package names.

EH_MECHANISM defines which exception handling package the runtime is built with, lines 847-850:

# When using the GCC exception handling mechanism, we need to use an
# alternate body for a-exexpr.adb (a-exexpr-gcc.adb)

EH_MECHANISM=

THREADSLIB defines which threading libraries this runtime needs to link against, some of these are empty meaning they have no threading/tasking defined/enabled afaics.

Lines 1065-1069 explain that these objects are for the packages required for each type of runtime:

# Additional object files from Ada sources to be added in libgnat
EXTRA_GNATRTL_NONTASKING_OBJS=

# Additional object files from Ada sources to be added in libgnarl
EXTRA_GNATRTL_TASKING_OBJS=

There are a number of indepsw*.adb files which different implementations, from the spec this is for GNATLINK platform-independent switches.

Lines 863-867 specify that GNATLIB_SHARED must be a target name inside the gcc-interface/Makefile.in:

# Default gnatlib-shared target.
# By default, equivalent to gnatlib.
# Set to gnatlib-shared-default, gnatlib-shared-dual, or a platform specific
# target when supported.
GNATLIB_SHARED = gnatlib

MISCLIB is other libraries to link against.

I’ve no idea what GMEM_LIB is.

LIBRARY_VERSION is retrieved from the gnatvsn.ads packe near the start of Makefile.rtl.

GNATLIBCFLAGS_FOR_GCCSJLJ is explained on lines 852-855:

# Compilation options for the GCC-SJLJ RTS. This may be augmented for
# target specific contexts, e.g. to add -fno-omit-frame-pointer for backtrace
# computations.
GNATLIBCFLAGS_FOR_GCCSJLJ=-fsjlj

This if for exceptions using setjmp/longjmp function calls, not zero cost exceptions.

1 Like

TRASYM_DWARF_UNIX_PAIRS is documented on lines 926-946:

# Implementation of symbolic traceback based on DWARF

TRASYM_DWARF_UNIX_PAIRS = \
  s-trasym.adb<libgnat/s-trasym__dwarf.adb \
  s-mmosin.ads<libgnat/s-mmosin__unix.ads \
  s-mmosin.adb<libgnat/s-mmosin__unix.adb \
  s-mmauni.ads<libgnat/s-mmauni__long.ads

TRASYM_DWARF_MINGW_PAIRS = \
  s-trasym.adb<libgnat/s-trasym__dwarf.adb \
  s-mmosin.ads<libgnat/s-mmosin__mingw.ads \
  s-mmosin.adb<libgnat/s-mmosin__mingw.adb

TRASYM_DWARF_COMMON_OBJS = \
  s-objrea$(objext) \
  s-dwalin$(objext) \
  s-mmap$(objext)   \
  s-mmosin$(objext)

TRASYM_DWARF_UNIX_OBJS = $(TRASYM_DWARF_COMMON_OBJS) s-mmauni$(objext)

TRASYM_DWARF_MINGW_OBJS = $(TRASYM_DWARF_COMMON_OBJS)

ATOMICS_TARGET_PAIRS is defined from lines 886-907:

# On platforms where atomic increment/decrement operations are supported,
# special version of Ada.Strings.Unbounded package can be used.

ATOMICS_TARGET_PAIRS = \
  a-coinho.adb<libgnat/a-coinho__shared.adb \
  a-coinho.ads<libgnat/a-coinho__shared.ads \
  a-stunau.adb<libgnat/a-stunau__shared.adb \
  a-suteio.adb<libgnat/a-suteio__shared.adb \
  a-strunb.ads<libgnat/a-strunb__shared.ads \
  a-strunb.adb<libgnat/a-strunb__shared.adb \
  a-stwiun.adb<libgnat/a-stwiun__shared.adb \
  a-stwiun.ads<libgnat/a-stwiun__shared.ads \
  a-swunau.adb<libgnat/a-swunau__shared.adb \
  a-swuwti.adb<libgnat/a-swuwti__shared.adb \
  a-stzunb.adb<libgnat/a-stzunb__shared.adb \
  a-stzunb.ads<libgnat/a-stzunb__shared.ads \
  a-szunau.adb<libgnat/a-szunau__shared.adb \
  a-szuzti.adb<libgnat/a-szuzti__shared.adb

ATOMICS_BUILTINS_TARGET_PAIRS = \
  s-atocou.adb<libgnat/s-atocou__builtin.adb

Hi Luke,

the Projects category is for the proposal of Ideas/tasks for the Ada Awards. Is this a submission?

Beyond the above, I know what you are talking quite well. These files were my bread and butter when I helped update GNAT in NetBSD. However, after a sparse read of your texts, I miss what you are looking for or what could I help you with :grimacing: Could you be a bit more explicit with the goal?

Best regards,
Fer

Er, no. I just intend to add to to it when I can. Maybe a new category for this kind of stuff should be added then?

This is created from my other thread that I’m waiting on a reply for. The goal is to document porting the runtime, i.e. adding a new runtime target into Makefile.rtl.

It is unclear what you want to achieve. What kind of runtime? For which hardware/software platform? Which features it should have.

Runtime distributed as part of FSF GCC is intended to work on “native” platforms, on regular OS, and supports almost all language features.

Runtimes distbiuted as part of bb-runtimes is another corner case - they are intended to run on bare metal, without any OS at all, and supports limited set of language features.

There are a lot of runtimes between these corner cases…

Just a suggestion/feedback: if the category is indeed for that specific topic, it might be better to use a more specific category name like “Ada Awards” (or however you would handle spaces), just to avoid confusion.

3 Likes