Skip to content

Commit

Permalink
Merge branch 'mr/fix-linker-warnings-with-lld' into 'master'
Browse files Browse the repository at this point in the history
Fix linker warnings when using lld

See merge request eng/toolchain/bb-runtimes!139
  • Loading branch information
sebastianpoeplau committed Nov 7, 2024
2 parents 0639599 + 89e3acd commit 3f82b97
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
23 changes: 16 additions & 7 deletions aarch64/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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")
43 changes: 28 additions & 15 deletions support/bsp_sources/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 3f82b97

Please sign in to comment.