From cef7137cb0b317744b71a5d12ac5fae592702bb1 Mon Sep 17 00:00:00 2001 From: Sebastian Poeplau Date: Fri, 1 Mar 2024 16:38:02 +0100 Subject: [PATCH 1/2] Use libunwind for exception handling with GNAT-LLVM on ZynqMP The LLVM library libunwind is a replacement for the parts of libgcc that perform stack unwinding and exception propagation. It uses slightly different symbols to locate exception data in memory, which this commit adds to the ZynqMP linker script. We also enable it by default when the runtime is assembled for use with GNAT-LLVM. Issue: eng/toolchain/bb-runtimes#20 --- aarch64/zynqmp/common.ld | 12 +++++++++++- support/bsp_sources/target.py | 2 ++ support/rts_sources/sources.py | 6 ++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/aarch64/zynqmp/common.ld b/aarch64/zynqmp/common.ld index 69a33f4f..74268dbc 100644 --- a/aarch64/zynqmp/common.ld +++ b/aarch64/zynqmp/common.ld @@ -95,7 +95,17 @@ SECTIONS __eh_frame_hdr = .; *(.eh_frame_hdr) } > REGION_CODE - .eh_frame : { KEEP (*(.eh_frame)) } > REGION_CODE + + __eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0; + __eh_frame_hdr_end = SIZEOF(.eh_frame_hdr) > 0 ? . : 0; + + .eh_frame : + { + __eh_frame_start = .; + KEEP (*(.eh_frame)) + __eh_frame_end = .; + } > REGION_CODE + .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) } > REGION_CODE . = ALIGN(0x1000); diff --git a/support/bsp_sources/target.py b/support/bsp_sources/target.py index f83a9026..b250c4e3 100644 --- a/support/bsp_sources/target.py +++ b/support/bsp_sources/target.py @@ -372,6 +372,8 @@ def dump_runtime_xml(self, rts_name, rts): blank + '"-nostartfiles", "-nolibc", ' + '"-Wl,--start-group,-lgnarl,-lgnat,-lc,-lgcc,-lgcc_eh,--end-group",' + if target_compiler() != Compiler.gnat_llvm + else '"-Wl,--start-group,-lgnarl,-lgnat,-lc,-lunwind,--end-group",' ) # Add the user script path first, so that they have precedence diff --git a/support/rts_sources/sources.py b/support/rts_sources/sources.py index 87a5d083..4d9127a7 100644 --- a/support/rts_sources/sources.py +++ b/support/rts_sources/sources.py @@ -1523,9 +1523,11 @@ "srcs": [ "libgnat/s-excmac__gcc.ads", "libgnat/s-excmac__gcc.adb", - "libgcc/unwind-dw2-fde.h", + # TODO + # "libgcc/unwind-dw2-fde.h", ], - "bb_srcs": ["hie/unwind-dw2-fde-bb.c"], + # TODO + # "bb_srcs": ["hie/unwind-dw2-fde-bb.c"], }, "full/zcx-aarch64": { "conditions": ["RTS_Profile:embedded", "CPU_Family:aarch64"], From eb26a9dfb3acdcee01bded9831657f88be098d79 Mon Sep 17 00:00:00 2001 From: Pat Bernardi Date: Mon, 4 Mar 2024 17:15:12 -0500 Subject: [PATCH 2/2] Add Compiler_Backend scenario Some runtime files depend on the compiler backend used, for example GCC requires us to include gcc specific unwinder code. To allow us to specify code specific to a compiler backend, a new Compiler_Backend scenario is added. Also added a connivence function to tell if we are building for LLVM or not to improve code readability. Issue: eng/toolchain/bb-runtimes#20 --- aarch64/__init__.py | 4 ++-- support/__init__.py | 4 ++++ support/bsp_sources/installer.py | 10 +++------- support/bsp_sources/target.py | 8 ++++---- support/rts_sources/profiles.py | 3 +++ support/rts_sources/sources.py | 14 ++++++++++---- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/aarch64/__init__.py b/aarch64/__init__.py index 3e1ec52f..787bc38b 100644 --- a/aarch64/__init__.py +++ b/aarch64/__init__.py @@ -1,5 +1,5 @@ # BSP support for ARM64 -from support import Compiler, target_compiler +from support import using_llvm_compiler from support.bsp_sources.archsupport import ArchSupport from support.bsp_sources.target import DFBBTarget @@ -117,7 +117,7 @@ def system_ads(self): # GNAT-LLVM can't build the embedded Morello runtime yet, so we exclude it for # the time being. - if target_compiler() != Compiler.gnat_llvm: + if using_llvm_compiler(): result["embedded"] = "system-xi-arm-nxstack-embedded.ads" return result diff --git a/support/__init__.py b/support/__init__.py index 7b4c41b5..9def0ea3 100644 --- a/support/__init__.py +++ b/support/__init__.py @@ -99,3 +99,7 @@ def set_target_compiler(comp): def target_compiler(): return _TARGET_COMPILER + + +def using_llvm_compiler(): + return target_compiler() == Compiler.gnat_llvm diff --git a/support/bsp_sources/installer.py b/support/bsp_sources/installer.py index 70194b71..ad4838ed 100644 --- a/support/bsp_sources/installer.py +++ b/support/bsp_sources/installer.py @@ -1,4 +1,4 @@ -from support import readfile, getdatafilepath, Compiler, target_compiler +from support import readfile, getdatafilepath, using_llvm_compiler from support.bsp_sources.target import Target from support.files_holder import _copy @@ -147,15 +147,11 @@ def _find_rts_sources(self, destination, descriptor): break if ret is None: # gprls did not work, try to find out manually the proper location - compiler_name_pattern = ( - "%s-llvm-gcc" if target_compiler() == Compiler.gnat_llvm else "%s-gcc" - ) + compiler_name_pattern = "%s-llvm-gcc" if using_llvm_compiler() else "%s-gcc" compiler = shutil.which(compiler_name_pattern % self.tgt.target) if compiler is not None: compiler_root = os.path.dirname(os.path.dirname(compiler)) - lib_dir = ( - "gnat-llvm" if target_compiler() == Compiler.gnat_llvm else "gnat" - ) + lib_dir = "gnat-llvm" if using_llvm_compiler() else "gnat" tentative = os.path.join( compiler_root, self.tgt.target, "lib", lib_dir, rts_json_file ) diff --git a/support/bsp_sources/target.py b/support/bsp_sources/target.py index b250c4e3..a87af9f6 100644 --- a/support/bsp_sources/target.py +++ b/support/bsp_sources/target.py @@ -1,7 +1,7 @@ import copy import sys -from support import readfile, is_string, Compiler, target_compiler +from support import readfile, is_string, using_llvm_compiler from support.files_holder import FilesHolder from support.bsp_sources.archsupport import ArchSupport from support.rts_sources.profiles import RTSProfiles @@ -176,7 +176,7 @@ def __init__(self): "c_flags": ["-DIN_RTS", "-Dinhibit_libc", "-DLIGHT_RUNTIME"], } # GNAT-LLVM doesn't support -fcallgraph-info - if target_compiler() != Compiler.gnat_llvm: + if using_llvm_compiler(): self.build_flags["common_flags"].append("-fcallgraph-info=su,da") # Add the following compiler switches to runtime.xml for all targets: @@ -187,7 +187,7 @@ def __init__(self): # a hidden runtime dependency that is considered undesirable by many # of our customers. strlen is particularly problematic, as its not # provided in our light and light-tasking runtimes. - if target_compiler() == Compiler.gnat: + if using_llvm_compiler(): self.global_compiler_switches = ("-fno-tree-loop-distribute-patterns",) else: self.global_compiler_switches = () @@ -372,7 +372,7 @@ def dump_runtime_xml(self, rts_name, rts): blank + '"-nostartfiles", "-nolibc", ' + '"-Wl,--start-group,-lgnarl,-lgnat,-lc,-lgcc,-lgcc_eh,--end-group",' - if target_compiler() != Compiler.gnat_llvm + if using_llvm_compiler() else '"-Wl,--start-group,-lgnarl,-lgnat,-lc,-lunwind,--end-group",' ) diff --git a/support/rts_sources/profiles.py b/support/rts_sources/profiles.py index 8d81a39b..c33aae87 100644 --- a/support/rts_sources/profiles.py +++ b/support/rts_sources/profiles.py @@ -5,6 +5,7 @@ # BSP to actually create a runtime project. import sys +from support import using_llvm_compiler from support.rts_sources import Rule from support.rts_sources.sources import all_scenarios, sources @@ -61,6 +62,8 @@ def light_scenarios(self, profile="light"): """Returns the list of directories contained in a base Light runtime""" ret = {} ret["RTS_Profile"] = profile + ret["Compiler_Backend"] = "llvm" if using_llvm_compiler() else "gcc" + ret["Add_Arith64"] = "yes" ret["Add_Case_Util:yes"] = "yes" ret["Add_Exponent_Float"] = "yes" diff --git a/support/rts_sources/sources.py b/support/rts_sources/sources.py index 4d9127a7..fcd0177f 100644 --- a/support/rts_sources/sources.py +++ b/support/rts_sources/sources.py @@ -26,6 +26,7 @@ all_scenarios = { # Main profile "RTS_Profile": ["light", "light-tasking", "embedded", "cert"], + "Compiler_Backend": ["gcc", "llvm"], # Runtime RTP support "Is_RTP": ["no", "yes"], # CPU architecture @@ -1523,11 +1524,16 @@ "srcs": [ "libgnat/s-excmac__gcc.ads", "libgnat/s-excmac__gcc.adb", - # TODO - # "libgcc/unwind-dw2-fde.h", ], - # TODO - # "bb_srcs": ["hie/unwind-dw2-fde-bb.c"], + }, + "full/zcx-dw2-gcc": { + "conditions": [ + "RTS_Profile:embedded", + "CPU_Family:!arm", + "Compiler_Backend:gcc", + ], + "srcs": ["libgcc/unwind-dw2-fde.h"], + "bb_srcs": ["hie/unwind-dw2-fde-bb.c"], }, "full/zcx-aarch64": { "conditions": ["RTS_Profile:embedded", "CPU_Family:aarch64"],