build: fix four things a clean build found, three of them mine
`make` had been failing since the e1000 work and I did not see it, because I was checking build output with `grep error` -- which matches neither "Błąd" nor mkfs's "image full". Checking the exit status instead found all of this in a minute. **usbstick.img was full.** `make ldls-stage` puts a module and its BTF in sysroot/lib/modules, and a vmlinux BTF is 5 MB on its own; the 16 MB test image could not hold it. The size cannot move -- tools/windows/bootcheck.ps1 asserts READ CAPACITY returns exactly 32768 sectors -- so the exclusions grew instead: lib and usr as well as bin. That image exists to prove the USB driver can read one block, so its contents were never the point. It also stopped a GPL module riding into a test artifact, which RAMDISK_EXCLUDE does for the ramdisk and nothing was doing for this one. **toybox's httpd was shadowing ours.** /bin/httpd answered `-p` with toybox's "Unknown option 'p'", because whichever install rule ran second won the name. TOYBOX_SKIP existed for exactly this and held one entry, `ping`, found the same hard way. It is now generated from cmd/ -- a list you have to remember is a list that is wrong the next time cmd/ grows, and it already was: `chvt` had been silently toybox's, whose VT ioctls are Linux's and not ours. **ldlsd would not link with clang.** `*out = in;` on a 96-byte struct is a call to memcpy as far as the C standard is concerned; gcc unrolled it and clang emitted the call, so a freestanding program linked for months and then did not on a machine where nothing about it had changed but the compiler. lib/glue.c now provides memcpy, memmove, memset and memcmp -- the four an implementation may call without being asked. **OVMF was never found on NixOS.** `$(dir $(QEMU))share` is the *bin* directory plus "share", so it looked in /usr/bin/share. The absolute paths after it covered that up on distributions that keep firmware in /usr; on one that keeps nothing there it meant the firmware was undiscoverable on a machine that had it, and the only way to build was to copy the file in by hand. It resolves the prefix properly now and looks in <prefix>/share/qemu too. Verified by exit status, from a clean tree and a no-op: both 0. ldls-check passes 27. The guest boots, serves /srv to the host and answers 403 to %2e%2e/etc/passwd. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
This commit is contained in:
parent
b08432b2c3
commit
4a032c9c62
3 changed files with 113 additions and 13 deletions
65
lib/glue.c
65
lib/glue.c
|
|
@ -16,6 +16,71 @@ exit(void)
|
|||
/* _start lives in lib/start.S — it must read incoming registers, which
|
||||
* cannot be expressed portably in C. See that file. */
|
||||
|
||||
// The four the compiler is allowed to call without being asked.
|
||||
//
|
||||
// A freestanding build gets no libc, but it does not get a compiler that
|
||||
// promises never to *call* one: the C standard lets an implementation emit
|
||||
// calls to memcpy, memmove, memset and memcmp for things that look nothing
|
||||
// like a function call. A struct assignment is the common one --
|
||||
//
|
||||
// *out = in; /* struct pciuser_info, 96 bytes */
|
||||
//
|
||||
// -- which gcc unrolled into stores and clang turned into `call memcpy`, so
|
||||
// ldlsd linked for months and then did not, on a machine where nothing about
|
||||
// it had changed except which compiler ran. The fix is not to avoid struct
|
||||
// assignment; it is to provide the four functions, because the compiler is
|
||||
// within its rights either way.
|
||||
//
|
||||
// Deliberately simple. These are not the hot path of anything here, and a
|
||||
// clever one risks being turned back into a call to itself.
|
||||
void *
|
||||
memcpy(void *dst, const void *src, unsigned long n)
|
||||
{
|
||||
unsigned char *d = dst;
|
||||
const unsigned char *s = src;
|
||||
while (n--) *d++ = *s++;
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *
|
||||
memmove(void *dst, const void *src, unsigned long n)
|
||||
{
|
||||
unsigned char *d = dst;
|
||||
const unsigned char *s = src;
|
||||
|
||||
if (d == s || n == 0)
|
||||
return dst;
|
||||
// Backwards when they overlap the wrong way, which is the whole reason
|
||||
// this is not memcpy.
|
||||
if (d < s) {
|
||||
while (n--) *d++ = *s++;
|
||||
} else {
|
||||
d += n; s += n;
|
||||
while (n--) *--d = *--s;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *
|
||||
memset(void *dst, int c, unsigned long n)
|
||||
{
|
||||
unsigned char *d = dst;
|
||||
while (n--) *d++ = (unsigned char)c;
|
||||
return dst;
|
||||
}
|
||||
|
||||
int
|
||||
memcmp(const void *a, const void *b, unsigned long n)
|
||||
{
|
||||
const unsigned char *p = a, *q = b;
|
||||
while (n--) {
|
||||
if (*p != *q)
|
||||
return *p - *q;
|
||||
p++; q++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
__stack_chk_fail(void)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue