Skip to content

What EmbLinkRTOS needs from EmbCC (tracking) #184

Open

Description

@teo1747

This tracks what EmbLinkRTOS still needs from EmbCC. It is an inventory of the RTOS repository as of f76cc7c (2026-11-08). The RTOS's CI pins EmbCC 0.0.1-beta. Each item gives the evidence on the RTOS side and the workaround the RTOS uses today. Items can be split into their own issues when work starts.

RTOS links below are relative to https://github.com/EmbLinkOs/EmbLinkRTOS/blob/f76cc7c/.

1. Xtensa code speed

The only EmbCC runtime measurements are on the ESP32. The same kernel and port built by EmbCC take about 1.8 times GCC's cycles.

Checked build, 40 MHz, in cycles (docs/engineering/hil-esp32-port-2026-11-05.md):

EmbCC GCC Clang
notification hand-over 2090 1163 1325
semaphore hand-over 2075 1154 1250
semaphore give + take 436 226 218
interrupt wake 4211 2500 2697

Release build, 160 MHz, against FreeRTOS on the same board (docs/engineering/bench-esp32-freertos-2026-11-06.md):

FreeRTOS (GCC) EmbLink GCC 16.1 EmbLink Clang 22.1.4 EmbLink EmbCC
notify_handover 1535 969 1135 1749
sem_handover 1959 973 1056 1742
sem_give_take 316 208 200 406
isr_wake 3201 1951 2105 3247

Micro-costs under EmbCC: emb_thread_yield() with nothing to switch to costs 196 cycles; a software-interrupt round trip costs 318 (docs/ports/xtensa.md).

  • Compare EmbCC's and GCC's code for the scheduler (kernel/sched/sched.c) and the wait path (kernel/wait/wait.c), the hottest paths in these numbers.

2. Builtins the RTOS's compiler layer would use

include/emb/compiler/embcc.h defines none of the following, so the portable fallbacks in include/emb/compiler.h apply. If EmbCC already supports some of them, say which, and the RTOS will wire them in embcc.h (an RTOS change).

  • __builtin_clz, __builtin_ctz, __builtin_popcount. Without them, the scheduler's ready-set lookup (kernel/include/embk/word.h, called from kernel/sched/sched.c) is a loop of up to 32 steps instead of one instruction. This may account for part of §1; it is not measured.
  • __builtin_return_address(0). The crash record takes a software fault's pc from it (kernel/fault/fault.c), so under EmbCC that pc is 0.
  • __builtin_constant_p and __builtin_unreachable.
  • format(printf, …) checking, deprecated, and a C fallthrough attribute. Each is empty under EmbCC today.

3. Linux host compilation

EmbCC builds only the kernel on Linux. The RTOS's native port, board and tests are built by GCC, which also links: the "mixed" build of ADR-041 (docs/engineering/embcc-native-linux.md). That is the only EmbCC leg in the RTOS's CI.

  • pthreads in the x86_64-linux-gnu runtime. The error today is native_port.c:20: error: cannot find include file "pthread.h".
  • Accept __attribute__((__mode__)), so glibc's headers compile. glibc's sys/types.h:164 has typedef int register_t __attribute__ ((__mode__ (__word__)));.
  • Ship a Linux crt1.o. The 2026-10-14 snapshot failed with no crt1.o for x86_64-linux-gnu; check whether that is still the case.

4. Build-system integration

  • CMake identification. CMake reports "The C compiler identification is unknown" and "Did not find file Compiler/-ASM", so it requests no dependency files. A stale 40 MHz tick configuration survived a rebuild because of it. The RTOS now forces -MD -MT -MF itself (cmake/toolchains/embcc-depfile.cmake). An upstream Compiler/EmbCC-*.cmake module, or a GCC-compatible identification, would fix this.
  • A dependency file for assembly sources. The RTOS adds OBJECT_DEPENDS for xt_vectors.S by hand (arch/xtensa/CMakeLists.txt).

5. Per architecture

