Skip to content

Commit

Permalink
Add Compiler_Backend scenario
Browse files Browse the repository at this point in the history
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
  • Loading branch information
burratoo committed Mar 5, 2024
1 parent cef7137 commit eb26a9d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions aarch64/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 3 additions & 7 deletions support/bsp_sources/installer.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
)
Expand Down
8 changes: 4 additions & 4 deletions support/bsp_sources/target.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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 = ()
Expand Down Expand Up @@ -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",'
)

Expand Down
3 changes: 3 additions & 0 deletions support/rts_sources/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
14 changes: 10 additions & 4 deletions support/rts_sources/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit eb26a9d

Please sign in to comment.