diff --git a/aarch64/__init__.py b/aarch64/__init__.py index 9d3ed6c2..9bb6f891 100644 --- a/aarch64/__init__.py +++ b/aarch64/__init__.py @@ -95,13 +95,19 @@ def amend_rts(self, rts_profile, conf): def dump_runtime_xml(self, rts_name, rts): cnt = super(Aarch64Target, self).dump_runtime_xml(rts_name, rts) if rts_name == "embedded": - cnt = cnt.replace( - '"-nostartfiles"', - ( - '"-u", "_Unwind_Find_FDE", "-Wl,--eh-frame-hdr",\n' - ' "-nostartfiles"' - ), - ) + if using_llvm_compiler(): + cnt = cnt.replace( + '"-nolibc"', + '"-Wl,--eh-frame-hdr", "-nolibc"', + ) + else: + cnt = cnt.replace( + '"-nostartfiles"', + ( + '"-u", "_Unwind_Find_FDE", "-Wl,--eh-frame-hdr",\n' + ' "-nostartfiles"' + ), + ) return cnt @@ -309,3 +315,6 @@ def __init__(self, uart_io): self.add_linker_script("aarch64/morello/common.ld") self.add_linker_script("aarch64/morello/ram.ld", loader="RAM") + + if using_llvm_compiler(): + self.add_linker_switch("-nostartfiles") diff --git a/support/bsp_sources/target.py b/support/bsp_sources/target.py index 12a5c097..2fbb248d 100644 --- a/support/bsp_sources/target.py +++ b/support/bsp_sources/target.py @@ -374,8 +374,13 @@ def dump_runtime_xml(self, rts_name, rts): # For the Light and Light Tasking runtimes we have the choice of # either using libgcc or our Ada libgcc replacement. For the # later choice we do not link with any of the standard libraries. + # + # LLVM doesn't use start files on most bareboard targets, so we + # don't pass "-nostartfiles" to avoid a linker warning. if rts.rts_vars["Certifiable_Packages"] == "yes": ret += blank + '"-nostdlib",' + elif using_llvm_compiler(): + ret += blank + '"-nolibc",' else: ret += blank + '"-nostartfiles", "-nolibc",' else: @@ -385,22 +390,30 @@ def dump_runtime_xml(self, rts_name, rts): # interdependencies between libgnarl and libgnat, so we need to # force -lgnarl at link time, always. # - # We provide the link arguments for libc ourselves. Inhibit the - # gcc mechanism doing so with -nolibc first. Then we need to - # account for intricacies in dependencies, e.g. libc depends on - # libgcc as everyone, libgcc on libc for strlen, libgnat on libc - # for __errno or other, libc on libgnat for sbrk, libgnat and - # libgnarl on each other... - - ret += ( - blank - + '"-nostartfiles", "-nolibc", ' - + ( - '"-Wl,--start-group,-lgnarl,-lgnat,-lc,-lgcc,-lgcc_eh,--end-group",' - if not using_llvm_compiler() - else '"-Wl,--start-group,-lgnarl,-lgnat,-lc,-lunwind,--end-group",' + # With gcc, we provide the link arguments for libc ourselves. + # Inhibit the gcc mechanism doing so with -nolibc first. Then we + # need to account for intricacies in dependencies, e.g. libc + # depends on libgcc as everyone, libgcc on libc for strlen, + # libgnat on libc for __errno or other, libc on libgnat for sbrk, + # libgnat and libgnarl on each other... + # + # The LLVM linker doesn't depend on the order of archive files on + # the command line because it remembers defined symbols in + # addition to undefined symbols when scanning archives (see + # https://lld.llvm.org/NewLLD.html, "Efficient archive file + # handling"). We stills want "-nolibc" because it disables + # automatic linking of libm. + + if not using_llvm_compiler(): + ret += ( + blank + + '"-nostartfiles", "-nolibc", ' + + '"-Wl,--start-group,' + + "-lgnarl,-lgnat,-lc,-lgcc,-lgcc_eh," + + '--end-group",' ) - ) + else: + ret += blank + '"-nolibc", "-lgnarl", "-lgnat", "-lc", "-lunwind",' # Add linker paths (only needed for bare-metal runtimes) if not self.is_os_target: