From 3fcfcb749bcefe4f388ed38c423a039fcd60a93f Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Thu, 19 Nov 2026 09:08:44 +0900 Subject: [PATCH] 0.30.1: the System V row states its program headers (no PT_PHDR) The kernel of AT&T UNIX System V/386 Release 4.0 refuses an executable that has a PT_PHDR entry and no PT_INTERP one (elfexec), after the old image is gone, so a program of i686-svr4-musl was killed as it started. A static lld link writes PT_PHDR unless the headers are stated; link/svr4.ld states them: the three segments the link made before, the file's headers in the first, no PT_PHDR. The emulation (ibcs-us) accepts either form, so CI now reads the headers of the built program. Measured on that kernel (Release 4.0 Version 3.0 in QEMU, locally, once): the specification's suite 111 held / 0 did not hold; the program of checks/svr4 in both modes; no member changes. --- .github/workflows/ci.yml | 8 +++++++ README.md | 26 ++++++++++++++++------- link/svr4.ld | 45 ++++++++++++++++++++++++++++++++++++++++ mcpp.toml | 17 ++++++++++++--- 4 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 link/svr4.ld diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0eead1..0c78a48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -436,6 +436,14 @@ jobs: file "$p" file "$p" | grep -q 'ELF 32-bit LSB executable, Intel 80386.*statically linked' \ || { echo "::error::the program is not a static ELF32 i386 executable"; exit 1; } + # 0.30.1: the kernel of System V/386 Release 4.0 kills a static program + # that has PT_PHDR, so the row's link (link/svr4.ld) writes none; the + # emulation above accepts either, and this is what holds the statement. + for q in $(find target/i686-svr4-musl -path '*bin/svr4' -type f); do + readelf -lW "$q" | tee headers.log + if grep -qE '^ +(PHDR|INTERP) ' headers.log; then echo "::error::$q has a PT_PHDR or PT_INTERP entry"; exit 1; fi + [ "$(grep -cE '^ +LOAD ' headers.log)" -eq 3 ] || { echo "::error::$q does not have three PT_LOAD segments"; exit 1; } + done # The same executable under the interfaces the emulation is told to answer # as: the part of the interface the program issues is the one they share. diff --git a/README.md b/README.md index 2f289b2..4523e7a 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,9 @@ builds openkal-run's core runner as a program of the DOS row below, with the image in its `.oke` section. Measured under DOSBox Staging: the image sorted its arguments, caught its exception, read DOS's `PATH` and returned 7. -Platform 0.30.0 adds a row and a member: `i686-svr4-musl`, programs of UNIX +Platform 0.30.1 states the program headers of `i686-svr4-musl` (no `PT_PHDR`, +which the kernel of System V/386 Release 4.0 refuses in a static executable); no +member changes. Platform 0.30.0 adds a row and a member: `i686-svr4-musl`, programs of UNIX System V Release 4 and its descendants on i386, over openkal-svr4 0.1.0 (below). In openkal-musl 0.29.10 and openkal-llvm-runtime 0.20.4 a system they do not know takes the general selections, where the selections named systems; the rows served @@ -191,7 +193,7 @@ until a project or this machine does: ```toml [target.x86_64-freebsd-musl] -platform = "openkal-platform@0.30.0" +platform = "openkal-platform@0.30.1" runner = { enabled = true } ``` @@ -303,7 +305,7 @@ with `import std`: ```toml [target.x86_64-uefi] -platform = "openkal-platform@0.30.0" +platform = "openkal-platform@0.30.1" runner = { enabled = true } ``` @@ -339,7 +341,7 @@ and C++ run-time over openkal-svr4, so it is written in C++23 with `import std`: ```toml [target.i686-svr4-musl] -platform = "openkal-platform@0.30.0" +platform = "openkal-platform@0.30.1" runner = { enabled = true } ``` @@ -364,8 +366,18 @@ as the interface states them. Measured under it, as UnixWare 7, Solaris and OpenServer 5: the specification's suite conforms in every observation made (111 held), and a C++23 program with `import std` sorted its arguments, caught an exception, made, renamed, listed (301 names) and removed files, and returned 7, -unoptimised and optimised. No run on a System V kernel has been made; it needs the -system's own media in a machine emulator. +unoptimised and optimised. + +**On a System V kernel (0.30.1), measured once and not by CI.** AT&T UNIX System +V/386 Release 4.0 Version 3.0 was installed in QEMU from its floppy set, which this +platform neither holds nor distributes, on the developer's machine. The +specification's suite conformed there in every observation made (111 held), and the +program of `checks/svr4` and a C program ran, unoptimised and optimised, as they do +under the emulation. One difference was found and is the row's from 0.30.1: that +kernel kills an executable that has a `PT_PHDR` entry and no `PT_INTERP` one, which +a static link writes by default, so the row states its program headers +(`link/svr4.ld`: the same three segments, no `PT_PHDR`). The unoptimised +executables were stripped of their debugging sections to fit a floppy. ## DOS programs (0.28.0; technical experiment only) @@ -375,7 +387,7 @@ run-time over openkal-dos, so it is written in C++23 with `import std`: ```toml [target.i686-dos-musl] -platform = "openkal-platform@0.30.0" +platform = "openkal-platform@0.30.1" ``` The row is TECHNICAL EXPERIMENT ONLY (openkal-dos's README). A program is the diff --git a/link/svr4.ld b/link/svr4.ld new file mode 100644 index 0000000..a0751c8 --- /dev/null +++ b/link/svr4.ld @@ -0,0 +1,45 @@ +/* The program headers of an i686-svr4-musl executable. + * + * The kernel of UNIX System V/386 Release 4.0 refuses an executable that has a + * PT_PHDR entry and no PT_INTERP one (`elfexec': the entry is for the run-time + * linker), and it refuses after the old image is gone, so the program is killed + * as it starts. A static link writes PT_PHDR unless the headers are stated, as + * here: the same three segments the default link makes, the file's headers + * inside the first, and no PT_PHDR. + */ +PHDRS +{ + rodata PT_LOAD FILEHDR PHDRS FLAGS(4); + text PT_LOAD FLAGS(5); + data PT_LOAD FLAGS(6); + unwind PT_GNU_EH_FRAME FLAGS(4); + stack PT_GNU_STACK FLAGS(6); +} + +SECTIONS +{ + . = 0x400000 + SIZEOF_HEADERS; + + .rodata : { *(.rodata .rodata.*) } :rodata + .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :rodata :unwind + .eh_frame : { KEEP(*(.eh_frame)) } :rodata + + /* A segment begins in a page of its own, at the offset its file position has. */ + . = ALIGN(CONSTANT(MAXPAGESIZE)) + (. & (CONSTANT(MAXPAGESIZE) - 1)); + .text : { *(.text .text.*) } :text + PROVIDE(etext = .); PROVIDE(_etext = .); + + . = ALIGN(CONSTANT(MAXPAGESIZE)) + (. & (CONSTANT(MAXPAGESIZE) - 1)); + .preinit_array : { KEEP(*(.preinit_array)) } :data + .init_array : { KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*))) KEEP(*(.init_array)) } + .fini_array : { KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*))) KEEP(*(.fini_array)) } + .data.rel.ro : { *(.data.rel.ro .data.rel.ro.*) } + .data : { *(.data .data.*) } + .got : { *(.got) } + .got.plt : { *(.got.plt) } + PROVIDE(edata = .); PROVIDE(_edata = .); + PROVIDE(__bss_start = .); + .bss : { *(.bss .bss.*) *(COMMON) } + PROVIDE(end = .); PROVIDE(_end = .); +} diff --git a/mcpp.toml b/mcpp.toml index 6d2923d..94f2662 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -12,7 +12,7 @@ [package] namespace = "mcpplibs" name = "openkal-platform" -version = "0.30.0" +version = "0.30.1" description = "The platform of ok images (-openkal): their toolchain, C library and C++ run-time, tools, compile and link conventions, seal, runner and carrier, as one versioned statement mcpp reads." license = "Apache-2.0" authors = ["mcpplibs"] @@ -359,6 +359,16 @@ runner = { cmd = ["dirun", "--payload", "{}", "--profile", "{pkg:dosbox-staging} # System V kernel needs the system's own media and is not this runner's. A # program that replaces its image leaves the emulation, so openkal-svr4 0.1 claims # no `openkal.process' and the row starts no other program. The tier is `preview'. +# +# THE PROGRAM HEADERS ARE THE ROW'S STATEMENT (0.30.1; `link/svr4.ld'). The kernel +# of System V/386 Release 4.0 refuses an executable that has a PT_PHDR entry and +# no PT_INTERP one, after the old image is gone: the program is killed as it +# starts. A static link writes that entry unless the headers are stated, so the +# row states them: the three segments the link made before, the file's headers in +# the first, and no PT_PHDR. Found by running the row's programs on that kernel +# (AT&T UNIX System V/386 Release 4.0 Version 3.0 in QEMU, on the developer's +# machine, from media this platform neither holds nor distributes); the emulation +# accepts either form. [[platform.system]] name = "svr4" @@ -380,7 +390,7 @@ base = "none" hosted = true layers = { "kernel-abi" = { name = "openkal-svr4", version = "0.1.0", features = ["standalone"] }, compiler-runtime = "openkal-llvm-runtime@0.20.4", "c++-abi" = "openkal-llvm-runtime@0.20.4", c-abi = { name = "openkal-musl", version = "0.29.10", default-features = false, features = ["posix", "malloc-mallocng"] } } -link = { driver = "lld", flags = ["-static", "-z", "norelro", "--gc-sections", "--eh-frame-hdr"] } +link = { driver = "lld", script = "link/svr4.ld", flags = ["-static", "-z", "norelro", "--gc-sections", "--eh-frame-hdr"] } runner = { cmd = ["unshare", "-Ur", "{pkg:ibcs-us}/bin/ibcs-us", "{}"], hosts = ["linux-x86_64"], requires = ["xim:ibcs-us@4.3-1"], enabled = false } # The family released together for openkal 0.17 (the 0.17.2 round: okb, the @@ -451,7 +461,8 @@ runner = { cmd = ["unshare", "-Ur", "{pkg:ibcs-us}/bin/ibcs-us", "{}"], hosts = # volume's root); 0.30.0, openkal-svr4 0.1.0 (System V Release 4 on i386, the # `kernel-abi' layer of its row) with openkal-musl 0.29.10 and openkal-llvm-runtime # 0.20.4, in which a system they do not know takes the general selections, where -# the selections named systems. From 0.24.1 the members name one another by +# the selections named systems; 0.30.1, no member changes (the System V row's +# program headers, above). From 0.24.1 the members name one another by # compatible ranges (`^0.28.0`) and this group chooses the versions: mcpp # 2026.11.7.1 resolves within it, and a fix of one member is that member's # release and a patch of this group, released together through one index change