[ATfE] Replace call to abort with __llvm_libc_exit in libc startup code#678
Conversation
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().
| EXFN_ATTR void handle_reset() { | ||
| print_str("CPU Exception: Reset\n"); | ||
| abort(); | ||
| __llvm_libc_exit(1); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Now we have at least two symbols required by crt0
_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.
…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)
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
…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().
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()
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().