Skip to content

[AUTOMATED] Bind glibc's void declaration at a MIPS import its symbol version ties to glibc - #1950

Merged
mahaloz merged 2 commits into
Noelo-Lab:mainfrom
phix33:fix/mips-glibc-void-imports
Nov 25, 2026
Merged

mahaloz merged 2 commits into
Noelo-Lab:mainfrom
phix33:fix/mips-glibc-void-imports

Conversation

@phix33

@phix33 phix33 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The problem

A MIPS PIC wrapper that hands its pointer straight to glibc's free never writes a0, so Kuna drops the argument even when the image links free@GLIBC_2.0 from libc.so.6:

(
  image=$(mktemp ./glibc.XXXXXX)
  trap 'rm -f "$image"' EXIT
  base64 -d <<'IMAGE' | xz -d >"$image"
/Td6WFoAAATm1rRGBMC7BchFIQEcAAAAAAAAADbsA6vgIscCs10AP5FFhGg0igkKQGOk4Cl52te1S1aBteDTTTHbcL5aJLLMb3qQ
D497TIXtlBIdq3IhP0SBoVKe7eiZKK5PCEdZiMYGRCxcOEGyh/Z36LfhWit7JWtbye1ZI32jI26rwBT/tv0SkqvoaEhpI1R3qHtB
enYG8/Vf0LA8Ah+S0aIqiqxVlh5b9Bnm6b99wf3NFzxBY4y5P1UpYyAZSlC54tEW8Bn5ACRl0+UHiZ3vH14FcZIOw/ewR7HAzC2N
O0VPf+cdqQhF17ENO06J4xT683e+YkmbZlFgxPJEgfvzOenQlIsqOWfqIiIOQdITxU9Fmwhwx1UW4mwQLIzeFYzAHXoM1GsBTnZd
PNDENeiwxuzFzN1LDw3VarTjyJBI+J/Hu6hljPLMfGDN2E72ztDyXi+cACkotVsF+0PrST6sZHBqMPVWL6YgHq/k67AXHkyR5qgY
OhkVUU4rNrIA7xVUf50XNSetQpP3MdkCkZbhFhZpgxFaEgrMZjfpHHwcrZ22ktSPjXog+v1LgMRo3+J+j7rnvA57wI13CLSLTBaC
JFJSL3zSp27xgdZ1RX6DrFOyblJNjI1I9PCEpz1bWW+NanEpCPqn76y+lPvjDmurOOL+7Cvo5fBuaJLIhxxBdDm2htasuubaSaaL
ei1P2thOl8wsv0m0GoGDTn9AA1L6qq5j+tui3hJELuFPaFqh+DSVtLIrSee2wqkwveuDuYRP8W/cMgYWaNXqOKux74Akv/B45HsP
pq0tJnoswfXFpCpLcXnhDmoYiuFjSAH6CMC24EqtKnm+krLzpP8lmOKIILiuLaAdUIZb18FLlWIPIloY1RZxVbRCUocWTBFgS1hW
G6N9F2VkZcE/EYJ1+LaERbz2TVsqyPQph5NXI4FdMZFqfJ10gOZiRUHw/uK0yaBWFyAkst9CAAAAh0ln9+1pgu0AAdcFyEUAAPj+
JsGxxGf7AgAAAAAEWVo=
IMAGE
  kuna decompile "$image" release
)
void release(void)
{
  free();
}

The built-in table knows void free(void *), but a type-only declaration with a void result was never bound at a MIPS import. That guard is right for the import name alone: a free that takes nothing compiles to the same instructions.

The fix

  • The loader records, by name, the MIPS imports whose dynamic symbol requires a public GLIBC_* version of one of glibc's own libraries (libc.so.6, libpthread.so.0, libm.so.6, ...), read from .gnu.version once per undefined dynamic function. GLIBC_PRIVATE does not count, nor does a name also imported under another version.
  • Prototype pieces now say whether a built-in library table supplied them.
  • At such an import, the table's declaration of that same symbol binds with a void result when it has at most four integer or pointer parameters no wider than a pointer, which every MIPS ABI passes in argument registers. The wrapper above becomes void release(void *a0) { free(a0); }.
  • An unversioned import, another library's version, GLIBC_PRIVATE, a declaration of another name (--define-function naming the free stub exit), a debug-info declaration, and a floating-point or fifth parameter keep today's rule. A prototype assertion still wins.

Tests

tests/stages/kuna-glibcvoidimport.xml covers N32, O32 and N64 images linked to a versioned libc.so.6, one linked to libpthread.so.0, the unversioned, other-library and GLIBC_PRIVATE controls, console declarations naming the stub free and exit, a caller's void free(void) declaration, strlen, and sincos, which no table declares on MIPS. The forwarding cases fail on main. A loader test checks which imports each fixture binds to glibc, and a console test checks the name, provenance, parameter-count, type and width guards. The fixtures are built from source with clang and GNU ld (recipe in their README). Compiled emitted C for each ABI forwards the same pointers as the original under QEMU, where main's output does not.

Model: anthropic/claude-opus-5-5

@mahaloz
mahaloz merged commit 69c7b56 into Noelo-Lab:main Nov 25, 2026
2 checks passed
@phix33
phix33 deleted the fix/mips-glibc-void-imports branch November 25, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants