Skip to content

[ATfE] Provide LLVM libc handlers for hardware setup#706

Merged
voltur01 merged 5 commits intoarm:arm-softwarefrom
voltur01:add_libc_hw_handlers
Feb 6, 2026
Merged

[ATfE] Provide LLVM libc handlers for hardware setup#706
voltur01 merged 5 commits intoarm:arm-softwarefrom
voltur01:add_libc_hw_handlers

Conversation

@voltur01
Copy link
Contributor

Add handlers in LLVM libc startup code that can be overridden by the user to customize hardware setup, e.g. provide a custom exceptions table or such.

Add handlers in LLVM libc startup code that can be overridden by the user to customize hardware setup, e.g. provide a custom exceptions table or such.
@voltur01 voltur01 requested a review from a team as a code owner January 30, 2026 16:46
Initialization of caches moved into the memory initialization handler to keep it in one place and make it easier to explain and override by a user.
Copy link
Contributor

@vhscampos vhscampos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but wait for an additional approval.

@voltur01
Copy link
Contributor Author

voltur01 commented Feb 2, 2026

Thank you for the review!

smithp35
smithp35 previously approved these changes Feb 2, 2026
Copy link
Contributor

@smithp35 smithp35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's scope to go a bit further, for example I think we could add more extensive pre and post conditions, but that could be done in a follow up patch.

It may also be worthwhile to have one overridable function per object file. This is a bit more size efficient if garbage collection is not enabled. Again possibilities for a follow up patch.

misc::setup();
_platform_setup_exceptions();
_platform_setup_memory();
_platform_setup_arch_extensions();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend extracting the memcpy and memset below the // Perform the equivalent of scatterloading into a separate function.

That would allow someone to use a different linker script with different RW and .bss.

Perhaps:
// Perform linkerscript specific tasks such as copying RW data from Flash to RAM, and zero initializing .bss. The default implementation assumes one RW data region and one .bss region, described by the following linker defined symbols:

  • __data_source ; the load address of the start of the RW in Flash.
  • __data_start ; the destination address of the start of the RW in RAM.
  • __data_size ; the size of the RW.
  • __bss_start ; the address of the start of .bss in RAM.
  • __bss_size ; the size of the .bss.

extern "C" [[gnu::weak]] void _platform_linkerscript_init();


When llvm-libc supports TLS the function would be a good place to setup the thread pointer for the "main" thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good suggestion to address this here as well, thanks - let me add one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a dedicated handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split the code into multiple cpp files, a lot of changes, but mostly moving things around.

Split the monolithic bootcode.cpp into smaller object files to allow the linker discarding code related to overridden customization handlers to save a bit of application binary size.
smithp35
smithp35 previously approved these changes Feb 6, 2026
Copy link
Contributor

@smithp35 smithp35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One copyright message using 2025 when all others use 2026. Otherwise LGTM.

@@ -0,0 +1,19 @@
//
// Copyright (c) 2025, Arm Limited and affiliates.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2026

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot - fixed!

Copy link
Contributor

@smithp35 smithp35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks.

@voltur01
Copy link
Contributor Author

voltur01 commented Feb 6, 2026

Thank you for reviews and good ideas!

@voltur01 voltur01 merged commit bc8a58b into arm:arm-software Feb 6, 2026
2 checks passed
voltur01 added a commit to voltur01/arm-toolchain that referenced this pull request Feb 20, 2026
…#706)

Add handlers in LLVM libc startup code that can be overridden by the
user to customize hardware and runtime setup, e.g. provide a custom
exceptions table or such.
voltur01 added a commit that referenced this pull request Feb 20, 2026
This cherry-picks changes relevant to llvmlibc-support from current
arm-software into the 22.x release branch:

12a4f2c [ATfE] Document _platform_debug_putc() (#723)
75faad2 [ATfE] Support command line options in LLVM libc (#705)
2ae2b6c [ATfE] Fix libc v7-R no-fpregs attribute build failure
(#720)
bc8a58b [ATfE] Provide LLVM libc handlers for hardware and runtime
setup (#706)
852e751 [ATfE] Provide debug output handler in LLVM libc crt0
9be5d72 (origin/add_unhosted_exit, add_unhosted_exit) Simplified
implementation of exit to avoid issues with privileged assembly
instructions
983f37c [ATfE] Provide nohost init and exit in llvmlibc startup
code
6859f67 [ATfE] Replace call to abort with __llvm_libc_exit in libc
startup code (#678)
a284205 (origin/update_exit_comment, update_exit_comment) [ATfE]
Update comment about handling cleanup for exit()
fb865b8 (origin/remove_abort_redefinition,
remove_abort_redefinition) [ATfE] Replace call to abort with
__llvm_libc_exit in libc startup code
28c43df (origin/use_sys_readc_for_stdin) Merge branch
'arm-software' into use_sys_readc_for_stdin
53e062f (use_sys_readc_for_stdin) Added a comment with rationale
and TODO
bbf19b6 (origin/add_semihosting_abort, add_semihosting_abort) Mark
internal semihosting function as static
52d1d90 Provide semihosting_call_exit() and add TODO for exit()
99c608d Replace exit() with direct call to __llvm_libc_exit()
07fe14b [ATfE] Use semihosting SYS_READC for stdin with llvm libc
ab08655 [ATfE] Redirect libc abort() to semihosting exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants