[PATCH] m68k-atari-elf: libgloss bug fixes
micael@hildenborg.com
micael@hildenborg.com
Wed Nov 18 20:01:32 GMT 2026
I used Claude AI to analyze the libgloss code for the m68k-atari-elf
target, and found more bugs and problems than I want to admit...
The rest of the mail is composed by Claude AI and summarizes all the
patches that also are attached to this mail.
/Mikael Hildenborg.
This series fixes bugs in the libgloss support for Atari TOS
(m68k-atari-elf). All changes are in libgloss/m68k/atari and
libgloss/m68k/Makefile.in; no other target is affected.
Startup, linking and memory:
- Linker script: .bss.* input sections were placed outside .bss, so
they were not cleared and overlapped the heap (any C++ program).
- C destructors (.dtors) ran after stdio was shut down, and also on
_exit()/abort(). _fini is now registered with atexit, and _exit is
a plain Pterm.
- Environment and arguments were reserved twice in the stack/heap
size, and sbrk() let the heap grow right up to the stack pointer.
sbrk now keeps a margin (4KB, settable with _sbrk_stack_margin).
Command line and environment:
- Backslashes (the TOS path separator) were treated as escapes, the
command line length byte was ignored, the Atari ARGV protocol was
not followed, and parsing could read past the environment block.
The global environment also overwrote the program environment.
File and system calls:
- stat/fstat used Fgetdta on a handle and reported garbage; stat now
uses Fsfirst and works for directories, fstat seeks for the size.
- open: O_EXCL, O_TRUNC and O_CREAT now behave as POSIX requires, and
a file can no longer be truncated because Fopen failed. O_APPEND is
honoured by every write.
- isatty only returned true for the AUX handle; isatty and fstat now
detect character devices, so redirected handles are handled too.
- Console read added a newline to every short read, which made reads
from a redirected stdin never reach end of file.
- chdir changed drive before checking it, getcwd ignored the buffer
size, gettimeofday was 23 hours ahead, and kill() terminated the
program for signal 0 and for signals that are ignored by default.
- GEMDOS errors are mapped to the expected errno values, the
write-protect error code was wrong, and setmode() did not report
text mode for stderr.
- getentropy was seeded only from XBIOS Random() (24 bits). It now
collects timing jitter into a ChaCha20 based pool.
- The trap wrappers now have a "memory" clobber.
Testing: built with the configure line below, then run under EmuTOS in
the Hatari emulator, plus host tests of the parsing and conversion
code with stubbed system calls.
configure --target=m68k-atari-elf --with-float=soft --disable-lto \
--enable-target-optspace --disable-newlib-wide-orient \
--disable-newlib-mb --disable-newlib-multithread \
--enable-newlib-reent-small
Mikael (17):
m68k-atari-elf: Fixed bug for missing C++ sections.
m68k-atari-elf: Fixed bug with fstat and stat.
m68k-atari-elf: Fixed bug in gettimeofday where the time returned was
23 hours ahead.
m68k-atari-elf: Fixed several bugs with the argv and environment
strings.
m68k-atari-elf: Fixed bugs in isatty and fstat.
m68k-atari-elf: Fixed bug where wrong drive could be selected.
m68k-atari-elf: Fixed buffer overrun.
m68k-atari-elf: Open is now POSIX compatible, and a bug with truncated
files is fixed.
m68k-atari-elf: GEM error codes is more properly mapped to POSIX error
codes.
m68k-atari-elf: Added memory clobber to asm calls.
m68k-atari-elf: Fixed bug with line endings.
m68k-atari-elf: Fixed bug with C destructors not handled properly in
CRT.
m68k-atari-elf: Fixed some heap and stack problems.
m68k-atari-elf: getentropy is now a lot stronger.
m68k-atari-elf: Fixed getmode for stderr.
m68k-atari-elf: Kill is properly implemented for a single process
system.
m68k-atari-elf: Fixed bug where O_APPEND not always did what it should
do.
libgloss/m68k/Makefile.in | 2 +-
libgloss/m68k/atari/README | 2 +
libgloss/m68k/atari/atari-chdir.c | 75 +++--
libgloss/m68k/atari/atari-close.c | 5 +
libgloss/m68k/atari/atari-crt0.S | 22 +-
libgloss/m68k/atari/atari-crti.S | 12 +-
libgloss/m68k/atari/atari-crtn.S | 17 +-
libgloss/m68k/atari/atari-dostime.c | 88 ++++++
libgloss/m68k/atari/atari-dostime.h | 34 +++
libgloss/m68k/atari/atari-environ.c | 383 +++++++++++++++----------
libgloss/m68k/atari/atari-fstat.c | 78 +++--
libgloss/m68k/atari/atari-gem_errno.c | 106 +++----
libgloss/m68k/atari/atari-gem_errno.h | 10 +-
libgloss/m68k/atari/atari-getcwd.c | 50 +++-
libgloss/m68k/atari/atari-getentropy.c | 157 +++++++---
libgloss/m68k/atari/atari-gettod.c | 94 ++----
libgloss/m68k/atari/atari-handle.c | 64 +++++
libgloss/m68k/atari/atari-handle.h | 39 +++
libgloss/m68k/atari/atari-isatty.c | 17 +-
libgloss/m68k/atari/atari-kill.c | 67 ++++-
libgloss/m68k/atari/atari-open.c | 126 +++++---
libgloss/m68k/atari/atari-read.c | 55 ++--
libgloss/m68k/atari/atari-sbrk.c | 63 ++--
libgloss/m68k/atari/atari-setmode.c | 2 +-
libgloss/m68k/atari/atari-stat.c | 179 +++++++++++-
libgloss/m68k/atari/atari-tos.ld | 2 +-
libgloss/m68k/atari/atari-traps.c | 64 ++++-
libgloss/m68k/atari/atari-traps.h | 24 +-
libgloss/m68k/atari/atari-write.c | 12 +-
29 files changed, 1360 insertions(+), 489 deletions(-)
create mode 100644 libgloss/m68k/atari/atari-dostime.c
create mode 100644 libgloss/m68k/atari/atari-dostime.h
create mode 100644 libgloss/m68k/atari/atari-handle.c
create mode 100644 libgloss/m68k/atari/atari-handle.h
--
2.53.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-m68k-atari-elf-Fixed-bug-for-missing-C-sections.patch
Type: text/x-patch
Size: 698 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0017.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-m68k-atari-elf-Fixed-bug-with-fstat-and-stat.patch
Type: text/x-patch
Size: 14153 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0018.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-m68k-atari-elf-Fixed-bug-in-gettimeofday-where-the-t.patch
Type: text/x-patch
Size: 7206 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0019.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-m68k-atari-elf-Fixed-several-bugs-with-the-argv-and-.patch
Type: text/x-patch
Size: 14858 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0020.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-m68k-atari-elf-Fixed-bugs-in-isatty-and-fstat.patch
Type: text/x-patch
Size: 5678 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0021.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-m68k-atari-elf-Fixed-bug-where-wrong-drive-could-be-.patch
Type: text/x-patch
Size: 2644 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0022.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0007-m68k-atari-elf-Fixed-buffer-overrun.patch
Type: text/x-patch
Size: 2117 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0023.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0008-m68k-atari-elf-Open-is-now-POSIX-compatible-and-a-bu.patch
Type: text/x-patch
Size: 6901 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0024.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-m68k-atari-elf-GEM-error-codes-is-more-properly-mapp.patch
Type: text/x-patch
Size: 6319 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0025.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0010-m68k-atari-elf-Added-memory-clobber-to-asm-calls.patch
Type: text/x-patch
Size: 2185 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0026.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0011-m68k-atari-elf-Fixed-bug-with-line-endings.patch
Type: text/x-patch
Size: 3020 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0027.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0012-m68k-atari-elf-Fixed-bug-with-C-destructors-not-hand.patch
Type: text/x-patch
Size: 3111 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0028.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0013-m68k-atari-elf-Fixed-some-heap-and-stack-problems.patch
Type: text/x-patch
Size: 3881 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0029.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0014-m68k-atari-elf-getentropy-is-now-a-lot-stronger.patch
Type: text/x-patch
Size: 5648 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0030.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0015-m68k-atari-elf-Fixed-getmode-for-stderr.patch
Type: text/x-patch
Size: 784 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0031.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0016-m68k-atari-elf-Kill-is-properly-implemented-for-a-si.patch
Type: text/x-patch
Size: 2121 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0032.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0017-m68k-atari-elf-Fixed-bug-where-O_APPEND-not-always-d.patch
Type: text/x-patch
Size: 4837 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20261118/05d061cb/attachment-0033.bin>
More information about the Newlib
mailing list