Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing GNAT runtime name

Tags:

runtime

ada

I am building my own Ada runtime system.

However, I can only link again the custom runtime if it is called 'gnat' and compiled to 'libgnat.a' If I call it anything else I get the ld error:

/home/mark/opt/GNAT/2021/bin/../libexec/gcc/x86_64-pc-linux-gnu/10.3.1/ld: cannot find -lgnat

Any ideas on how to configure this so I can use a different name?

Here's the project file for the runtime (most of it is from OSdev)

project milo is
   
  for Languages use ("Ada");
  for Runtime ("Ada") use Project'Project_Dir;
  
  for Library_Auto_Init use "False";
  for Library_Name use "milo"; -- that must be "gnat"
  for Library_Kind use "static";

  for Library_Dir use "lib";
  for Object_Dir use "obj";
  for Source_Dirs use ("src/zfp", "src/milo");

   package Builder is
      for Global_Configuration_Pragmas use "milo.adc";
      for Switches ("Ada") use (
        "-nostdlib",
        "-nostdinc"
      );
   end Builder;

  package Compiler is
      for Default_Switches ("Ada") use (
        "-O2",
        "-ffunction-sections", 
        "-fdata-sections",
        "-fcallgraph-info=su,da",
        "-gnatp",
        "-gnatn2",                           
        "-gnat2012",
        "-gnatg",
        "-Wl,--gc-sections",
        "-gnatyN"
      );
   end Compiler;

end milo;

And here's the project that I am trying to use this runtime with

project Helloworld is

   for Source_Dirs use ("src");
   for Object_Dir use "obj";
   for Main use ("helloworld.adb");
   for Runtime ("ada") use "/home/mark/Milo/milo/";

end Helloworld;
like image 396
Mark Avatar asked Sep 02 '25 16:09

Mark


1 Answers

See here for an example of a runtime whose name is stm32f4, for the Cortex M4F-based STM32F4 MCU from STMicroelectronics.

To be a runtime called milo, the structure has to be at least

$prefix/milo/adainclude
            |
            /adalib

where adainclude/ holds the source files and adalib/ holds the .ali files and the library (usually libgnat.a, because it's hidden from users).

If that's all, then GNAT will be happy with gprbuild --RTS=$prefix/milo. But in may cases you'll want to alter how the compiler deals with Ada options and the linker commands. This is the job of the file runtime.xml, which is a gprbuild configuration file.

In package Compiler, see

      Common_Required_Switches :=
         ("-mlittle-endian", "-mhard-float",
          "-mcpu=cortex-m4", "-mfpu=fpv4-sp-d16", "-mthumb");

for switches appropriate for the target processor which will be applied to every compilation using this runtime (you might say, what about -ffunction-sections and -fdata-sections, and I wouldn't have a good answer for you!)

In package Linker, see

      for Required_Switches use Linker'Required_Switches &
        ("${RUNTIME_DIR(ada)}/adalib/libgnat.a") &
        Compiler.Common_Required_Switches &
        ("-nostdlib", "-lm", "-lgcc", "-lc");

      for Required_Switches use Linker'Required_Switches &
        ("-T", "${RUNTIME_DIR(ada)}/adalib/stm32f407-flash.ld");

of which the first part tells the linker to use $prefix/milo/adalib/libgnat.a, and the second (which could have been concatenated with the first, now I come to look at it) tells the linker script to use instead of the one baked into the compiler.

I think a useul addition here would be --gc-sections.

The &s are there because this is an XML file, and & needs escaping.

like image 85
Simon Wright Avatar answered Sep 07 '25 02:09

Simon Wright