Skip to content

[ATfE] Replace call to abort with __llvm_libc_exit in libc startup code#678

Merged
voltur01 merged 1 commit intoarm:arm-softwarefrom
voltur01:remove_abort_redefinition
Jan 19, 2026
Merged

[ATfE] Replace call to abort with __llvm_libc_exit in libc startup code#678
voltur01 merged 1 commit intoarm:arm-softwarefrom
voltur01:remove_abort_redefinition

Conversation

@voltur01
Copy link
Contributor

LLVM libc does not provide a way to redefine abort(), thus the local abort() definition in LLVM libc semihosting has to be removed.

Calls to abort() in LLVM libc crt0 replaced with __llvm_libc_exit() which is the LLVM libc defined platform specific exit handler.

This prevents exception handlers from crashing because of the trap instruction in LLVM libc implementation of abort().

LLVM libc does not provide a way to redefine abort(), thus the local abort() definition in LLVM libc semihosting has to be removed.

Calls to abort() in LLVM libc crt0 replaced with __llvm_libc_exit() which is the LLVM libc defined platform specific exit handler.

This prevents exception handlers from crashing because of the trap instruction in LLVM libc implementation of abort().
@voltur01 voltur01 requested a review from a team as a code owner January 16, 2026 15:56
Copy link
Contributor

@vrukesh vrukesh left a comment

Choose a reason for hiding this comment

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

LGTM

EXFN_ATTR void handle_reset() {
print_str("CPU Exception: Reset\n");
abort();
__llvm_libc_exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

From what I can see, we only have a definition of __llvm_libc_exit() in libsemihosting.a if we make this change then we will require a user of the support code to use -lsemihosting. If it is going to be a usage requirement we should update the user documentation for llvm libc.

I think __llvm_libc_exit() should be defined in libcrt0.a and libcrt0-semihost.a (not sure what libcrt0-none.a is for at the moment). The definition in libcrt0-semihost.a should exit via semihosting and the other definitions should either infinite loop or trap.

Ideally libsemihosting.a should just be an opt in library contain default implementations of the functions needing retargeting to semihosting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now we have at least two symbols required by crt0

#elif __LLVM_LIBC__ // built with llvmlibc

  • _platform_init
  • __llvm_libc_exit
    both are defined by LLVM libc itself so have to be provided by either ATfE startup code or the user code like in the unhosted sample above.

Let me address this as a separate PR to also update the unhosted sample accordingly.

@voltur01 voltur01 merged commit 6859f67 into arm:arm-software Jan 19, 2026
2 checks passed
voltur01 added a commit to voltur01/arm-toolchain that referenced this pull request Jan 21, 2026
…de (arm#678)

LLVM libc does not provide a way to redefine abort(), thus the local
abort() definition in LLVM libc semihosting has to be removed.

Calls to abort() in LLVM libc crt0 replaced with __llvm_libc_exit()
which is the LLVM libc defined platform specific exit handler.

This prevents exception handlers from crashing because of the trap
instruction in LLVM libc implementation of abort().

(cherry picked from commit 6859f67)
voltur01 added a commit that referenced this pull request Jan 22, 2026
This applies the following changes to 22.x release branch:

#667
[ATfE] Use semihosting SYS_READC for stdin with llvm libc

#676
[ATfE] Remove __LLVM_LIBC__ define workaround for libcxx

#678
[ATfE] Replace call to abort with __llvm_libc_exit in libc startup code

#679
[ATfE] Update comment about handling cleanup for exit()

#683
[ATfE] Provide nohost init and exit in llvmlibc startup code
voltur01 added a commit to voltur01/arm-toolchain that referenced this pull request Feb 20, 2026
…de (arm#678)

LLVM libc does not provide a way to redefine abort(), thus the local
abort() definition in LLVM libc semihosting has to be removed.

Calls to abort() in LLVM libc crt0 replaced with __llvm_libc_exit()
which is the LLVM libc defined platform specific exit handler.

This prevents exception handlers from crashing because of the trap
instruction in LLVM libc implementation of abort().
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