Xtensa

  • A release with embld's Xtensa script support (D-024, link: lay out Xtensa images from linker scripts #174). Until then, the ESP32 bring-up probe falls back to -Ttext/-Tdata.
  • A release with the working embflash --esp (embflash: program an ESP32 through its ROM's download mode #173). The installed 0.0.1-beta build sent FLASH_END, the ROM answered error 0x06, and embflash exited 2.
  • Directives in Xtensa inline assembly. Only instructions are accepted, so EMB_LAYOUT_MARKER uses a data form on __XTENSA__ (ADR-054, A95).
  • Stop warning on unused static inline functions, as GCC and Clang do not. The RTOS marks three trace helpers EMB_UNUSED for it.

Together, the first two would let the RTOS add an EmbCC Xtensa CI leg.

AVR

  • .debug_frame: EmbDBG backtraces stop at frame 0.
  • -g code-size growth: -O0 code may not fit the ATmega328P.
  • C++ on 16-bit targets ("the C++ lowering assumes a 32-bit int and 4-byte pointers").

There are no EmbCC size or speed numbers for AVR yet. Wiring __flash/progmem into the RTOS's flash macros and linking the conformance suite is a joint RTOS-side session (docs/ports/avr.md).

RISC-V

  • Inline assembly: lr/sc/amo*, the la/call/tail pseudo-instructions, and floating point.
  • The interrupt attribute. The RTOS uses an assembly trap entry.

Cortex-M

  • CMSE with an FPU: cmse_nonsecure_entry functions must clear the floating-point registers.
  • Armv6-M atomic helpers mask with PRIMASK, which has no effect in unprivileged Thread mode.
  • Cortex-M23: checked only as an M33 with a Baseline instruction scan, never on an M23.

6. Language conformance and diagnostics

  • Enforce -std= (today accepted and ignored), so ISO conformance can be checked.
  • Refuse _Thread_local/__thread on embedded targets, or implement it. Today each silently becomes one shared instance.
  • __STDC_HOSTED__ should be 0 under -ffreestanding; it is 1.
  • Complete _Alignas, and _Atomic beyond integer and pointer types.
  • The warnings the RTOS builds with: -pedantic/-Wpedantic, -Wcast-align, -Wnull-dereference. Each is reported as "not a warning EmbCC has", 390 times across the RTOS's archived build logs.
  • Inline assembly: labels, wider-than-register outputs, callee-saved clobbers.
  • Inlining of functions that return a struct. The RTOS's time constructors are macros for this reason (include/emb/time.h, SPEC-001). The current toolchain profile no longer lists it, so it may be fixed; please confirm.
  • Build EmbCC warning-clean with GCC 14.2: a missing readlink declaration, then format-truncation and empty-body warnings.

Already done upstream

These need no work. The ten items of the RTOS's 2026-10-14 capability review are each done within their stated scope:

  • Armv8-M stack limits;
  • AVR linker scripts, __flash/progmem, DWARF 4 and the EmbDBG register layout;
  • small RV32/AVR atomics;
  • soft-float CMSE;
  • Cortex-M23;
  • SVD clusters/arrays/JSON;
  • C++ without exceptions.

Constructor priorities, typedef alignment and 8-byte atomic helpers are also done.

The RTOS side still owes cleanup: some of its specifications describe these as missing, and its Xtensa default toolchain is EmbCC although its CI builds Xtensa only with GCC and Clang. That is being fixed there.

Activity

  1. teo1747 commented on Nov 9, 2026

    @teo1747
    MemberAuthor

    Status of every item. "On main" means it was already in EmbCC before this issue; "#185" means PR #185 fixed it (merged). Items marked release reach the RTOS once its CI moves from 0.0.1-beta to EmbCC 0.1.0, which is being released now (#199).

    1. Xtensa code speed

    I compared EmbCC's and GCC's code for sched.c and wait.c (ESP32, -Os, the checked build's flags). Seven causes, each now fixed in #185:

    Cause Fix
    Every instruction was 24-bit; GCC's assembler narrows mov, movi, add, addi, l32i, s32i and retw to the 16-bit density forms The code generator emits the density forms (lib/libc at -Os: −20%)
    static inline list helpers stayed calls at -Os (on the windowed ABI each one costs a call8, an entry and a retw) At -Os, a function declared inline gets a larger budget, weighed as optimized. lib/libc also gets smaller on every target
    emb_time_now().ticks was read one byte at a time (8 loads and 7 shifts) A member of a returned struct is now an aligned load (also on ARMv6-M and MIPS)
    bool runnable = a && b; if (runnable) built the 0/1, merged it, and tested it again, three times in embk_sched_select Branches on the original conditions
    A list walk's NULL arm went through the loop test whose answer it already had Goes straight on
    A test shared by two branches (cur != idle twice) was built as a 0/1 and kept Compared again at each branch, so each fuses with its compare
    Constant unsigned char/short call arguments (the trace calls) were re-extended Written once

    Result, in bytes:

    before now GCC
    sched.c 2073 1520 1202
    wait.c 1656 1141 890

    EmbCC's code for these two files is now about 1.27× GCC's size; it was about 1.8×. Since the first round, 64-bit arithmetic stays in register pairs, 64-bit tests are a branch per half, addx4 is used for indexing, and beqz.n/bnez.n are used. These are byte and instruction counts, not cycles; the HIL cycle numbers need a rerun on the board. The one item that was still open, an 8-byte struct parameter going through the stack (an emb_time_t passed by value), is fixed in #196: it is passed in a register pair on Xtensa, AAPCS and RV32.

    2. Builtins

    All of these were already on main: __builtin_clz/ctz/popcount (one instruction on Xtensa: nsau), __builtin_return_address(0), __builtin_constant_p, __builtin_unreachable, and format(printf) checking. deprecated and fallthrough are on main too. embcc.h can wire them all in.

    3. Linux host compilation

    All on main: pthread.h, __attribute__((__mode__)), and crt1.o. release — 0.0.1-beta lacks pthread.h.

    4. Build-system integration

    • CMake: share/embcc/cmake/embcc.cmake is shipped and identifies EmbCC. A bare CC=embcc cannot be identified by CMake itself; use the toolchain file.
    • Assembly depfiles: -MD/-MMD on .S and .s now write a depfile, and -M on a .S no longer links (What EmbLinkRTOS needs (#184) #185).

    5. Per architecture

    Xtensa

    AVR

    RISC-V

    Cortex-M

    • CMSE with an FPU: What EmbLinkRTOS needs (#184) #185, with clang's sequences (SFPA test, FPSCR clearing, VLSTM/VLLDM), tested on QEMU's M33.
    • ARMv6-M atomics unprivileged: What EmbLinkRTOS needs (#184) #185. The helpers call weak __embcc_atomic_lock/__embcc_atomic_unlock hooks, which the RTOS overrides (an SVC, for example); the default traps instead of silently not masking.
    • Cortex-M23: EmbSim now has a Cortex-M23 (--cpu cortex-m23, board mps2-an519) with exactly Baseline's instructions; anything else faults. Every Baseline exec program now also runs on it and must exit as on QEMU's M33: 1480 runs, all alike (What EmbLinkRTOS needs (#184) #185).

    6. Language conformance and diagnostics

    • -std= enforcement, __STDC_HOSTED__ 0 under -ffreestanding, _Alignas: on main.
    • _Thread_local/__thread: What EmbLinkRTOS needs (#184) #185. Local-exec TLS on ARM (__aeabi_read_tp, R_ARM_TLS_LE32) and RISC-V (tp). embld provides picolibc's __tdata_*/__tls_* symbols. Targets without a thread pointer refuse a thread-local by name.
    • _Atomic float, double and structs: What EmbLinkRTOS needs (#184) #185, with GCC's layout. 12-byte and 3-byte structs go through libatomic's generic calls, which lib/rt provides.
    • Warnings: -Wpedantic was on main. -Wcast-align (and =strict) and -Wnull-dereference: What EmbLinkRTOS needs (#184) #185.
    • Inline asm:
    • Struct-returning (and struct-parameter) functions are inlined: What EmbLinkRTOS needs (#184) #185. The time constructors can be functions again.
    • GCC 14 builds warning-clean: on main, with a CI job.

    Needs a release

    #173, #174, pthread.h in the Linux runtime, everything above marked #185, and #196. All of it is in 0.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions