Commit 087d780
fix(esp32c3): skip -march=rv32imac to avoid illegal instruction crash
This commit fixes the illegal instruction crash issue for ESP32-C3 and
improves the architecture to support all ESP RISC-V chips through a
proper llvm-target based approach.
## Problem
1. ESP32-C3 only supports RV32IMC (no A/D/F extensions)
2. Previous fix used hardcoded `targetName == "esp32c3"` check, which
doesn't work for inherited targets (esp32c3-supermini, m5stamp-c3, etc.)
3. compiler-rt's atomic.c was included for all riscv32 targets, causing
compilation failure on ESP chips (requires A extension)
## Solution
### 1. Create ESP RISC-V base configuration
- Rename: `riscv32-nostart.json` → `riscv32-esp.json`
- Change `llvm-target` from `riscv32-unknown-none` to `riscv32-esp-elf`
- Change `cflags` from `-march=rv32imac` to `-march=rv32imc`
### 2. Update ESP32-C3 inheritance
- Update `targets/esp32c3.json` to inherit from `riscv32-esp`
- Automatically applies to all boards inheriting esp32c3:
- esp32c3-supermini
- m5stamp-c3
- esp32-c3-devkit-rust-1
- esp-c3-32s-kit
- esp32c3-12f
### 3. Fix compiler-rt atomic.c inclusion
- Exclude atomic.c for ESP targets (riscv32-esp-elf)
- Keep atomic.c for other riscv32 targets that support A extension
### 4. Use llvm-target instead of targetName
- Check `config.LLVMTarget == "riscv32-esp-elf"` instead of hardcoded name
- Properly supports inheritance relationships
- ESP series: `-march=rv32imc`
- Other riscv32: `-march=rv32imac`
## Benefits
✅ Fixes illegal instruction crash (C.FLD) for all ESP32-C3 boards
✅ Fixes compiler-rt atomic.c compilation error
✅ Supports inheritance - all ESP32-C3 variants automatically fixed
✅ Follows ESP-IDF conventions (riscv32-esp-elf is official target triple)
✅ Scalable - future ESP RISC-V chips just inherit riscv32-esp.json
✅ Backward compatible - other riscv32 targets unchanged
## Files Changed
- targets/riscv32-nostart.json → targets/riscv32-esp.json (rename + modify)
- targets/esp32c3.json (update inherits)
- internal/crosscompile/compile/rtlib/compiler_rt.go (exclude atomic.c for ESP)
- internal/crosscompile/crosscompile.go (use LLVMTarget instead of targetName)
Fixes: Issue #1427
Related: PR #1440
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent edb15ea commit 087d780
File tree
4 files changed
+15
-9
lines changed- internal/crosscompile
- compile/rtlib
- targets
4 files changed
+15
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
538 | 540 | | |
539 | 541 | | |
540 | 542 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
0 commit comments