Repository navigation
APExp release 0.6 #643
staalmannen
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
APExp 0.6
APExp is an enhanced ANSI/POSIX compatibility layer for Plan 9 and 9front,
aiming for maximal GNU/POSIX compatibility so that C programs written for
UNIX build on Plan 9 with as little modification as possible.
0.5 replaced the C library's stdio and widened three types. 0.6 is mostly
about what that made possible: GNU coreutils, tar, diff and patch build
and are installed by default, and so do LibreSSL, curl, libzip, pax and
perl. TLS 1.3 works. bash is
/bin/shand builds the tree.It is also the release in which a long series of compiler bugs were found,
nearly every one of which produced silently wrong values rather than an
error. Several had been corrupting output for as long as they had existed.
That is the reason for the rebuild notice below, and it is not a formality.
The library bugs ran the same way.
st_rdevwas 0 for every file, socmpcompared two different files in silence;ino_twas sixteenbits against a tree of 64799 files;
fsyncanswered failure where thehonest answer was nothing to do, and
xzdeleted every file it wroteas a result; and no thread this library ever created reached its start
routine, because the child half of
pthread_createwaited on arendezvous the parent never answered. Not one of those announced itself
as the thing it was.
APE's struct layout changed.
pccnow lays structs out the way everyother C compiler does; see the section on it. That alone means nothing
built before 0.6 can be mixed with anything built after it.
As always, APExp is intentionally unstable between releases. Download the
latest release rather than upgrading in place.
Rebuild everything — read this first
Anything built before 0.6 is suspect, whether or not it links. This is
not the usual ABI-change warning: the compiler was quietly producing wrong
values in ordinary C, so a binary can link cleanly and still be wrong.
Two of the bugs are the clearest reason:
boolwas a signed char, so every conversion to it truncated tothe low byte instead of comparing against zero, as C99 6.3.1.2 requires.
bool b = 256;was false.(bool)pfor any aligned pointer was a cointoss on its low byte. The common idiom
bool ok = flags & SOME_MASK;isfalse whenever the mask is above bit 7 — there are around 350 of that
exact shape in the ported packages, and curl alone mentions
boolin291 files.
6ctruncated a live 64-bit value across a 32-bit divide or modulo.Every SHA-3 digest was wrong, so ML-KEM was wrong, so every TLS 1.3
handshake offering X25519MLKEM768 failed. Nothing about that is
Keccak-specific: a 64-bit value live across a 32-bit
%is ordinary C.Rebuilding the compiler is not enough on its own, and neither is
rebuilding libap. Everything here links statically, so a library fix
reaches only the binaries relinked after it — an old
lskeeps the oldhash.cand the oldsetlocaleinside it however many times libap isrebuilt underneath. That is what "everything" means above.
The order matters, because every architecture compiler consumes
y.tab.hfrom
cc:Prefer
mk distcleantomk nukeat the root.nukeiscleanplusrm -f ... $LIB, and$LIBis$APEXPROOT/$objtype/lib/ape/libap.a—with
$APEXPROOTempty that is an absolute path into the host's own stockAPE rather than into this tree. Every mkfile here assigns
APEXPROOTitself, so it takes a command-line override to get there, but there is no
reason to run into it.
distcleanloops over a literal architecture listand touches only
./$arch/binand./$arch/lib.distcleanempties those two directories rather than removing them,and that is load-bearing:
apexp-shbinds them, a Plan 9 bind captures adirectory's channel, and
rm -rffollowed by a freshmkdirleaves therunning shell looking at a directory that no longer exists. Every lookup
then falls through to the host's own
/$objtype/bin, so the next compileruns stock 9front's
6cand dies onsyntax error, last name: bool.A library that built yesterday stops building and nothing in the message
is about binds. If that shape appears, start a fresh
apexp-sh.There are ABI-visible changes as well:
bool/_BoolSIZE_MAX0xffffffffon amd64, beside an 8-bytesize_tsize_tSSIZE_MAXLONG_MAX, i.e. 32-bit on amd64ssize_tS_IFSOCKS_IFIFO0140000, its own valuestruct direntd_ino/d_typewere macrosNAME_MAX/PATH_MAXS_IFSOCKis worth calling out: aliasing it toS_IFIFOmadeS_ISSOCK()true for every FIFO, and gave duplicatecaselabels to anyswitchover file types.Source-level changes
<stdio.h>no longer includes<errno.h>,<unistd.h>,<fcntl.h>and
<pthread.h>. It used to include musl's internal<stdio_impl.h>,which pulls all of those in, so nearly every translation unit in the tree
saw every
O_andF_macro by accident. Code that usederrno,open()orpthread_*while including only<stdio.h>compiled byluck and now needs the right
#include— a one-line fix per file, andeach one is a real latent bug.
That leak was not harmless. Portable code guards its fallbacks on whether
a name exists, and libzip's
compat.hdefinesO_CLOEXECas 0 when itcannot see one; the definition then collided with the real one arriving
later through
<zip.h>.<features.h>no longer defineshiddenorweak_alias. Both aremusl's internal macros and both were in a public header.
hiddenexpandsto nothing, and
sqlite3.h:10957declaresunsigned char hidden[48];—erased wherever
features.hcame first, which is a silent struct-layoutchange in a public API. Sixteen private libap files carry an
#ifndef hiddenguard instead, which is the idiominclude/libm.halready used.<stdlib.h>no longer declaresunameandgetrusage. It definesneither
struct utsnamenorstruct rusageand includes neither header,so each struct named in those parameter lists was a new incomplete type
scoped to the declaration — distinct from the real one, and
conflicting typesfor any file that included both. POSIX puts them in<sys/resource.h>and<sys/utsname.h>, which already declare themcorrectly.
<qlock.h>no longer definesLocka second time. It includes<lock.h>, which typedefs it, and then carried its own copy behind#ifndef Lock— andLockis a typedef, not a macro, so that test wasalways true. Two
typedef struct { int val; } Lock;define two distinctanonymous structs sharing a name, which C forbids; kencc tolerated it,
which is why it survived. Sixteen of the public headers could not be
compiled by a standards-strict compiler at all.
Plan9libnet.his deleted (nothing included it, and two of its threedistinctive declarations named functions that do not exist), and
<libnet.h>— which<sys/socket.h>itself includes — no longer declaresnet_accept,net_listenandnet_reject, which were defined nowhereand called nowhere.
Changelog
The sections after this one give the evidence for each line. Where a
thing was recorded rather than measured, the entry says so — that
distinction is the point of the list, and Known limitations is sorted
by it.
Incompatible changes
pccpasses-J: APE structs are laid out the way every other Ccompiler lays them out. Sixteen public structs move — all the sockets
and locks, plus
termios. Native6cis unchanged.ino_tanddev_tare 64 bits, andstruct statis 104 bytes whereit was 88.
mk distcleanbeforemk install. Nothingolder can be mixed with anything newer.
New in the default build
LibreSSL, curl, libzip, pax; perl 5.42.2 (no XS — Plan 9 has no
dlopen)./bin/shand builds the tree.dashis gone.c++/eccp. It translates, compiles andlinks, templates included, with
--instantiate local. There is noC++ standard library here and EDG ships none, so the reachable subset
is the one EDG itself is written in.
Compiler
_Generic,boolas a real type,__alignof__, unicode escapes,bit-fields.
the sign of zero, mixed-signedness
op=, theL-suffix width cap, atruncated wide
caselabel, a compound literal not zeroing omittedmembers, and both bit-field layout rules with the static initialiser
underneath them.
Library, by what the bug did rather than what it was
cmpcompared two different files in silence —st_rdevwas 0for every file, so gnulib's
same_file()said yes to every pair ofcharacter specials, and
cmpconcluded its own stdout was/dev/null.than 65536 —
ino_twas sixteen bits and a Plan 9 qid is 64. Thistree alone is 64799 files.
xzdeleted every file it wrote —fsyncanswered failure wherethe honest answer was nothing to do.
pthread_create's child waited on a rendezvous the parent neveranswered. Both archiver hangs were this.
message — gnulib's
strerrorcalled itself for ever.printfdid not know%td, and an unrecognised conversion consumes no argument, so everyconversion after it took the wrong one.
sizeof(union block)was 520.
isblank('\t')answered false, and bash's syntax table is generated.getcwd(NULL,n);mktemp's 26 names; fifteen missingstrftimeconversions; 40 wrongstrerrorentries;dup/dup2/F_DUPFDon a buffered descriptor;.and..inreaddir;collating symbols in
regcomp;umask;poll()'s three POSIXviolations, two of which can spin a caller; and
select()reportinga regular file readable, as POSIX requires.
Still open and deliberately so
separated — see What's next for the two runs that would.
pthread_attr_*are no-ops;detachstateis not honoured.Conforming struct layout
pccpasses-Jon every compile, and APE structs are laid out the wayevery other C compiler lays them out. Native
6ckeeps the 9front rule,because native code links the host's own
libc.a.Stock kencc rounds every struct's size up to 8 and aligns a nested
struct member to 8 (
6c/swt.c'salign(), casesAsu2andAel1), sosizeof(struct{char a[500];})is 504. Field offsets are still right, so amemcpyinto a local is fine — what breaks issizeofused as a strideor a length. That made GNU tar's
union block520 where the format says512, so every block landed eight bytes late and every archive tar wrote
was malformed; the reader mis-strode identically, so a correctly formed
foreign archive walked into its own payload and reported
This does not look like a tar archive. Both symptoms, one cause.The flag is
-Jand the global is namedconformalign. It is not aper-package flag and must not be used as one: it changes every struct the
translation unit sees,
<stdio.h>'s and<sys/stat.h>'s included, so onepackage built with it against a libap built without it disagrees about
FILE,struct statandDIR— silently, with no link error, becauseevery symbol still resolves. The safe unit is all of APE after a
distclean, or nothing.The cost was measured before it was taken, by compiling a probe twice
and diffing the two acid dumps.
-Jmoves sixteen structs and they areall sockets and locks —
in_addr8→4,sockaddr_in24→16,pthread_mutex_t56→40,QLock32→24, plustermios32→28 — every oneof them becoming the number every other system says. What is absent is
the result:
FILE,struct stat,DIR,jmp_buf,fd_set,tm,timeval,dirent,passwd,sigaction,regex_tandsigset_tareall unchanged, and they are the types the flag's own warning had named as
the reason it was all-or-nothing.
Bit fields share the container at both ends. Under
-Ja bit-fieldgroup no longer reserves a whole
tfieldunit. Its tail is shared:the width advances by
ceil((shift+nbits)/8), so the next ordinary membersits in what is left of the container. And its head is shared: a group
that follows an ordinary member starts at the next available bit, in the
tfield-aligned unit containing that bit, moving to the next unit onlywhere the field would cross a boundary. That is what C compilers do
everywhere else, and it is what EDG's generated C, perl's
struct opandmusl's mallocng header are all written expecting.
In the public headers the tail rule moves exactly one struct —
__res_state, whoseunused[3]goes from 368 to 365 and whose size goes456→448 — plus
curl.h's HSTS entry. The head rule moves one more, and itis the one that mattered:
fenv_t, whose bit-field group follows anunsigned short, so__data_offsetwas at 24 and__mxcsrat 32 wheregcc says 20 and 28 — and 28 is the number
arch/amd64/fenv.shardcodes,FSTENV (DI)followed bySTMXCSR 28(DI), because the struct is atranscription of the x87 environment image. Latent rather than live:
nothing in the tree read a member by name, and the 32 bytes the assembly
writes fitted inside the 36 the struct had. It would have bitten the first
time anything read
env.__mxcsr.structalign-testsection 9 asserts both rules over nine shapes, andsys/lib/tests/sualign-model.pychecks the arithmetic against gcc on thebuild host — twelve shapes, 0 disagreements — before the VM compiles a
line, because kencc's own sources need Plan 9's headers.
And the static initialiser had to be narrowed to match.
init1emitted a bit-field group as one DATA of
tfield's width at thecontainer, which with either end of that container shared writes over
the neighbouring members —
6lanswersmultiple initialization, and itis right, since the same bytes really are written twice. GNU make's
struct function_table_entryis what found it.cc/dcl.c'sgbitagg()emits the group's own bytes one at a time (
datblkaccepts widths 1, 2,4 and 8, and a group can span three), and the group boundary is a gap in
the bits rather than a change of container offset, since two groups can
now share one container. The tail rule carried the same defect from the
day it landed and nothing had statically initialised a struct that
would fire it.
bitinit-test.cis the regression test andbitinit-model.pychecks the emitted bytes against gcc's own object,with the replaced code as a control that fires.
All of it is measured on the machine, after a full
mk distcleanplusmk install.structalign-test0 underpccand 29 underpcc -9;edgscope-probe6 disagreements -> 0, with its no-preceding-membercontrol still clean in both runs, so the fix is the following rule
specifically and not bit fields in general;
edgtuoff-probeand__res_stateunchanged, which was a written-down refutationcondition and did not fire — every group in those is preceded by a
pointer, so the head rule cannot reach them;
bitinit-test0 with itsno-bit-field control passing. The
-9count was predicted as 30 and theone-line difference is unattributed; every per-name condition held, which
is the half that was about the rule.
pcc -9asks for the old rule and exists for the instruments only.Nothing in the tree passes it and nothing should:
structalign-test'scontrol run and the layout probe's two compiles are both differences
between the two rules, and with no way to ask for the old one neither
measurement could ever be taken again.
New ports
sbaseis cut back to what only it providesdiff,diff3,sdiff,cmplibressl.aplus theopensslcommandlibcurl.aplus thecurlcommandzipcmp,zipmergeandziptoolpaxandcpio; GNU tar is thetarlibitcl.aanditclsh; its own suite runsbasic; self-hosts to a fixpoint — it converts its own 10518 lines and the result emits byte-identical Clibedg.aandcpfe, withc++/eccpas the driver; translates, compiles and linksLibreSSL and curl are built by default, and their public headers are
installed into
sys/include/apewith#pragma lib, so#include <openssl/ssl.h>or<curl/curl.h>is enough to link.TLS 1.3 works, including X25519MLKEM768 —
openssl s_clientcompletesa handshake with a verified certificate chain. Getting there took the 6c
fix above; the route was upstream's own ML-KEM and SHA-3 vectors, which
now live in
sys/src/ape/lib/libressl/testand run withmk test.C++: there is a front end, and it is not a C++ toolchain yet
rc/bin/ape/eccpis the driver andc++is a one-line forwarder toit, so
CXX=c++works for autoconf, for GNU make's default and forsys/src/cmd/transpilers— whose rules did not have to change at all,which is the whole value of having gone through a driver. The pipeline is
cpfe(C++ -> C) ->cc -c-> link againstlibedg.a.Measured, end to end: a toy with a virtual base, an override, a
template and
new/deletegoes through cpfe, throughcc -c, throughthe link, and runs. It did not at first — it failed on a template
instantiation, because EDG's default mode expects an
edg_prelinkpassthis tree has not got and cannot naturally express.
eccppasses--instantiate local, which emits each instantiation inside thetranslation unit that needs it with internal linkage, so nothing is
undefined and nothing collides. The cost is that a template's static
data member, or a static local inside a template function, becomes one
object per translation unit instead of one per program — a program
resting on that identity is silently wrong, and a single translation
unit cannot show it.
What is honestly absent, and it is the big one: there is no C++
standard library here and EDG ships none.
lib_srcis thelibsupc++/libc++abi layer — new/delete, vtables, RTTI, static init,
pure-virtual — and
include_c++is the language-support set. There is no<vector>, no<string>, no<iostream>. The subset that works isthe one EDG itself is written in: classes, templates, virtual dispatch,
RAII,
new/delete, andbad_alloc/type_info/initializer_list.Static constructors are a recorded gap — nothing calls EDG's
__call_ctors— so a translated program's static initialisers do notrun. Read it as "kencc can now compile a useful subset of C++", not as
"APExp has C++".
perl
The interpreter runs and loads modules;
ExtUtils::Miniperlgeneratesperlmain.cduring the build. Two things to know:dlopen, soxs_initis empty andonly the pure-perl
dist/andcpan/trees are installed — thefourteen with a
.xsare deliberately left out, because a.pmthatdies inside
XSLoaderis worse than one that is simply absent.Config.pmis hand-maintained, atsys/src/ape/cmd/perl/Config.pm.APExp does not run
Configure, so there is noconfig.shforconfigpm; it is the companion to the hand-answeredconfig.hand hasto be kept in step with it.
Tcl/Tk/itcl
Tcl's suite finishes with nothing aborting:
Total 68118 Passed 62160 Skipped 5916 Failed 42, 167 files, four minutes, clean exit — measuredon the tree that carries this release's whole ABI move. All 42 are listed
by name in
docs/notes/tcl-suite.md, beside the 43 of the previousbaseline, which is the first per-name comparison this suite has had: its
absence is what made every earlier one a total, and a total cannot tell
"nine fixed" from "fifteen fixed and six broken".
TotalandSkippedare identical to the digit across the two runs, so43 → 42is a statement about the same population: one fixed, nothing broken, and
the name is
io-52.22.1. It stays unattributed — nothing this round wasaimed at it, and inventing a mechanism to fit a number is how the earlier
rounds went wrong. That an ABI change of this size moved exactly one
test is the result the re-run existed to get.
Tk's suite:
Total 10027 Passed 8926 Skipped 924 Failed 177, clean exit.Most of the remainder is out of reach here — a second
wishprocess, an Xproperty, a system tray, a scalable font, or a constraint that fails on
Linux too. This number is also a regression that was caught and
reversed: for one build
wishshowed a white window and the suitefroze on
bell.test, the first of 97 files, and nothing in Tk hadchanged — it was
select()'s new regular-file arm answering for rio's/dev/mouse. See libap below.Failed 177is identical before andafter.
itcl builds and runs first try:
Total 792 Passed 716 Skipped 66 Failed 10, and the remaining ten are upstream's or Tcl 9's, two of them settledat source. Nothing uses stubs — Plan 9 has no
dlopen, so itcl linksstraight into
itclsh, andTcl_StaticLibraryis the load-bearing callrather than
Itcl_Init: without it the commands exist butpackage require Itclgoes looking for something to load.Two test binaries were being deleted and never rebuilt.
cmd/tclsh/tcltestandcmd/wish/tktestwereV:targets reachable fromnothing while each mkfile's clean rule named them, so
mk distcleanremoved them and the next suite run used the ordinary shell — where Tcl's
suite skips 5317 extra tests and reports 27 fewer failures. A falling
failure count beside a rising skip count is not an improvement. Both
harnesses now refuse or warn when the test interpreter is absent.
bash is
/bin/shdashis gone from the tree. bash serves everyshthe build asks for,and a full
mk distcleanplusmk installcompletes with it.Getting there was five separate bugs, and the one that mattered was
isblank('\t')answering false. bash'ssyntax.cis generated by itsown
mksyntax, whoseaddblanks()isif (isblank(uc)) lsyntax[uc] |= CBLANK;— so the shipped table gave TABCSHBRKand noCBLANK, whichmade a tab a word delimiter rather than whitespace to skip. The lexer
then returned an endless stream of empty WORD tokens, the parser appended
each to one simple command, and bash died of
Killed: Insufficient physical memoryafter about 17 million 16-byte list nodes. Everytab-indented script file. The table is corrected by hand, because it is
checked in and the mkfile compiles rather than regenerates it.
bash's own suite now runs to completion: 49 of 86 files pass, and of
the ~1015 differing lines in the rest, roughly 950 are platform limits
with no bug behind them — no
tcsetpgrp(job control), no/dev/fd(process substitution), no
dlopen(loadable builtins), no/etc, andwhole-second file times. The harness is
rc/bin/bash-runtests, whichexists because three preconditions fail silently:
THIS_SHmust name abash that exists, four helper programs must be built, and stdin must be
redirected (one test runs a command named
p, which on 9front is thepager and blocks for ever).
config.hwas wrong in both directions. Fourteen features were#undef— arrays,((,[[, extglob, brace expansion, aliases,programmable completion,
help, history expansion, the restricted shell —every one of them compiled, linked and switched off by a commented-out
line. And two capabilities were claimed and absent:
HAVE_DEV_FD(Plan9 binds the fd device at
/fd, and a/fdentry names the descriptor ofthe process that opens it, so it is useless for a child) and named pipes.
A hand-maintained capability file is wrong in both directions, and the
two kinds fail differently — a denial costs a feature silently, a claim
costs a crash.
vts
sys/src/cmd2/vtsis a VT emulator built on libvterm, served over 9P,with two front ends:
vtwin(a rio window) andvts-attach(a dumb TTY,for ssh or drawterm).
./apexp-sh -vlaunches a bash session inside it.It exists because rio speaks no escape sequences. Under vts, arrow keys
work,
$TERMisvt100rather thandumbso readline redraws insteadof reprinting, and the session has a real character grid to report as
$COLUMNS. Tab completion works under rio too, but the arrows do not —rio eats them before bash sees them, and no program can get them back.
Compiler correctness fixes
Nearly all of these produced wrong values with no diagnostic.
Converting to
booltruncated instead of comparing (cc/lex.c,cc.y,com.c)._Boolandboolwere mapped ontoLCHAR, which thegrammar turns into
BCHAR. They now have their own token and their ownType, marked withType.isbool— a field rather than the identity ofone object, because
copytyp()is a struct copy and a type is copiedwhenever it is used for a parameter or a
const. The comparison isapplied at all five places a conversion happens: cast, assignment,
return, argument passing, and auto initialisation, which has its own case
in
tcomoseparate from assignment.falsedid not evaluate to 0 (cc/lex.c).itab's third column is atype index applied as
s->type = types[...], andtrue/falsewerewritten into it as 1 and 0 as though it were a value. Nothing set
yylval.vval, which is what the grammar reads forLCONST, andyylexhad already stored a symbol pointer into the same union member — so both
keywords arrived carrying a pointer. Every
x = false,return true;and
flag == falsein every native C23 program had junk in it. APE codewas untouched, because APE's
<stdbool.h>defines them as macros — whichis exactly why no test under
sys/lib/testscould have caught it, and whytruefalse-test.cis the one native test in that directory.A fixed register was spilled at the operation's width, not the
register's (
6c/cgen.c).6cspills AX, CX or DX where the instructionit is about to emit can only use that register — a divide needs AX and DX,
a variable shift needs CX — and sized the spill slot from the operation.
A 32-bit
%therefore saved four bytes of a register holding eight. Thetrigger is
<expression containing / or %> op <64-bit function call>.Only
6chas this:8cis 32-bit, and the RISC back-ends need no fixedregister for division.
Unsigned 64-bit to floating point was wrong in both directions
(
cc/scon.c,6c/txt.c). Constant folding read the value back as signed,so
(double)(uvlong)~0was-1.0; at run time the top-bit case computedthe right answer and then never stored it. gnulib's
hash.ccomparesSIZE_MAXagainst a float, sohash_initializereturned NULL and everyprogram that hashes —
cp,mv,ln,du— died with "memoryexhausted" before looking at its arguments.
A compound literal did not zero the members its initialiser omitted
(
cc/dcl.c). C99 6.7.8p21 says an omitted member is initialised as onewith static storage duration would be.
compoundlit()lowers a literal toa hidden auto and calls
doinit(), which assigns only the members thelist names — while an ordinary
T x = {...}isdoinit()followed bycontig(), which zeroes every byte the initialiser did not cover.compoundlit()was the one caller ofdoinit()in the compiler thatnever had the second half. muon crashed before it read an argument,
because
tstr_initends*sb = (struct tstr){.flags=..,.buf=..,.cap=..}with
.lenomitted and then useslenas amemsetlength.contig()could not simply be called — its bulk arm emits a statement andeverything a compound literal builds has to survive in expression context
— so
clitzero()reuses its trims and spells the loop out asstraight-line stores.
A single
Lcapped a constant's width (cc/lex.c). The widening pathwas guarded by "no suffix", so
convvtox(vv, TLONG)threw away everysignificant bit of a constant written
0x0200000000000000L— the normalspelling on any LP64 system, and the one every upstream header uses. C99
6.4.4.1 says the opposite:
Ltakes the first of long, unsigned long,long long, unsigned long long in which the value can be represented.
Lis a floor on the type, not a ceiling. CHICKEN's fourteen headertags all became 0.
A 64-bit case type is not a 64-bit case value (
cc/pswt.c).doswitdiscarded every case whose type was wide, in a switch whoseexpression was 32 bits, under the comment "can never match" — a sentence
about a value too wide to appear, applied to a small number with a wide
type. C 6.8.4.2p5 says a label "is converted to the promoted type of the
controlling expression", so a wide label is truncated, not discarded.
Silent: the file compiled and the arm was never reached. The loud half
beside it was that the case count was taken before the drop, so
qsortand the duplicate scan ran over entries that were never written —
duplicate cases in switch 0, naming a case the program does not contain.A comma expression's type decayed, so
sizeofan array compoundliteral was the size of a pointer (
cc/com.c).compoundlit()builds(type){...}asOCOMMA(initialisation, ONAME), and theOCOMMAcasetyped its right operand with
tcom()— which istcomo(..., ADDROF), andso turned the array into a pointer.
sizeoftypes its operand withtcomo(l, 0)precisely to stop that happening, and the flag was beingthrown away one level down:
That is the standard way of counting variadic arguments, so
ARRAY_CARDINALITYover a compound literal answered 1 for any array ofpointers. bison's
muscle_kind_newuses it to size a table and aborted.A designator was resolved in the wrong scope (
cc/dcl.c). C996.7.8p17 makes a designator relative to the object of the enclosing
brace list;
init1()restarted its member walk at whatever level it hadreached. Two members of the same name at different depths were enough, and
when the two have the same type there is no diagnostic at all — the
value simply lands at the wrong offset.
auto size_t x;did not parse (cc.y).autoadlistbegan withxdecor, which reachesLNAME | LTYPE, so afterLAUTOthe parser couldshift a typedef name as the variable being declared — and yacc resolves
shift/reduce in favour of shift, so the C23 deduction path won over the
storage class.
-std=would not have fixed it: the conflict is resolvedwhen yacc builds the table, and there is no dialect disagreement to
arbitrate, since C23 kept
autoas a storage-class specifier and its typeinference applies only where
autois the sole type specifier. EDG'sgenerated C writes
auto <type> <name>;for every local — 116,079 of themacross 103 of 133 files.
6land friends can be asked for COMDAT (cc/, the ten back-ends).The linkers have always skipped a duplicate
ATEXTcarryingDUPOKandsuppressed
multiple initializationfor duplicateDATA— the onemissing piece was a way for C to set the bit.
pcc -Cis it. It isblunt and the mkfiles that use it say so: it marks every TEXT and GLOBL in
the translation unit, not the vague-linkage ones, so two genuinely
different functions of one name become first-wins rather than a
diagnostic. Safe for generated C, where every duplicate is the same entity
by construction; nothing else in the tree passes it.
Also fixed:
(
cc/com.c).E1 op= E2with a signedE1and unsignedE2did theoperation signed. Still wrong in a second way, and a larger job: kencc
performs the operation in the lvalue's own width, so
long x; x /= (uvlong)y;divides in 32 bits on amd64 where C requires64.
&(struct S){...}now works; the comma is hoisted out ofOADDR.char *againstunsigned char *warns rather than refusing. Thisis
-Wpointer-sign, which gcc and clang do not treat as an error, andportable code is full of it. One level only, and only for the five
signed/unsigned spellings of the same type.
pccforwards-aand-Z, so a layout can be read out of thecompiler;
-cis required with them, since with-athe compilerwrites acid to stdout and makes no object.
pccno longer appends-Jto every invocation as an"old/new decl mixture hack". Stock
ccnames no-J, so it fell toARGBEGIN's default and set a debug counter nothing reads — a pure no-op
for its entire life, until the letter was given a meaning.
#includenesting limit was a bare20and is nowNINCDEPTH, 200, which is what gcc and clang use — LibreSSL reaches 20on an ordinary chain with nothing repeated in it.
#elifis no longerevaluated once a group has been selected, and
#ifdoes unsigneddivision without relying on the compound-assignment bug above.
Headers and types
<string.h>reached Plan 9's<u.h>, by way ofwchar.h,time.h,signal.h,pthread.handlock.h— so asking forstrlenalso defined
nil,uchar,ushort,ulonganduint. Every link inthat chain existed for a single pointer parameter and is now a forward
declaration;
string.handwchar.hhad also been including eachother, so what a file saw depended on which it asked for first.
SIZE_MAXwas 32-bit on amd64 whilesize_twas 8 bytes, andSSIZE_MAXwasLONG_MAXwith the same problem. The cause is worthknowing because it will recur: stock APE keeps
float.h,stdarg.handstdint.hin the architecture directory, whichpccsearches before/sys/include/ape. APExp's copies were never read on any architecture.Worse for
stdint.h, whose stock copy takes the same include guard asAPExp's arch header, so APExp's compiled to nothing. All three are now
shadowed by a real file in every architecture directory.
The symptom was GNU
lsreading off the end of the heap, via a gnulibline that means "no length given" when it sees
SIZE_MAX.NAME_MAXwas 27 andPATH_MAX1023, set insys/limits.h, which<limits.h>includes at its very end and which#undefs and redefineswhat the outer file had just set. 255 and 4096 now. That file also carried
two dead values —
NGROUPS_MAX 10andPIPE_BUF _POSIX_PIPE_BUF—which were never in effect and existed only to break any translation unit
that reached the two headers in the other order.
FLT_MAXwas notFLT_MAX. C saysFLT_MAX,FLT_MINandFLT_EPSILONhave typefloat, andfloat_arch.hwrote them with noFsuffix, so each was a double holding the nearest double to a roundeddecimal —
3.4028234999999998e+38against a true3.4028234663852886e+38,about 3.4e30 too big.
Four headers could not be included from C++, every one of them a
parameter name or a keyword and so invisible to a C caller:
stdlib.h'sunguarded
_Noreturnand its parameter namedtemplate,unistd.h'sparameter named
new, andsignal.h'srestrictread as a duplicateparameter name.
restrictbecomes__restrict, which costs nothingbecause kencc lexes all three spellings to the same token; the two
parameters are renamed, which no caller can see. The obvious fix for two
of them would have been a
#defineof an unreserved name in a publicheader, which is exactly the mistake that had broken the build one round
earlier — see
reject, below.Other header work:
__BYTE_ORDERwas never defined on any architecture.O_DIRECTORYwas 0, so the whole*atfamily ignored real directorydescriptors. The
O_flags Plan 9 lacks are now defined as 0deliberately, and documented as such.
<float.h>gained the C99/C11 macros;<sys/statvfs.h>and<sysexits.h>are new;<locale.h>no longer declares two of musl'sfile-local helpers;
<stdint.h>lost theu8/u32/s8/s32typedefs that collided with everything.
<termios.h>gainedTCIFLUSH,TCOFLUSHandTCIOFLUSH, which werethe only one of POSIX's four groups absent while
tcflush(int, int)wasdeclared — a function the header promised whose second argument could
not be named.
<netinet/in.h>gained the IPv4 multicast options andstruct ip_mreq;the IPv6 spellings had all been present and the IPv4 ones had not.
<values.h>is new, and every value in it is derived from<limits.h>/<float.h>rather than transcribed.getoptwas declared incompatibly in two installed headers;bsd.hnowmatches
getopt.hand POSIX.tcl.hhad beeninstalled alone while its line 2433 includes
tclDecls.h, which was notinstalled at all — so
#include <tcl.h>from outside Tcl's own buildhad always been a fatal error on the first line.
S_IXUGOis spelled the way everyone else spells it. Macro identity inC includes whether there is white space between tokens, so a
definition differing only in spacing is a redefinition error.
Before adding any name to a public APE header, grep
external/for thebare word. Declaring
rejectinlibnet.h— which<sys/socket.h>includes — broke flex, whose
flexdef.h:366hasextern int reject;, avariable. A function-shaped grep cannot match a variable. A public
header's blast radius is every package in the tree, and no instrument here
measures that:
apehdr-sweepcompiles the APE headers against each other,while that collision arrived from a package's own header.
libap
posix_spawnhonours file actions and attributes. It was fork+execwith everything discarded, so
posix_spawn_file_actions_adddup2()returned 0 and did nothing. Undetectable by the caller, and gnulib's
spawn-pipe.cwires its pipe to the child entirely throughadddup2.vsnprintfleft the buffer untouched when it formatted nothing,and reported a truncated length when it ran out of room. It was built
on
fmemopen, whose write hook only lays down the terminating NULafter a write, so
snprintf(buf, n, "%s", "")returned whatever thebuffer held before; and the same hook's short write at the end of the
buffer made the return value the length written rather than the length
that would have been (C99 7.19.6.5p2 and p3), which quietly breaks
measure-allocate-format-again. musl's own implementation replaces it.
GNU m4's
format()is what found it, and every parser bison generatedhad a doubled comma after each token as a result.
printfdid not know%td,%jd,%hhdor%F. An unrecognisedconversion prints the letter and consumes no argument, so
printf("%td", n)printed the literal texttdand leftnin theva_list— every conversion after it in that format string took thewrong argument. diffutils has
#define pI "t"and prints every linenumber through it, so every diff position line on this system had
always been garbage:
1,2d0came outtd\x01tddtd.%gwith aprecision of 0 and the
0flag beside a precision were wrong too; aprecision of zero is a specified precision, and the test read
precision <= 0.vfscanfhas handled all three length modifiers since it waswritten. The library knew these on the input side and not the output
side.
strftimewas missing fifteen conversions —C D e F G g h n r R s t T u V— with the same silent failure mode: thedefault:arm writesthe conversion character out as a literal, so
%FprintedF. And%cand
%xwere wrong rather than missing, against POSIX's fixed C-localedefinitions.
strerrorwas wrong in 40 of 76 entries, and two named the wrongerror. The table said
EACCES "Access denied"andEPERM "Permission denied"— andPermission deniedis what every other system prints forEACCES. So the one message a reader is most likely to recognise
named the wrong errno, and anything matching on it drew the opposite
conclusion. The other 38 were merely terse. The table is generated
from
errno.hand glibc rather than transcribed, and every row nowcarries its name.
strtodis Gay's now, and correct. The file it replaced was wrongon 148018 of 199887 round-trips (74%) and said so in its own first line
for as long as it existed. Four of the six bugs were in the shared Bigint
kit, and all four are one sentence: Gay's arithmetic needs a 32-bit word
and spells it
long— true under kencc and false under gcc, so the codewas correct on Plan 9 by accident. One of those four also broke
_dtoain the shipping printf path, where subnormals printed as
?.strtofneeded more than(float)strtod: rounding to 53 bits and thento 24 is not rounding to 24, and 12709 of 39694 decimals built to sit on
a float midpoint came out wrong.
scalbnhad2^1023where musl writes0x1p1023— an integerexclusive-or, 1021.
scalbnf.chad the same with 127. Every subnormalany program reached through
ldexpwas wrong, some with the wrongsign, and the host cross-check that had passed
scalbnused anexponent window that never entered the broken branch.
mktempcould produce 26 names per process, ever. It wrotegetpid() % 100000into five of the six X's and tried one trailingletter
a..z.mkstemp's twenty retries re-derived the sametwenty-six, since nothing in them varied — a retry is only a retry if
something varies between the tries. The right generator, musl's
__randname, was already in the same directory and already in OFILES.getcwd(NULL, n)killed the process. It passed its argumentstraight to
_FD2PATHwith no null check, so the POSIX.1-2008"allocate it for me" form — which a great deal of GNU code uses — handed
the kernel address zero. bash had already detected this and shipped its
own fix, and the link order threw it away.
umask()discarded its argument and always answered 0. libap is thecode that chooses the permission it hands
_CREATE, at exactly twouser-facing sites, so storing it is not inventing semantics — and it
composes with the file server rather than fighting it, since Plan 9
already hands out
perm & (dirperm | ~0666)and a umask may only everremove bits. The initial mask is 0, not 022: a conformance fix should
not also be a default change.
dup()anddup2()refused any descriptor that had beenselect()ed. Both are one line offcntl(.., F_DUPFD, ..), whosebuffered-descriptor arm answered
EGREG. A descriptor becomes bufferedthe first time anything selects it, so any program with an event loop
had lost the ability to dup the descriptors it was watching — select
being how an event loop works and dup being how a shell redirects.
readdirreturns.and... Plan 9 directories contain neither,so
glob .*was missing them and two independent suites said so. Theinodes are real rather than 0 —
.from the stream's own descriptor,..throughfd2path— becausefind's loop detection, the classicgetcwdanddu's hard-link check all readd_ino. No new field, sosizeof(DIR)does not move.regcompaccepts[[.x.]]and[[=x=]]. There is no collationtable anywhere in TRE — the engine compares encoded values — so the C
locale is what every comparison already implements, every equivalence
class is a singleton, and a collating symbol naming one character is
that character. A multi-character element still answers
REG_ECOLLATE,and an equivalence class is refused as a range endpoint, because it
names a set and so has no position in the order.
random,srandom,initstateandsetstateexist, bit-compatiblewith glibc and 4.4BSD deliberately: a seeded sequence is something
programs reproduce across machines, so "a generator with the right
distribution" is not the specification — the numbers are.
isblank('\t')is true, andisprintis a function.isprint'smask was
(graph bits | _ISblank)and used_ISblankas a stand-in for"space", correct only while space was the sole character carrying it.
strtoull's overflow threshold was effectively disabled(
1LL<<63isLLONG_MIN, and the signed division that followed gave anegative quotient),
strtoll(LLONG_MIN)answeredERANGEfor a valuethat is exactly representable, and
strtoX("0x")with no hex digitreported no conversion where C says the subject sequence is the longest
initial subsequence of the expected form.
close()on a listening socket freed nothing.listen()replacesthe descriptor with a pipe and forks a child holding the real network
fd, so
close()shut a pipe while the announcement lived in anotherprocess. This was the hundred leaked
listenprocprocesses. The pidis recorded keyed on
dev/inorather than on the descriptor number,because
dup2()and raw_CLOSE()retire a number without clearing —and a stale entry SIGKILLed the wrong process and froze a suite.
socket -asynchas never worked, and now does:connect()on anO_NONBLOCKdescriptor forks to do the ctl write and returnsEINPROGRESS, the child reports its errno down a pipe, andgetsockopt(SO_ERROR)— which returned a hard-coded 0 — gives the realanswer.
execve()destroyed the caller. POSIX: "If the execfunction returns to the calling process image, an error has occurred;
the process image is unchanged." libap's did the opposite —
_RFORK,then
/env/_fdinfoand/env/_sighdlrrewritten, then everyFD_CLOEXECdescriptor closed, all before_EXECwas tried. It nowopens the file
OEXECfirst, which is the same question Plan 9's ownexec asks, and the closes moved to immediately before the exec.
FD_BUFFEREDbecomesFD_BUFFEREDXin a forked child, andexecvewrote the flags wordverbatim into
/env/_fdinfowhere the new image applied it verbatim —so any program started by an APE parent that had ever selected on a
descriptor inherited it unreadable.
FD_BUFFERED/FD_BUFFEREDXarefacts about a process image, not about a descriptor.
select()does not poll: it forks a process that reads continuously for the life
of the caller, so an interactive bash permanently read its window's
/dev/consand partitioned the input with its own parent. For a tty thecopy process now sleeps unless a read has been asked for.
tcsetattron a real/dev/consreturned 0 and changed nothing,while
tcgetattrreported a hardcodedICANON|ECHOwhatever theconsole was doing — so readline asked for raw, was told it got it, and
waited for keystrokes the driver was holding until Enter. Both halves
silent.
plan9/tty.cnow owns the one switch Plan 9 offers(
rawon/rawoffon/dev/consctl) and termios drives it.$TZreached nothing.tzset()parsedgetenv("timezone"), Plan9's spelling, while
localtime_rseparately read/env/timezoneonceper process into a static of its own, and neither had heard of
TZ.Nothing set
tm_gmtoff/tm_zoneeither, sostrftime's%Zwas ahardcoded
{"EST","EDT"}under a comment reading "hack for now: assumeeastern time zone", and
%zdid not exist.time/tzone.cis the singleengine now — POSIX TZ strings with DST rules,
/env/timezoneas thefallback, UTC with an empty name when neither parses.
rename()of a directory into a different directory always failed(the cross-directory copy path opened the destination for writing, and a
directory cannot be), and a directory moved into itself is now detected
by qid up the tree rather than by string.
objc's scanner is theonly thing in the tree that runs flex, so it had never worked here,
and it uses all three within twenty lines.
fseekset the errorindicator when the seek failed — C99 7.19.9.2 says it returns
nonzero and nothing more, and a stream you cannot seek is not a stream
that has failed; a pipe is unseekable, so probing one poisoned it for
good.
freopenreturned a new stream instead of reopening the oneit was given (7.19.5.4), which on a permanent stream did nothing at
all, leaving
stdouton the terminal.fclosedid not close thestandard streams —
F_PERMmeans theFILEis static, not that thefile stays open (7.19.5.1), so closing
stdoutto signal end of inputto a pipeline silently didn't.
ungetcrefused a stream that had not been read from yet, againstC99 7.19.7.11's guarantee of one character of pushback.
isattyfollowed a stale flag, not the descriptor, so a descriptorthat was the console in the parent and a pipe in the child still claimed
to be a terminal.
sigset_theld three signals.sigaddset/sigdelsetwere gated ona mask built by ORing signal numbers together, so only 0, 1 and 2 were
accepted;
sigfillset()produced a set naming SIGHUP and SIGINT alone.signal()is prototyped. It had been the unprototypedvoid (*)()so that libap's three-argument Plan 9 dispatch stayedreachable — a public declaration that turned off argument checking for
every caller in the tree. The extension is unchanged and still
dispatched; the cast lives at the one place that calls a handler.
execvpsearchesPATH. It prepended/bin/and gave up.setlocalereports the locale it set. It ignored the name andanswered
"C.UTF-8"to everything.getprogname()returnedargv0— lib9's global, filled fromARGBEGIN, an rc idiom no APE program executes. So it was NULL unlessthe program happened to call
getopt_long, which set it as a sideeffect, and gnulib's
error()is#define program_name getprogname().Every GNU program in the tree printed its diagnostics with no program
name.
argv0is set inplan9/callmain.cnow, the one path every APEprogram takes.
path, so a regular file reported "would block" and an empty one said
fblocked 1, eof 0for ever. POSIX:O_NONBLOCKdoes nothing to aregular file.
i/o on hungup channelmapped toESHUTDOWNwhere POSIX wantsEPIPE._unlockedfamily is real. It existed only as four macros inmusl's internal header, visible by accident through the
<stdio.h>leak. All fifteen are functions in libap now.
timespec_get,fdopendir,initgroups,arc4random_uniform,__fpurge,strerrorname_np,ESTALE,EDQUOTand the tail ofsys_errlist,IFTODT/DTTOIF,DT_WHT.st_rdevwas 0 for every file, and it madecmpsilent. gnulib'ssame_filetreats two character specials with equalst_rdevas thesame device and therefore the same contents, so with a constant every
char special matched every other.
cmpasks whether its own stdout is/dev/nullin order to skip describing a difference nobody will read —and under a terminal stdout is
/dev/cons, a char special, so cmpcompared two plainly different files and printed nothing, with only
the exit status still correct.
diff -rhad the same fault atdiff.c:1300, reporting every pair of special files identical withoutreading them.
_dirtostatnow setsst_rdevto the qid for thecharacter and block cases and leaves it 0 elsewhere, which POSIX permits
and which is true of Plan 9: two char specials are the same device if
and only if they are the same file.
rdev-test.cis the regressiontest.
ino_tanddev_twere 16 bits, andstruct statis now 104 bytesrather than 88.
_dirtostatassignsst_ino = d->qid.path, so everyinode was a 64-bit qid truncated to sixteen bits and two unrelated files
compared as the same file once a server held more than 65536 of them —
the APExp tree alone is 64799. Everything that identifies a file by
dev+ino was exposed:
same_filein diffutils,find's loop detection,du's hard-link accounting,fts,tar, and libap's own listenertable. This is the release's second ABI change and the
mk distcleanthat-Jalready required covers it. Two things it correctswithout being touched: musl's
<sys/sysmacros.h>, whosemajor/minor/makedevalready assumed a 64-bitdev_t, and perl'sconfig.h, which already declaredST_INO_SIZE 8.poll()obeys three POSIX rules it did not. It returnedselect()'scount of ready bits across three fd_sets where POSIX wants the number
of pollfd structures with nonzero
revents; it skipped a negative fdwhen building the sets and not when reading them, so
FD_ISSET(-1, ...)read out of bounds and the result became a
reventsthe callerbelieved; and it had no
POLLNVAL, so one closed descriptor failed thewhole call instead of marking that entry. The first two can make a
caller spin rather than merely get an odd answer — a loop of the shape
while(true){ if(poll(...)==0) break; if(pfd[0].revents) break; }neversleeps when poll returns positive without marking the entry watched.
poll-test.cis the regression test.select()reports a regular file readable, as POSIX requires — andthe predicate for "regular" is
_selregular(), notS_ISREG(), whichis a whole bug on its own. libap's
selectbuffers every watcheddescriptor through a copy process and answers from what that process
has collected, so a regular file came back not readable until the
first read completed, though POSIX says one is always ready and cannot
block. The fast arm reports it ready without buffering it — which is
sound only for a file that genuinely cannot block, and on Plan 9
S_IFREGdoes not say that._dirtostathas no device-type bit toread, so it takes
Dir.type: a directory, then|andsfor pipesand sockets, then anything that is not
Mis a character special, andeverything left, meaning every file reached through a 9P mount, is
called regular. rio serves
/dev/cons,/dev/mouse,/dev/winnameand
/dev/snarfthat way. The first version of this fix usedS_ISREG()and left wish showing a white window, frozen on the firstof Tk's 97 test files, because Tk polls the mouse with a zero timeout
and then does a blocking read of whatever select marks.
_selregularadds a positive length, which no Plan 9 device file has and no file
whose readiness matters lacks; an empty regular file falls back to the
buffered path, whose bug is a race and not a wrong answer.
sys/lib/tests/devreg-probe.cmeasures it, and Tk's suite is back toFailed 177, identical to the pre-regression run.pthread_createnever ran the thread, and three bugs said so atonce. Nothing in the tree had exercised it until
xz, which ismultithreaded (
liblzma/common/stream_encoder_mt.c)._RENDEZVOUS(tag, 0)and the parent neveranswered — that was the only
_RENDEZVOUSin the whole threaddirectory. So every thread ever created blocked before reaching its
start routine, while its creator was told the call had succeeded.
The handshake is not decoration:
pthread_exitasserts_pthreadget(pthread_self())andpthread_joinlooks the thread upthe same way, so the parent has to register the child's pid first —
and
_pthreadsetpidalready existed with no callers anywhere.*twas never written, so every caller handed whatever was onits stack to
pthread_join.attr != NULLreturned EINVAL, and libap's ownpthread_cond_timedwaitalways passes one, so it returned EAGAINwithout ever waiting, on every call, for its whole existence. A
caller that loops on it — xz's
wait_for_work— becomes a busy-waitmade of
clock_gettimesyscalls, which on Plan 9 is a_PREAD.That is why the system figure sat at the maximum while the user
figure did not.
All three are fixed. Every
pthread_attr_*remains a no-op anddetachstatein particular is not honoured — accepting the structsays only that; rejecting it never made detachstate work, it only made
the call fail.
sys/lib/tests/pthread-test.cis the regression test andis the first here that can hang, so the first that arms a
SIGALRM.fsync()answered failure, and xz deleted every file it wrote. Itwas
errno = EINVAL; return -1. xz'sio_sync_destturns a nonzerofsyncintosuccess = falseandio_close_dest(pair, false)thenremoves the destination;
opt_synchronousis on by default, sothis was every
xzandunxzon a named file, every time — the bytescorrect, written, and thrown away on the way out. Nothing in
"Synchronizing the file failed" says "your output is gone". This is
the stub-answers-failure family, and libap already held the right
answer in a second place that disagreed with the first:
plan9/__p9_syscall.creadscase SYS_fsync: /* Plan9 writes are synchronous; no-op is correct */ return 0;. Plan 9 has nofsyncbecause a write to a file server is already acknowledged when
writereturns; there is no local cache to flush. It answers 0 for an open
descriptor and EBADF otherwise — a function that cannot fail is its
own kind of lie, which is why
fsync-test.chas a section for aclosed descriptor as well as an open one.
gnulib
One shared
libgnu.anow serves coreutils, tar, diff, patch, grep, sed,m4 and bison, with a
config-common.hplus a per-packageconfig.h.Roughly forty modules were added over the release for the new packages,
and a dozen dropped because libap supersedes them.
The rule that matters when adding one: gnulib's replacement system
headers are not used — they shadow APE's — so a module that needs a
declaration needs it in the real header.
And a module libap already provides is a problem whether or not
arsays so.
strerror.$Owas inlibgnu.a, and gnulib'sstrerror.cdefines the plain name and then calls
strerrorexpecting to reach thesystem's — an arrangement that works only because gnulib's generated
string.hcarries#define strerror rpl_strerror. Nothing generatesthose headers here, so the function called itself for ever and every GNU
program in the tree died with a stack fault instead of a message, reading
as a different bug every time. The idiom (a definition of NAME followed by
#undef NAME) is in 34 places across 24 files in that tree, and exactlyone of them was in OFILES; the sweep for it is rule 6 of the directory's
README so that it can be repeated when OFILES grows.
Testing
The tests in
sys/lib/testsare standalone programs. Each printsPASS/FAILper case, exits with the number of failures, and opens witha comment recording which bug it came from and what that bug cost:
Anything testing a language or library rule should also be correct on
gcc, and checking a new test against gcc first is how you find out
whether the test or the tree is wrong. It has caught both.
Five kinds of thing live in that directory and they are not
interchangeable:
operating system's own behaviour is a probe, not a library rule.
devreg-probeis the one with no host form at all: its subject iswhat rio serves, so a Linux build would measure a machine that has
neither rio nor
/dev/mouse.says whether it gates the build.
check its arithmetic on the host — they exist because kencc's own
sources need Plan 9's
<u.h>, so the first build of any compilerchange is the VM's.
VM. The strongest pattern here is to link the unit under test into a
glibc program beside the reference implementation:
tz-xcheck.cswept 1.4 million instants against
localtime_rand found two bugswith no VM round at all. It applies to anything that is a pure
function of its input, and it is how
strtod,strtof,_dtoa,strftime,strtoll,random,regcomp's collation,ctypeandstrerrorwere all settled.A control is part of an instrument, not an optional extra. A check
that cannot fail is not a check, and several here passed for the wrong
reason before anyone looked:
poll-test's section 1 originally used apipe, whose read end is never writable, so the defect it was written for
was unreachable. The habit that catches it is to replicate the replaced
code beside the new and confirm the instrument notices —
poll-testreports 4 that way,pthread-test3,fsync-test1,bitinit-model --old6 of 7.And no output is not a pass. A fault, a kill and a clean finish all
just give the shell prompt back.
pthread-testandfsync-testsetline buffering and print a marker before their first real call for that
reason, and
pthread-testarms aSIGALRMthat names the section itdied in — it is the one test here that can legitimately hang.
Several carry a version marker —
_sock_listenmark(),_execmark(),_ttymark(),_getcwdmark(),_printfmark(),_dupmark(),_dotdirmark(),_tempmark(),_fdinfomark(),_umaskmark(),_bufmark(),_rdevmark(),_selregmark(),_pthreadmark(),_syncmark().pcc -o x x.crelinks against the installed libap, soa test built from a fresh pull can run days-old library code and say
nothing. A marker makes that a link error instead. The idiom has paid
eleven times, and it matters most where the bug's whole symptom is that
nothing is printed.
sys/src/ape/lib/libressl/testis separate: upstream's own ML-KEM andSHA-3 known-answer vectors, run with
mk test.Known limitations
Everything here is recorded and not fixed. Where something has been
measured, the number is given; where it has not, it says so. That
distinction is the point of the list.
Platform limits — not bugs, and not fixable here
dlopen. perl has no XSextensions, bash has no
enable -fand no loadable builtins, andanything that probes for shared-library support gets a truthful no.
tcsetpgrpand notcgetpgrp— absentrather than stubbed — and Plan 9 has no controlling-terminal foreground
process group to give them meaning (
setpgidanswers ESRCH,setsidreturns
getpgrp()). bash is built withJOB_CONTROL_MISSINGdefined,which says which kind of off it is.
symlink()isENOSYS. Donot emulate it with a copy.
link()answersEMLINK, which is correct, because<sys/limits.h>declaresLINK_MAX 1and POSIX saysEMLINKis what alink past
LINK_MAXgives.mkfifo()isENOSYS./dev/fd. Plan 9 binds the fd device at/fd, and a/fdentrynames the descriptor of the process that opens it — so handing the
name to a child, which is the whole point of
<(...), names the child'sown descriptor. Process substitution is off for that reason and should
stay off. Do not invent semantics to make a feature compile.
Dir.mtimehas no nanosecondsand
dirtostat.csets everytv_nsecto 0. Anything sorting files bya sub-second timestamp cannot be made to work here.
O_APPEND. 9P'sTwritecarries an explicit offset and there isno write-at-end request, so libap emulates it with a seek in
open()and another in
write()— two calls with a window between them.Measured: four processes appending flat out lose 1280 of 2050 bytes;
one writer in the same loop is exact. Plan 9's one atomic append is
DMAPPEND, a permanent mode bit on the file, which is not whatO_APPENDmeans for a descriptor.ip/ipconfig loopback /dev/null 127.1has beenrun, and that belongs in the machine's startup rather than in
apexp-sh.~USERcannot be expanded.unixFCmd-1.1-shaped: walking through a mode-0 directory answers"does not exist" where POSIX wants
EACCES. The file server's choice.Compiler
static bool b = 256;still truncates. A file-scope initialiser isfolded in
dcl.cwithout going through the conversion path. An autobool b = expr;is correct.it means rewriting
E1 op= E2asE1 = (T1)(E1 op E2).typeof_unqualdoes not strip qualifiers,_Alignashas no layouteffect, and
_Atomicis dropped as a qualifier.__threadis silently dropped (cc/lex.chas a swallow list; Plan 9has no TLS). That is right for single-threaded programs and a live
hazard for anything else: EDG's
__thread_needed_destruction_headbecomes one process-wide global shared by every thread.
9ldeclaresdupokand never reads it — zero hits in its.cwhere every other linker has two — and
1l/2lhave no such field atall. A pre-existing gap, found by the COMDAT change and not closed by
it; on those three targets the back end now diagnoses instead of setting
a bit the linker ignores, because a flag that silently does nothing
produces a link failure that looks like a different bug.
pcc -Cis blunt, as above: first-wins for two genuinely differentfunctions of one name. The precise version is
cclearning__attribute__((__weak__)).%a/%Ado not exist inprintf, and_dtoahands back"Infinity"and"NaN"where C wantsinfandnan— which is alsowhy
%Fdoes not upper-case them, since that would turn one wrongspelling into another.
libap
S_ISREGon Plan 9 is a fallback, and one place still relies on itbeing more.
_dirtostathas no device-type bit to read, so it takesDir.type: a directory, then|andsfor pipes and sockets, thenanything that is not
Mis a character special — and everythingleft, meaning every file reached through a 9P mount, is called
regular. rio serves
/dev/cons,/dev/mouse,/dev/winnameand/dev/snarfthat way, so all four answerS_ISREG.This release's
select()fix reported a regular file readablewithout arranging for anything to read it, which is sound only for
a file that cannot block — and it left wish showing a white window,
frozen on the first of Tk's 97 test files, because
PollP9Eventspolls the mouse with a zero timeout and then reads it.
_selregularnarrows the predicate by length (a Plan 9 device file reports 0; an
empty regular file falls back to the buffered path, whose bug is a
race and not a wrong answer). Believed fixed and NOT yet measured;
MEASURED AND CLOSED:
devreg-probereports/dev/mouseand/dev/consasREG size 0and not ready, while/dev/winnameand/dev/snarf-- alsoREG size 0-- come back READABLE, which is thecopy process answering truthfully for the two that have data and the
two that block. Tk's suite is back at
Total 10027 Passed 8926 Skipped 924 Failed 177,Failedidentical to the pre-regressionrun. The mechanism was confirmed from both ends: the prediction that
/dev/mousewould answerS_ISREGheld, and the window draws again.What remains recorded rather than fixed is that
/dev/consanswersREGtoo --FD_ISTTYis not set on a freshly opened one -- soGNU grep's
SAME_INODE-against-stdout check now runs against theterminal instead of being skipped. Not measured.
pthread_attr_*are no-ops, anddetachstateis not honoured.pthread_createaccepts a non-nullattrnow -- it used to answerEINVAL, which meant
pthread_cond_timedwait, the one caller inlibap, never waited at all -- but accepting the struct is all it
does. A thread created
PTHREAD_CREATE_DETACHEDstill leaves aWaitmsgfor somebody to collect. Rejecting the attr never madedetachstate work; it only made the call fail.
posix_spawnpdiscards theenvpit is handed.spawn()testsusepathfirst and the child callsexecvp, which passesenviron.POSIX says
envpis the child's environment either way. Tcl'sexecisthe caller. Not measured.
wait4'sWNOHANGpath can block. When_dirstatreturns nil itfalls through to the blocking
_WAIT()withWNOHANGset, and the samehappens when the pending message belongs to a different pid — which is
what a bare
waitandwait -ndo.ioctl(FIONREAD)stores*(long*)argwhere every caller passes anint *, writing eight bytes and smashing four of the caller's frame._startbufnever checks its_RFORK. A failed fork leaves theparent waiting for ever on a rendezvous with a process that does not
exist.
select()'s rendezvous — a copy process reachingEOF before the parent sets
selwait. Recorded, never reproduced.select()forks a processthat reads the same open file, so after a fork or an exec the parent's
copy process may already hold bytes the child asks for;
bufexec-testmeasuresEWOULDBLOCKwhere glibc reads all six seededbytes. Inherent in select() being a copy process.
dupof a buffered descriptor does not share a read position.Bytes already drained into the
Muxbufare not visible through the newdescriptor, where POSIX says two dups of one open file description
share everything. There is nowhere to put them, and the dominant use of
dup — a shell saving a descriptor to restore later — never reads it.
umaskdoes not surviveexec. The mask lives in the process image;carrying it over means another
/env/variable beside_fdinfoand_sighdlr.umask-testsection 4 is a probe that measures the gaprather than asserting it.
mktimenever writestm_zone,tm_gmtoffortm_isdstback.glibc and the BSDs set all three, and gnulib's
mktime_zis writtenaround that. A conformance gap, recorded as one.
datecrashes after printing the right answer. The fault is instrftime's%sarm, andlstk()named the pointer:zone = 0x834383635, whose bytes are the ASCII text4865— achar *holding digit text, the third time in this tree a pointer has contained
characters. Open, and the
mktimegap above sits directly under itwithout closing the chain.
strtol/strtoulhave the same one-limit-for-both-signs shapestrtollhad, sostrtol(LONG_MIN)is likelyERANGEtoo. They cannotbe swept by cross-check — kencc's
longis 32-bit and the host's is 64,so the two sides disagree about the right answer by construction — and
they are untouched for exactly that reason.
unlink()of a directory reportsEPLAN9where POSIX allowsEPERMorEISDIR.tcflushaccepts its argument and does nothing. That is right forthe kernel and questionable for this library, whose select() copy
process does hold unread bytes a conforming
TCIFLUSHwould discard.Nothing has measured it.
EGREGreadsUnknown error, which is also what the fallbackreturns for an errno out of range — so the two are indistinguishable
from outside. It is APE's own error (Plan 9's "ken has left the
building") and glibc has no counterpart to copy a wording from.
fts.c:600computesnlinks = fts_nlink - 2, assuming a directory'slink count includes
.and.., whiledirtostat.csetsst_nlink = 1always — so that arithmetic has been giving −1 here all along. Found on
the way to the
readdirchange and independent of it.lib.hdeclares_notehandler(void *, char *)andsignal.cdefinesit
(Ureg *, char *). Both sides are right: the declaration matches_NOTIFY, which is Plan 9's ownvoid *, and the definition matcheswhat the body does. Whichever side changes, one needs a cast.
globcannot produce.and..from a pattern that names themliterally — fixed for
.*, butfilename-14.9-style literal caseswere never the question.
${#GROUPS[@]}is 0 while${GROUPS[0]}has a value in bash, whichis bash's dynamic getter rather than ours. Noted because it looks like a
libap
getgroupsbug and is not.Headers
<stdio_impl.h>is musl's internal stdio header, installed public,reached by six
stdio/*.c. Same shape asfeatures.h'shidden, andmoved only when a victim is found — none has been.
<stddef.h>typedefswchar_t, which is a built-in type in C++. Theone surviving error when the public headers are included from C++; the
same unit compiled as C is clean.
<regex.h>and<pcre2posix.h>both defineregex_t, and<f2c.h>definesmin/max/abs/complex. Both are designintent: the first pair are alternatives no program includes together,
and
f2c.his installed public solely so that a user compiling f2c'soutput gets
#pragma lib "libf2c.a". They are the eight errorsapehdr-sweep's together-case still reports, and it deliberately doesnot gate on them — failing on an untriaged list makes a sweep cry
wolf.
sys/src/ape/lib/apsetsHFILES, so editing a header rebuildsnothing;
mk cleanfirst. (Thirteen packages underexternal/hadthe same gap for their own
config.hand were fixed; libap was not.)the list of 31 against both include directories rather than one at a
time.
<iso646.h>was a fifth and is written now — EDG's wholeinclude_c99directory is that one file, which is how it was noticed,and it is C95 rather than C99 despite where it lives. What remains:
<stdalign.h>and<threads.h>(C11),<stdbit.h>and<stdckdint.h>(C23). They are not one item.<threads.h>is alibrary question — C11 threads over the pthread layer, which is itself
under development — while the other three are compiler-coupled:
alignas/alignofneed_Alignasto have a layout effect, which itdoes not here, and the C23 pair need
__builtin-level support. Nothingin the tree includes any of the four; recorded rather than stubbed,
because a header that declares what the compiler cannot do is the
capability-present-and-not-declared bug with the sign reversed.
sys/include/ape/c++is EDG's language-support set, sixteen filesplus
experimental/meta.stdh, committed copies ofexternal/edg/include_c++— which is the arrangementsys/include/ape/X11,tcl.h,tk.handf2c.halready use, and itmeans the headers reach the VM through git alone. There is still no
C++ standard library; these are the headers that need front-end magic
(
<new>,<typeinfo>,<exception>,<stdexcept>,<initializer_list>,<compare>,<coroutine>,<source_location>,<stdfloat>,cxxabi.h), andlibedg.ais the matching ABI runtime.Most are
.stdh, which only cpfe resolves —include_file_suffixesis"::stdh:"— so no other compiler reads them andapehdr-sweep, beingtop-level only, never sees them. Two copies of a header can drift, so
sys/include/ape/c++/READMEcarries the one-command check, with emptyoutput as the pass.
Cfront's seventeen pre-standard headers used to be here, and two
names collided —
new.handstdexcept.h, the first under the sameinclude guard
__NEW_H— so order alone decided which a program got.That is why the two sets could never have shared the directory.
xzHANGS, AND THE CAUSE IS NAMED: libap'spthread_create.xz -con a seven-byte text file went to high load and never returned.Two rounds went to
poll,selectandO_NONBLOCK— xz uses allthree and none was the fault — and the
select()regular-file fix wasoffered as a candidate with a refutation condition attached, which
fired. The one fact that survived was the shape of the load: the
lfigure lower but
spinned at the maximum, and a pinned systemfigure is a syscall loop. That reading was right, and
psplus twoacidstacks then named the cause outright.xz is multithreaded (
liblzma/common/stream_encoder_mt.c), and thepthread layer had three bugs:
pthread_createdid a_RENDEZVOUSthe parentnever answered — that was the only
_RENDEZVOUSin the wholethread directory — so every thread ever created blocked before
reaching its start routine, while its creator was told the call had
succeeded;
*twas never written, so every caller handed rubbish topthread_join;attr != NULLreturned EINVAL, and libap's ownpthread_cond_timedwaitalways passes one, so it returned EAGAINwithout ever waiting — and
wait_for_workis a loop, which makeseach turn a
clock_gettime, which on Plan 9 is a_PREAD. A spinmade of syscalls, which is exactly the pinned
sfigure.All three are fixed.
sys/lib/tests/pthread-test.cis the instrument —the first test in this tree that can hang, so the first that arms a
SIGALRM— 0 failures on gcc and 3 on the replaced code,reproducing xz's spin on the build host.
AND THE CLAIM THAT lz4 AND xz SHARE NO MECHANISM IS WITHDRAWN. That
grep asked about
poll,selectandO_NONBLOCK; it was true and itanswered the wrong question. lz4 has
programs/threadpool.c, iscompiled
-DLZ4IO_MULTITHREAD, and linksthreadpool.$O. A workerthat never reaches its start routine is exactly "froze and left an
empty output". A grep that finds nothing has ruled out what you
grepped for and nothing else.
BOTH ARE MEASURED NOW AND THE REFUTATION CONDITION DID NOT FIRE.
xz -c <sample.txt >/tmp/t.xzreturns and writes 72 bytes;unlz4returns with an error instead of freezing. lz4 was wedged on the same
mechanism, so the two hangs were one bug after all.
And then
fsyncdeleted the output.unxz /tmp/t.xzdecompressedcorrectly and printed
Synchronizing the file failed: Invalid argument. libap'sfsyncwaserrno = EINVAL; return -1-- thestub-answers-FAILURE family, with the right answer already written in a
second libap file that disagreed (
plan9/__p9_syscall.c:594, "Plan9writes are synchronous; no-op is correct"). xz turns a nonzero
fsyncinto
success = falseandio_close_dest(pair, false)removes thedestination, and
opt_synchronousis on by default, so this wasevery
xz/unxzon a named file, every time. Fixed;fsync-testis 0on gcc and 1 on the replaced line. Not yet measured on the VM.
What remains is two decode failures, and neither is separated.
unxz xz_sample_file_1MB.xzanswersCompressed data is corrupt;unlz4 sample.txt.lz4answersError 26 : LZ4F frame decoding could not complete: invalid frame,Decompressed : 0 MiB. Both files camefrom elsewhere, so each has two explanations -- a bad download, or a
path only those files reach -- and nothing local has been round-tripped
to tell them apart.
The positive result is hidden inside the sync error:
unxz /tmp/t.xzreachedio_sync_dest, which runs after decoding, soencoder and decoder already agree on a small file. The two
discriminators are a local round trip at 1MB, and
-T1against thedefault
-T0, since the threaded encoder is ground nothing in thistree has ever covered -- a fix that makes a process reach code it
never reached before can expose anything on that path. Deferred to
0.7 either way;
zstdis untested (lib/common/pool.cputs it in thesame position),
unarjlists a 1MB archive correctly, and unrar, unaceand clzip are untried.
pcc -9is not available as an A/B, since onepackage under the old layout rule against a
-Jlibap is a silent ABIsplit.
One instrument note worth keeping:
ratrace -c "cmd args >file"does not run the command. It execs the whole string as a single
argv[0]and answersfile does not exist: '/bin/xz -c <sample.txt >',so a session that reports "cannot reproduce" from that line has
measured nothing.
psandacidon the pid are what worked.Ports not in the default build
further in —
boolas a kencc keyword, a missing-cin the mkfile,and Makefile backslash escaping that mk does not share — and the fourth
is structural:
cmd/distis compiled with-DPLAN9, which selectsplan9.cand its<u.h>/<libc.h>, under a compiler that has neither.The portable arm is already written:
unix.cis 843 lines of POSIXand every one of its nine includes exists in this tree. The macro is
doing two unrelated jobs — choosing the portability file at compile
time, and standing for
gohostos == "plan9"at run time in six placesin
build.c— and only the first is wrong. The change is one#elifarm in
unix.c's compile-time chain plus a new-Din place of-DPLAN9. Not started.configurerather thanthe compiler. Its
configureprints5: Bad file descriptoronhundreds of lines — autoconf keeps
config.logon fd 5 — so the closingC compiler cannot create executablesis the verdict of a configurethat could not write its own log, and is not a statement about
pcc.The construct itself is cleared:
execfd-test.shreports 0 failuresacross all eleven sections on 9front, including a forked-and-exec'd
child, the shell re-execing itself (which is configure's own first act)
and fd 5 held across 300 forks. The plan is to stop running
configureat all — a hand-answered
config.hplus an mkfile, as perl and bashalready have. The honest size of that:
lisp.runis the tractable half,and the memory image is a second half, since CLISP compiles its own Lisp
sources with the interpreter it has just built. Not started.
overloads apart on a 64-bit target, reproduced character for character
by a host gcc build — a fault both compilers reproduce is upstream's,
not this tree's — and once the struct-layout work had extracted the
last kencc bug from it, it stopped being a bug-finder.
cmd/cfront,cmd/c++lib, the seventeen pre-standard headers insys/include/ape/c++,cfrontsz-probe.pyand two committed x86-64Linux binaries under
external/cfront-C4all went with it. The C++front end is EDG's, and
c++is its driver.It had been kept for three reasons and all three expired before it
went: the layout rule now has
structalign-test's nine shapes plustwo straddles and
edgscope-probe/edgtuoff-probeon EDG's ownstructs;
cfrontsz-probe.py's input stopped being tracked; and the EDGdriver turned out to want none of cfront's pipeline —
<values.h>wasalways perl's, p2c's and Devel-PPPort's rather than cfront's. The
comments that name it in
pcc.c,callmain.cand three instrumentsstay: each explains why code is as it is, and
pcc.c's is still thereason
-Jis unconditional rather than insideif(!Aflag).cpferuns; translation is open.sys/src/external/edgholds 133 generated C files, ~2.90M lines, andall of them compile.
cpfelinks, starts, parses a translation unitand builds IL for it; under
--target win64it then faults,fault read addr=0x10, in IL pruning at the end of a function body — wherethe same commit's host
cpfe, same flags, exits 0 and writes correctC. Both struct-layout rules it was first blamed on are now in and
neither explains it: the whole corpus bakes exactly two folded
offsetofconstants, and the tail rule put both back to the numbersEDG computed.
rc/bin/ape/eccpis the driver andc++is a one-lineforwarder to it, so
CXX=c++works for autoconf, for GNU make and forthe shared transpiler rules — which did not have to change, because they
were written against the driver rather than against cfront. It carries
the target flags, the three
--sys_includedirectories in order and the$statusdiscipline, so the long hand-written command in the NOTE ishistory. The remaining three are open. The link model: 556 of 558
mangled names are template instantiations emitted nowhere, with no
vtable, typeinfo or guard variable among them, so the output is not
self-contained for templates and needs a prelink phase mk cannot
naturally express. Static initialisation: nothing calls
_Z12__call_ctorsv, so a C++ program cpfe translates would not run itsstatic constructors. cpfe itself does not need it — the whole corpus
holds one
__sti__routine and its body assigns 0 to members a BSSglobal already has — but that is a different claim, and any gtest-shaped
suite registering tests from static initialisers would report zero tests
and read exactly like a translation bug.
lib_srcis thelibsupc++/libc++abi layer — new/delete, vtables, RTTI, static init,
pure-virtual — and
include_c++is the language-support set, its ownREADME saying "only those headers that require specific magic". What
works with no library at all is the subset EDG itself is written in.
The exception model decides what could fill the gap: EDG's
exceptions are setjmp/longjmp with its own regions and there are zero
_Unwind_references in all 51 files — which is good, since there isno libgcc, no libunwind and no
.eh_framehere, and bad, sincelibc++'s EH assumes the Itanium ABI. And the axis that disqualifies a
candidate is the namespace: code written against
std::vectordoesnot compile against
etl::oreastl::however good they are. Arenamed STL serves new code; only a
std::one serves a port.What's next
unix.carm above.config.hand a native mkfile.re-translation with
kencc_targ.hactually in effect fortarget.c,which would fix
wchar_t, the field alignments, pointer-to-member andjmp_bufin one go.pthread_create—and what is left is two decode failures on files produced elsewhere:
unxzon a 1MB download saysCompressed data is corrupt, andunlz4saysinvalid frame. Neither is separated, because eachhas two explanations (a bad download, or a path only those files
reach) and nothing local has been round-tripped to tell them apart.
The two discriminators are a local round trip at 1MB and
-T1against the default
-T0— the threaded encoder is ground nothingin this tree has ever covered, since until this release no thread
ever reached its start routine. zstd is untested, in the same
position; unrar, unace and clzip are untried.
pthread_attr_*are still no-ops,detachstateincluded. Adetached thread leaves a
Waitmsgfor somebody to collect.attributed, named in
CLAUDE.md.select()learning about a pending connect, which is the lastapproximation in async connect.
FD_ISTTYon a freshly opened/dev/cons.devreg-probereportsit as
S_ISREG, which means GNU grep's "am I writing to the file I amreading" check now runs against the terminal instead of being skipped
as a non-regular file. Recorded, not measured.
This discussion was created from the release APExp release 0.6.
All reactions