Merge remote-tracking branch 'origin/main' into feat/claude-code-plugin

This commit is contained in:
GamerDubz
2026-10-12 05:18:13 +02:00
389 changed files with 22916 additions and 2950 deletions
+24 -1
View File
@@ -1,7 +1,8 @@
/* Relocatable (ET_REL) static-analysis fixture, built with -c -G0 and never
* executed or linked by REA. It exercises the relocations Linux MIPS kernel
* modules use: R_MIPS_26 calls, HI16/LO16 address pairs (one HI16 shared by
* several LO16s, and a LO16 >= 0x8000 that forces a HI16 carry), R_MIPS_32
* several LO16s, two HI16s resolved by one LO16, and a LO16 >= 0x8000 that
* forces a HI16 carry), R_MIPS_32
* data words, and undefined external code and data symbols. powf is an
* external whose float prototype Ghidra's C library archive supplies by name,
* so soft-float builds must give it the soft-float prototype too.
@@ -19,6 +20,8 @@ struct rea_mips_rel_pair rea_mips_rel_pair = { 0x1111, 0x2222 };
/* Places rea_mips_rel_carry past a signed 16-bit low-half boundary. */
char rea_mips_rel_padding[0x8000] = { 1 };
int rea_mips_rel_carry = 0x3333;
/* Referenced only by rea_mips_rel_highs, so its single LO16 stays unique. */
int rea_mips_rel_highs_target = 0x4444;
static const char rea_mips_rel_marker[] = "rea-mips-relocatable-fixture";
__attribute__((noinline)) int rea_mips_rel_leaf(int value)
@@ -45,6 +48,26 @@ __attribute__((noinline)) int rea_mips_rel_scaled(int value)
return value ^ *(int *)&scaled;
}
/* Most GCC-built kernel modules checked contain LO16s that resolve several
* pending HI16s; Clang does not produce that from C. Two %hi and exactly one
* %lo of a symbol nothing else references: any assembler that orders each
* HI16 before a matching LO16 (GNU as, every LLVM version) must emit both
* HI16s ahead of that single LO16, which therefore resolves both.
*/
__asm__(".text\n"
".globl rea_mips_rel_highs\n"
".type rea_mips_rel_highs, @function\n"
".set push\n"
".set noreorder\n"
"rea_mips_rel_highs:\n"
" lui $2, %hi(rea_mips_rel_highs_target)\n"
" lui $3, %hi(rea_mips_rel_highs_target)\n"
" addiu $2, $2, %lo(rea_mips_rel_highs_target)\n"
" jr $31\n"
" move $3, $2\n"
".set pop\n"
".size rea_mips_rel_highs, .-rea_mips_rel_highs\n");
int rea_mips_rel_entry(int value)
{
return rea_mips_rel_leaf(value) + rea_mips_rel_far(value) +
@@ -0,0 +1,22 @@
/* Build an older-style shared image from source without ABI declarations. */
PHDRS {
headers PT_PHDR PHDRS;
text PT_LOAD FILEHDR PHDRS FLAGS(5);
data PT_LOAD FLAGS(6);
dynamic PT_DYNAMIC FLAGS(6);
}
SECTIONS {
. = SIZEOF_HEADERS;
.hash : { *(.hash) } :text
.gnu.hash : { *(.gnu.hash) } :text
.dynsym : { *(.dynsym) } :text
.dynstr : { *(.dynstr) } :text
.rel.dyn : { *(.rel.*) } :text
.text : { *(.text*) } :text
. = ALIGN(0x10000);
.dynamic : { *(.dynamic) } :data :dynamic
.got : { *(.got*) } :data
.data : { *(.data*) } :data
.bss : { *(.bss*) *(COMMON) } :data
/DISCARD/ : { *(.MIPS.abiflags) *(.reginfo) *(.pdr) *(.mdebug.*) *(.comment) *(.note.*) }
}
@@ -0,0 +1,156 @@
import assert from "node:assert/strict";
import { execFile } from "node:child_process";
import { createHash } from "node:crypto";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
const execute = promisify(execFile);
const source = fileURLToPath(new URL("./mips16-shared.S", import.meta.url));
const linkerScript = fileURLToPath(
new URL("./mips16-recordless.ld", import.meta.url),
);
const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
/** BYO GNU cross-binutils; generated controls are never executed or byte-patched. */
export async function buildMips16SharedFixture(directory, byteOrder, variant) {
assert(["little", "big"].includes(byteOrder));
assert(
[
"declared",
"recordless",
"symbol-relative",
"section-relocations",
].includes(variant),
);
const assembler = process.env.REA_MIPS_AS ?? "mips-linux-gnu-as";
const linker = process.env.REA_MIPS_LD ?? "mips-linux-gnu-ld";
const endian = byteOrder === "little" ? "-EL" : "-EB";
const prefix = join(directory, `${byteOrder}-${variant}`);
const object = `${prefix}.o`;
const path = `${prefix}.so`;
const assemblerVersion = (
await execute(assembler, ["--version"], { timeout: 10000 })
).stdout;
const linkerVersion = (
await execute(linker, ["--version"], { timeout: 10000 })
).stdout;
assert(
assemblerVersion.includes("GNU assembler"),
"Use GNU's MIPS assembler: other assemblers have different compressed-instruction behavior.",
);
assert(linkerVersion.includes("GNU ld"));
await execute(
assembler,
[
"-32",
"-mips32r2",
endian,
...(variant === "symbol-relative"
? ["--defsym", "REA_MIPS_SYMBOL_RELATIVE=1"]
: []),
source,
"-o",
object,
],
{ timeout: 60000 },
);
await execute(
linker,
[
endian,
"-shared",
...(variant === "section-relocations" ? ["--emit-relocs"] : []),
...(variant === "recordless" ? ["-T", linkerScript] : []),
object,
"-o",
path,
],
{ timeout: 60000 },
);
const bytes = await readFile(path);
const little = byteOrder === "little";
const u16 = (offset) =>
little ? bytes.readUInt16LE(offset) : bytes.readUInt16BE(offset);
const u32 = (offset) =>
little ? bytes.readUInt32LE(offset) : bytes.readUInt32BE(offset);
assert.equal(
bytes.subarray(0, 6).toString("hex"),
little ? "7f454c460101" : "7f454c460102",
);
assert.equal(u16(16), 3);
assert.equal(u16(18), 8);
assert.equal(u32(36), 0x74001007); // noreorder/PIC/CPIC plus o32/MIPS16/MIPS32r2.
const headers = Array.from(
{ length: u16(44) },
(_, i) => u32(28) + i * u16(42),
);
const fileOffset = (address, size) => {
const mappings = headers.filter(
(offset) =>
u32(offset) === 1 &&
address >= u32(offset + 8) &&
address - u32(offset + 8) <= u32(offset + 16) - size,
);
assert.equal(mappings.length, 1);
return u32(mappings[0] + 4) + address - u32(mappings[0] + 8);
};
const readelf = await execute(
process.env.REA_MIPS_READELF ?? "readelf",
["-W", "-h", "-l", "-s", "-r", path],
{ timeout: 10000 },
);
const symbols = {};
for (const name of [
"rea_mips16_probe",
"rea_mips32_probe",
"rea_mips16_pointer",
]) {
const addresses = new Set(
readelf.stdout
.split("\n")
.map((line) => line.trim().split(/\s+/u))
.filter(
(fields) =>
fields[0]?.endsWith(":") === true &&
["FUNC", "OBJECT"].includes(fields[3]) &&
fields.at(-1) === name,
)
.map((fields) => Number.parseInt(fields[1], 16)),
);
assert.equal(addresses.size, 1, `Missing or conflicting ${name}`);
symbols[name] = [...addresses][0];
}
assert.equal(symbols.rea_mips16_probe & 1, 1);
assert.equal(symbols.rea_mips32_probe & 1, 0);
const compressedOffset = fileOffset(symbols.rea_mips16_probe - 1, 8);
assert.equal(
bytes.subarray(compressedOffset, compressedOffset + 8).toString("hex"),
little ? "5a6a8eea074aa0e8" : "6a5aea8e4a07e8a0",
);
const standardOffset = fileOffset(symbols.rea_mips32_probe, 12);
assert.equal(
bytes.subarray(standardOffset, standardOffset + 12).toString("hex"),
little ? "030082240800e00300000000" : "2482000303e0000800000000",
);
const pointerOffset = fileOffset(symbols.rea_mips16_pointer, 4);
const rawPointer = u32(pointerOffset);
if (variant !== "symbol-relative")
assert.equal(rawPointer, symbols.rea_mips16_probe);
return {
path,
sha256: hash(bytes),
byte_order: byteOrder,
variant,
elf_flags: u32(36),
symbols,
raw_pointer: rawPointer,
source_sha256: hash(await readFile(source)),
linker_script_sha256:
variant === "recordless" ? hash(await readFile(linkerScript)) : null,
assembler_version: assemblerVersion.split("\n")[0],
linker_version: linkerVersion.split("\n")[0],
readelf_output: readelf.stdout,
};
}
+41
View File
@@ -0,0 +1,41 @@
/* Source-owned mixed-instruction shared-image control. */
.abicalls
.module fp=xx
.module nooddspreg
.text
.set noreorder
.set nomicromips
.set mips16
.globl rea_mips16_probe
.type rea_mips16_probe, @function
.ent rea_mips16_probe
rea_mips16_probe:
li $2, 90
xor $2, $4
addiu $2, 7
jrc $31
.end rea_mips16_probe
.size rea_mips16_probe, . - rea_mips16_probe
.ifndef REA_MIPS_SYMBOL_RELATIVE
.hidden rea_mips16_probe
.endif
.set nomips16
.globl rea_mips32_probe
.type rea_mips32_probe, @function
.ent rea_mips32_probe
rea_mips32_probe:
addiu $2, $4, 3
jr $31
nop
.end rea_mips32_probe
.size rea_mips32_probe, . - rea_mips32_probe
.data
.balign 4
.globl rea_mips16_pointer
.type rea_mips16_pointer, @object
.size rea_mips16_pointer, 4
rea_mips16_pointer:
.word rea_mips16_probe
.section .note.GNU-stack, "", @progbits