From e8f0b7c7460227640c610276e1ca66956b7b070b Mon Sep 17 00:00:00 2001 From: Aleksandra Pasek Date: Fri, 22 Nov 2024 00:21:16 -0500 Subject: [PATCH 1/4] Backport auto-nvdrive source profile changes to 3841-W518-004 Issue: eng/cert/certified-rts#143 --- gen_rts_sources.py | 3 ++- native/__init__.py | 4 +--- support/rts_sources/sources.py | 44 +++++++++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/gen_rts_sources.py b/gen_rts_sources.py index 8242ae31..30a179b8 100755 --- a/gen_rts_sources.py +++ b/gen_rts_sources.py @@ -44,7 +44,8 @@ def main(): '--rts-profile', choices=['light', 'light-tasking', 'embedded', 'cert'], required=True, help='supported profiles') parser.add_argument( - '--source-profile', choices=['bb', 'deos', 'pikeos', 'vx7r2cert', 'qnx'], + '--source-profile', + choices=['bb', 'deos', 'linux', 'pikeos', 'vx7r2cert', 'qnx'], default='bb', help='platform specific source selections') args = parser.parse_args() diff --git a/native/__init__.py b/native/__init__.py index 8470acf2..1e362b86 100644 --- a/native/__init__.py +++ b/native/__init__.py @@ -4,9 +4,7 @@ class Native(DFBBTarget): def __init__(self): super().__init__() - self.add_gnat_sources( - 'src/s-macres__native.adb', - 'src/s-textio__stdio.adb') + self.add_gnat_sources('src/s-macres__native.adb') @property def target(self): diff --git a/support/rts_sources/sources.py b/support/rts_sources/sources.py index 4d489259..a4953346 100644 --- a/support/rts_sources/sources.py +++ b/support/rts_sources/sources.py @@ -229,6 +229,16 @@ 'hie/a-textio__deos.ads', 'hie/a-textio__deos.adb', 'hie/s-macres.ads', ], + 'linux_srcs': [ + 'hie/a-textio.ads', + 'hie/a-textio__libc.adb', + 'hie/g-io__zfp.ads', + 'hie/g-io__zfp.adb', + 'hie/g-io-put.adb', + 'hie/s-macres.ads', + 'hie/s-textio__libc.ads', + 'hie/s-textio__libc.adb', + ], 'pikeos_srcs': [ 'hie/a-textio.ads', 'exit.c', @@ -246,11 +256,15 @@ 'vx_stack_info.c'], 'qnx_srcs': [ 'exit.c', - 'hie/g-io__zfp.ads', 'hie/g-io__zfp.adb', + 'hie/g-io__zfp.ads', + 'hie/g-io__zfp.adb', 'hie/g-io-put.adb', - 'hie/a-textio.ads', 'hie/a-textio__qnx.adb', + 'hie/a-textio.ads', + 'hie/a-textio__qnx.adb', 'hie/s-macres.ads', - 'hie/s-textio__qnx.ads', 'hie/s-textio__qnx.adb'] + 'hie/s-textio__qnx.ads', + 'hie/s-textio__qnx.adb' + ], }, 'common/32': { @@ -282,6 +296,7 @@ 'hie/s-assert__xi.adb', 'hie/s-memory__light.ads'], 'bb_srcs': ['hie/a-elchha__zfp.adb'], + 'linux_srcs': ['hie/a-elchha__zfp.adb'], 'pikeos_srcs': ['hie/a-elchha__zfp.adb'], 'qnx_srcs': [ 'hie/a-elchha__traceback.adb', @@ -307,6 +322,7 @@ 'hie/s-sssita.ads', 'hie/s-sssita.adb'], 'deos_srcs': [ 'hie/s-thread__cert.ads', 'hie/s-thread__cert.adb'], + 'linux_srcs': ['hie/s-sssita.ads', 'hie/s-sssita.adb'], 'pikeos_srcs': [ 'hie/a-textio__pikeos-light.adb', 'hie/s-sssita.ads', 'hie/s-sssita.adb'], @@ -1048,6 +1064,19 @@ 'hie/a-nalofl__light.ads', 'hie/a-nallfl__light.ads', 'libgnat/a-naliop__nolibm.ads'], + 'linux_srcs': [ + 'hie/a-ngelfu__cert.ads', + 'hie/a-ngelfu__cert.adb', + 'hie/a-nlelfu__cert.ads', + 'hie/a-nuelfu__cert.ads', + 'hie/s-gcmain__cert.ads', + 'hie/s-gcmain__cert.adb', + 'hie/a-nllefu__cert.ads', + 'hie/a-nuaufl__light.ads', + 'hie/a-nalofl__light.ads', + 'hie/a-nallfl__light.ads', + 'libgnat/a-naliop.ads', + ], 'pikeos_srcs': [ 'hie/a-ngelfu__ada.ads', 'hie/a-ngelfu__ada.adb', 'hie/a-nlelfu__ada.ads', @@ -1713,15 +1742,18 @@ }, 'gnat/parameters/light-small': { 'conditions': ['RTS_Profile:light', 'Memory_Profile:small'], - 'bb_srcs': ['hie/s-parame__zfp_small.ads'] + 'bb_srcs': ['hie/s-parame__zfp_small.ads'], + 'linux_srcs': ['hie/s-parame__zfp_small.ads'], }, 'gnat/parameters/light-large': { 'conditions': ['RTS_Profile:light', 'Memory_Profile:large'], - 'bb_srcs': ['hie/s-parame__zfp.ads'] + 'bb_srcs': ['hie/s-parame__zfp.ads'], + 'linux_srcs': ['hie/s-parame__zfp.ads'], }, 'gnat/parameters/light-huge': { 'conditions': ['RTS_Profile:light', 'Memory_Profile:huge'], - 'bb_srcs': ['hie/s-parame__zfp_huge.ads'] + 'bb_srcs': ['hie/s-parame__zfp_huge.ads'], + 'linux_srcs': ['hie/s-parame__zfp_huge.ads'], }, # Cert From 988d070d2b163db59600a41dad314ebd914b6a44 Mon Sep 17 00:00:00 2001 From: Aleksandra Pasek Date: Fri, 22 Nov 2024 18:21:23 +0000 Subject: [PATCH 2/4] Split native into separate Linux and Windows targets As part of the backport of auto-nvdrive from wavefront to 3841-W518-004. Issue: eng/cert/certified-rts#143 --- build_rts.py | 19 ++++++++----- {native => linux}/__init__.py | 36 +++++++++++++------------ linux/adaint.c | 44 ++++++++++++++++++++++++++++++ windows/__init__.py | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 24 deletions(-) rename {native => linux}/__init__.py (67%) create mode 100644 linux/adaint.c create mode 100644 windows/__init__.py diff --git a/build_rts.py b/build_rts.py index 5879df00..02b89d1d 100755 --- a/build_rts.py +++ b/build_rts.py @@ -49,7 +49,8 @@ from x86_64 import X8664Generic # native -from native import Aarch64Native, X86Native, X8664Native +from linux import Aarch64Linux, X86Linux, X8664Linux +from windows import X86Windows, X8664Windows # vx7r2cert from vx7r2cert import AArch64Vx7r2Cert, ArmVx7r2Cert, \ @@ -224,12 +225,16 @@ def build_configs(target): elif target == 'x86_64': t = X8664Generic() # native platforms - elif target in ('x86-linux', 'x86-windows'): - t = X86Native() - elif target in ('x86_64-linux', 'x86_64-windows', 'x86_64-windows64'): - t = X8664Native() - elif target in ('aarch64-linux',): - t = Aarch64Native() + elif target == "aarch64-linux": + t = Aarch64Linux() + elif target == "x86-linux": + t = X86Linux() + elif target == "x86_64-linux": + t = X8664Linux() + elif target == "x86-windows": + t = X86Windows() + elif target in ("x86_64-windows", "x86_64-windows64"): + t = X8664Windows() # vx7r2cert elif target == "aarch64-vx7r2cert": t = AArch64Vx7r2Cert() diff --git a/native/__init__.py b/linux/__init__.py similarity index 67% rename from native/__init__.py rename to linux/__init__.py index 1e362b86..968de20c 100644 --- a/native/__init__.py +++ b/linux/__init__.py @@ -1,18 +1,19 @@ from support.bsp_sources.target import DFBBTarget -class Native(DFBBTarget): +class Linux(DFBBTarget): def __init__(self): super().__init__() - self.add_gnat_sources('src/s-macres__native.adb') - - @property - def target(self): - return None + self.add_gnat_sources("src/s-macres__native.adb") + self.add_gnarl_sources("linux/adaint.c") def has_libc(self, profile): return True + @property + def name(self): + return self.target + def dump_runtime_xml(self, rts_name, rts): return ('\n' '\n' @@ -20,24 +21,25 @@ def dump_runtime_xml(self, rts_name, rts): ' \n' '\n') - def amend_rts(self, rts_profile, cfg): - super().amend_rts(rts_profile, cfg) + @property + def is_legacy_format(self): + return True -class X86Native(Native): +class X86Linux(Linux): @property - def name(self): - return 'native-x86' + def target(self): + return "x86-linux" @property def system_ads(self): return {'light': 'system-xi-x86.ads'} -class X8664Native(Native): +class X8664Linux(Linux): @property - def name(self): - return 'native-x86_64' + def target(self): + return "x86_64-linux" @property def is_64bit(self): @@ -48,10 +50,10 @@ def system_ads(self): return {'light': 'system-xi-x86_64.ads'} -class Aarch64Native(Native): +class Aarch64Linux(Linux): @property - def name(self): - return 'native-aarch64' + def target(self): + return "aarch64-linux" @property def is_64bit(self): diff --git a/linux/adaint.c b/linux/adaint.c new file mode 100644 index 00000000..3e431e05 --- /dev/null +++ b/linux/adaint.c @@ -0,0 +1,44 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#include +#include + +void * +__gnat_lwp_self (void) +{ + return (void *) syscall (__NR_gettid); +} + +cpu_set_t * +__gnat_cpu_alloc (size_t count) +{ + return CPU_ALLOC (count); +} + +size_t +__gnat_cpu_alloc_size (size_t count) +{ + return CPU_ALLOC_SIZE (count); +} + +void +__gnat_cpu_free (cpu_set_t *set) +{ + CPU_FREE (set); +} + +void +__gnat_cpu_zero (size_t count, cpu_set_t *set) +{ + CPU_ZERO_S (count, set); +} + +void +__gnat_cpu_set (int cpu, size_t count, cpu_set_t *set) +{ + /* Ada handles CPU numbers starting from 1, while C identifies the first + CPU by a 0, so we need to adjust. */ + CPU_SET_S (cpu - 1, count, set); +} diff --git a/windows/__init__.py b/windows/__init__.py new file mode 100644 index 00000000..4e7ce7a1 --- /dev/null +++ b/windows/__init__.py @@ -0,0 +1,51 @@ +from support.bsp_sources.target import DFBBTarget + + +class Windows(DFBBTarget): + def __init__(self): + super().__init__() + self.add_gnat_sources("src/s-macres__native.adb", "src/s-textio__stdio.adb") + + @property + def name(self): + return self.target + + def has_libc(self, profile): + return True + + def dump_runtime_xml(self, rts_name, rts): + return ( + '\n' + "\n" + " \n" + " \n" + "\n" + ) + + @property + def is_legacy_format(self): + return True + + +class X86Windows(Windows): + @property + def target(self): + return "x86-windows" + + @property + def system_ads(self): + return {"light": "system-native-x86-light.ads"} + + +class X8664Windows(Windows): + @property + def target(self): + return "x86_64-windows" + + @property + def is_64bit(self): + return True + + @property + def system_ads(self): + return {"light": "system-native-x86-light.ads"} From 1d786062a3fd82ac9bb5b9ce371e6ea833b8cc2a Mon Sep 17 00:00:00 2001 From: Johannes Kliemann Date: Mon, 11 Nov 2024 16:15:47 +0100 Subject: [PATCH 3/4] Add -lc and -pthread to shared library builds The option -nostdlib that is used for shared library builds also removes -lc and -pthread. While this does not immediately cause problems when building the shared version of the runtime it won't use the correct symbol versions causing it to use the wrong version of some libc symbols. ref eng/cert/certified-rts#145 --- support/data/target_options.gpr.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/support/data/target_options.gpr.in b/support/data/target_options.gpr.in index 1b29d4ce..0a210760 100644 --- a/support/data/target_options.gpr.in +++ b/support/data/target_options.gpr.in @@ -52,8 +52,9 @@ abstract project Target_Options is -- link against libgnat (itself). -- Since -nostdlib also removes libgcc -- from the linked libraries we have to - -- add -lgcc again. - LOPTIONS := LOPTIONS & ("-nostdlib", "-lgcc"); + -- add -lc and -lgcc again. + -- Also add -pthread in case it is not already included in -lc. + LOPTIONS := LOPTIONS & ("-nostdlib", "-lc", "-lgcc", "-pthread"); end case; -- Concatenate with common flags From 15c2bfd281a33d4f3a9fd29247ab61977c3d8233 Mon Sep 17 00:00:00 2001 From: Johannes Kliemann Date: Wed, 13 Nov 2024 13:09:15 +0100 Subject: [PATCH 4/4] Remove -pthread from shared library build Remove -pthread from the linker options used to build a shared runtime. While this switch may be needed on some systems it is not available on QNX and causes the build to fail there. For future platforms that need this switch a feature to set platform specific linker options will be introduced. ref eng/toolchain/bb-runtimes#106 --- support/data/target_options.gpr.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/support/data/target_options.gpr.in b/support/data/target_options.gpr.in index 0a210760..9acf7fea 100644 --- a/support/data/target_options.gpr.in +++ b/support/data/target_options.gpr.in @@ -53,8 +53,7 @@ abstract project Target_Options is -- Since -nostdlib also removes libgcc -- from the linked libraries we have to -- add -lc and -lgcc again. - -- Also add -pthread in case it is not already included in -lc. - LOPTIONS := LOPTIONS & ("-nostdlib", "-lc", "-lgcc", "-pthread"); + LOPTIONS := LOPTIONS & ("-nostdlib", "-lc", "-lgcc"); end case; -- Concatenate with common flags