[PATCH v2 0/3] Improve semihosted stat reporting for ARM and AArch64

Torbjörn SVENSSON torbjorn.svensson@foss.st.com
Thu Oct 8 18:01:28 GMT 2026


Changes since v1:
- Extended the changes to also cover the aarch64 variant and the internal
  newlib syscalls implementations, as requested by Richard Earnshaw during
  GNU Tools Cualdron in Prague.
  Note, the aarch64 implementation has only been verified to build. No
  other tests has been ran on it.


Semihosting does not provide a stat operation, so the ARM and AArch64
syscall implementations infer file metadata from the available
operations. Without that inference, directories can be misclassified
and file type bits may be incorrect.

This series updates three implementations to identify terminals with
the IsTTY operation, use FLEN to identify regular files and retrieve
their sizes, and recognize directories in _fstat when FLEN returns
EISDIR. For _stat, it probes "path/." to recognize directories. The
implementations also report file type and regular-file size/block
metadata where available.

The changes are split by implementation:
  1. libgloss/arm
  2. newlib
  3. libgloss/aarch64

This information is needed by callers such as
std::filesystem::canonical to handle semihosted paths correctly.

The issue was discovered and reported here:
https://gcc.gnu.org/pipermail/gcc-patches/2026-August/727185.html

Testing:
- Regression tests for libgloss/arm and newlib were run with GCC
  r17-4804-gf7094fe5ff882f; no regressions were observed.
- With libgloss/arm, six tests changed from XFAIL to XPASS and one
  changed from FAIL to PASS. Once this series is merged, I'll send a
  follow-up GCC patch to update the expected results for those tests.
- The AArch64 change was compile-checked; runtime testing has not been
  performed.

Note: libstdc++'s check_v3_target_fileio passes with libgloss/arm.
With newlib, it fails at the first lseek call, leaving 154
otherwise-supported tests marked UNSUPPORTED.


Ok for trunk?

--

Torbjörn SVENSSON (3):
  libgloss/arm: report semihosted file types in stat calls
  newlib: report semihosted file types in ARM stat calls
  libgloss/aarch64: report semihosted file types in stat calls

 libgloss/aarch64/syscalls.c    |  77 ++++++++++++++++--
 libgloss/arm/syscalls.c        | 126 ++++++++++++++++++++++++------
 newlib/libc/sys/arm/syscalls.c | 138 +++++++++++++++++++++++++++++----
 3 files changed, 294 insertions(+), 47 deletions(-)

-- 
2.43.0



More information about the Newlib mailing list