fix(esp32c3): use semihosting _exit for QEMU emulator support#1539
fix(esp32c3): use semihosting _exit for QEMU emulator support#1539luoliwoshang wants to merge 3 commits intogoplus:mainfrom
Conversation
Summary of ChangesHello @luoliwoshang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where the ESP32-C3 QEMU emulator was not correctly utilizing the semihosting Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses the conflicting _exit symbol implementations for ESP32-C3 QEMU support by commenting out the stub versions from the build configuration. The changes are logical and well-explained in the description. I've added one comment regarding code duplication in the file list, which could be addressed to improve maintainability.
Code Review SummaryThe PR correctly addresses the immediate issue of conflicting Critical Issues Found:
Recommendation:
See inline comments for specific details. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1539 +/- ##
==========================================
- Coverage 91.06% 91.05% -0.01%
==========================================
Files 45 45
Lines 11938 11933 -5
==========================================
- Hits 10871 10866 -5
Misses 892 892
Partials 175 175 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Move _exit implementation from syscalls.c to syscalls_exit.c to allow easy replacement with semihosting version for QEMU emulator support. This separation enables llgo to compile the semihosting _exit as a separate object file that can override the default implementation when building for QEMU targets. Related to: goplus/llgo#1539 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3f1b5c7 to
ce7bca1
Compare
Move _exit implementation from syscalls.c to syscalls_exit.c to allow easy replacement with semihosting version for QEMU emulator support. This separation enables llgo to compile the semihosting _exit as a separate object file that can override the default implementation when building for QEMU targets. Related to: goplus/llgo#1539 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
487d0dd to
22bc753
Compare
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_close.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_exit.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_fdtable.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_fstat.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_ftime.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_isatty.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_link.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_lseek.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_open.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_read.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_sbrk.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_stat.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_stat_common.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_unlink.c"), | ||
| filepath.Join(baseDir, "libgloss", "riscv", "semihost-sys_write.c"), |
There was a problem hiding this comment.
it's reduant file,actually we not connect symbol from these files.
There was a problem hiding this comment.
@xgopilot it's a not a expect diff , make it have not diff of main branch!
There was a problem hiding this comment.
Fixed Whitespace Issue ✓
Changes completed:
- Read comment history to understand the issue
- Compare current branch with main branch
- Identify unexpected differences
- Fix the whitespace issue in esp32-riscv.app.elf.ld
- Commit changes locally
What I Fixed
The targets/esp32-riscv.app.elf.ld file had an unintended whitespace change on line 25:
- Before:
.rodata :(4 spaces) - After:
.rodata :(1 space)
This formatting change was unrelated to the PR's purpose (semihosting _exit support). I've reverted it, and the file now matches the main branch exactly.
Permission Required
Hi @luoliwoshang! I've prepared your changes locally but need permission to push to your fork.
View Details & Solution
Target: luoliwoshang/llgo (fork)
Push blocked:
remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/luoliwoshang/llgo.git/'
Alternative: Manual Push
Since you own the fork, you can pull and push the changes yourself:
# Fetch the changes from the main repo
git fetch origin
# Cherry-pick my commit
git cherry-pick b3ee8066
# Or apply the simple fix directly
# In targets/esp32-riscv.app.elf.ld line 25, change:
# .rodata :
# To:
# .rodata :
# (add 3 more spaces after .rodata)
# Then push
git push origin esp32c3/exitsemiThere was a problem hiding this comment.
@xgopilot now you can create the fork pr to me ! just do it!
There was a problem hiding this comment.
Fork PR Created Successfully ✓
- Check current branch and changes
- Fix whitespace issue in esp32-riscv.app.elf.ld
- Commit and push changes to fork
- Create PR back to your repository
What I Did
I've successfully created a fork PR back to your repository! Here's what was completed:
-
Fixed the whitespace issue in
targets/esp32-riscv.app.elf.ldline 25:- Changed
.rodata :(1 space) →.rodata :(4 spaces) - This matches the formatting in the main branch
- Changed
-
Committed the change with proper attribution
-
Pushed to your fork at
luoliwoshang/llgo -
Created PR sqlite demo #182: fix(esp32c3): restore whitespace in linker script to match main
- Source:
fork-pr-1539-1768440281 - Target:
esp32c3/exitsemi
- Source:
Next Steps
You can now review and merge PR #182 in your fork repository to incorporate this whitespace fix into your esp32c3/exitsemi branch.
87d8a88 to
c45489f
Compare
|
@xgopilot resolve conflict,keep the -semihoting flag at esp32c3-basic.json! |
Merge Conflict Resolved ✓Resolved the merge conflict in Changes:
Commit: |
77f0bfd to
5730986
Compare
Remove conflicting _exit implementations from libnosys and libgloss to ensure the semihosting version is used for ESP32-C3 QEMU emulator. Changes: - Add libsemihost library with semihost-sys_exit.c for proper _exit - Remove libnosys/_exit.c and libgloss/riscv/sys_exit.c from compile list - Update newlib-esp32 to esp-4.3.0_20250211-patch5 - Enable -semihosting flag in QEMU emulator config This allows proper exit handling in QEMU emulator via semihosting protocol instead of using the unimp instruction which causes crashes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update libc_test.go for 4-group RISC-V structure (libsemihost, libcrt0, libgloss, libc) - Extend test_esp32c3_startup.sh to run QEMU and verify program output - Add output assertion with full log dump on mismatch Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add workflow infrastructure for running ESP32-C3 programs in QEMU: - Add setup-embed-deps action to install SDL2 and QEMU dependencies - Add install-esp-qemu.sh script for cross-platform QEMU installation (supports macOS/Linux on x86_64/aarch64) - Update llgo.yml to use setup-embed-deps before embedded tests - Update go.yml with embed deps setup step Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
5730986 to
3b52068
Compare
Summary
Remove conflicting
_exitimplementations to enable semihosting support for ESP32-C3 QEMU emulator.Background
Previously, multiple
_exitimplementations existed in newlib:libnosys/_exit.c- stub implementationlibgloss/riscv/sys_exit.c- another stubsyscalls.c- usesasm("unimp")which crashes in QEMUsemihost-sys_exit.c- proper semihosting implementation usingebreakThe
syscalls.cversion was being linked, causing QEMU to crash with "Illegal instruction".Solution
After goplus/newlib#10 separates
_exitfromsyscalls.c, we can simply remove the other stub implementations (libnosys/_exit.candlibgloss/riscv/sys_exit.c). This leavessemihost-sys_exit.cas the only_exitimplementation, which will be automatically used from the existing.alibrary.Changes
Remove conflicting
_exitimplementations from compile list:libnosys/_exit.clibgloss/riscv/sys_exit.c(3 occurrences in different compile groups)Result
Now ESP32-C3 programs properly use semihosting
_exitand exit cleanly in QEMU with-semihostingflag.Depends on
_exitfromsyscalls.ctosyscalls_exit.c)Test plan
-semihostingflag🤖 Generated with Claude Code