@devries-cameron20 / t3code Mirror · read-only / commits / b64eebb991
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 13:30 UTC

fix(release): enforce packaged Linux glibc requirements (#30827)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Lakshmi Tanmay committed Nov 15, 2026 at 05:41 UTC b64eebb991bb744b438740bef468e80d5c7e6e29
4 files changed +237
docs/operations/development.md
+1
@@ -307,6 +307,7 @@ C/C++ build tools, libsecret development headers, pkg-config, and ImageMagick.
307 Bytecode preparation also runs packaged Electron and requires GTK, NSS, ALSA, and GBM runtime libraries.
308 Install Rust 1.95 or newer through [rustup](https://rust-lang.org/install), using the stable
309 toolchain as release CI does.
310 +The packaged ELF compatibility check uses binutils’ `readelf`, included by the C/C++ toolchain.
311
312 Ubuntu 24.04 and Debian 13:
313
scripts/linux-after-pack.ts
+20
@@ -3,11 +3,18 @@ import * as NodeFSP from "node:fs/promises";
3 import * as NodeModule from "node:module";
4 import * as NodePath from "node:path";
5
6 +import { scanGlibcNeeds } from "./linux-glibc.ts";
7 +
8 const prepareServerCompileCache: (context: AfterPackContext) => Promise<void> =
9 NodeModule.createRequire(import.meta.url)("./prepare-server-compile-cache.cjs");
10
11 interface AfterPackContext {
12 readonly appOutDir: string;
13 + readonly electronPlatformName: string;
14 + readonly targets: ReadonlyArray<{
15 + readonly name: string;
16 + readonly options?: { depends?: string | string[] } | null;
17 + }>;
18 }
19
20 // Electron's Linux zips can ship world-writable files (44.10.0 has 0777 binaries), and
@@ -15,6 +22,19 @@ interface AfterPackContext {
22 export default async function afterPack(context: AfterPackContext): Promise<void> {
23 await prepareServerCompileCache(context);
24 await removeSharedWriteAccess(context.appOutDir);
25 + const { minimum } = await scanGlibcNeeds(context.appOutDir);
26 + for (const target of context.targets) {
27 + if (target.name !== "deb") continue;
28 + if (!target.options || !Array.isArray(target.options.depends)) {
29 + throw new Error("Linux deb target must configure its dependencies before afterPack");
30 + }
31 + // FPM snapshots config when targets are created; update the target's resolved options.
32 + // Targets are shared across arches, so replace any entry an earlier arch added.
33 + target.options.depends = [
34 + ...target.options.depends.filter((dependency) => !dependency.startsWith("libc6 ")),
35 + `libc6 (>= ${minimum})`,
36 + ];
37 + }
38 }
39
40 // Walks by hand: recursive readdir follows directory symlinks out of the app folder.
scripts/linux-glibc.test.ts new
+125
@@ -0,0 +1,125 @@
1 +// @effect-diagnostics nodeBuiltinImport:off - Exercises the packaging filesystem and readelf.
2 +import * as HostProcess from "@t3tools/shared/HostProcess";
3 +import * as NodeFSP from "node:fs/promises";
4 +import * as NodeOS from "node:os";
5 +import * as NodePath from "node:path";
6 +import { describe, expect, it } from "vite-plus/test";
7 +
8 +import afterPack from "./linux-after-pack.ts";
9 +import { parseGlibcNeeds, scanGlibcNeeds } from "./linux-glibc.ts";
10 +
11 +it.each([
12 + ["GLIBC_2.9", "2.9"],
13 + ["GLIBC_2.34", "2.34"],
14 + ["GLIBC_2.10", "2.10"],
15 + ["GLIBC_2.2.5", "2.2.5"],
16 + ["GLIBC_ABI_DT_RELR", "2.36"],
17 +])("reads required %s without counting newer definitions", (name, expected) => {
18 + expect(
19 + parseGlibcNeeds(`
20 +Version definition section '.gnu.version_d' contains 1 entry:
21 + 0x0010: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: GLIBC_2.99
22 +Version needs section '.gnu.version_r' contains 1 entry:
23 + 000000: Version: 1 File: libc.so.6 Cnt: 3
24 + 0x0010: Name: GLIBC_2.2 Flags: none Version: 3
25 + 0x0020: Name: ${name} Flags: none Version: 4
26 + 0x0030: Name: GLIBCXX_3.4.30 Flags: none Version: 5
27 +`),
28 + ).toBe(expected);
29 +});
30 +
31 +it("ignores definitions, symbol tables, and unversioned/static binaries", () => {
32 + expect(parseGlibcNeeds("No version information found in this file.")).toBeUndefined();
33 + expect(
34 + parseGlibcNeeds(`
35 +Version symbols section '.gnu.version' contains 1 entry:
36 + 000: 2 (GLIBC_2.99)
37 +Version definition section '.gnu.version_d' contains 1 entry:
38 + 0x0010: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: GLIBC_2.99
39 +`),
40 + ).toBeUndefined();
41 +});
42 +
43 +it.each(["GLIBC_PRIVATE", "GLIBC_ABI_UNKNOWN"])("rejects unhandled requirement %s", (name) => {
44 + expect(() =>
45 + parseGlibcNeeds(`Version needs section '.gnu.version_r' contains 1 entry:
46 + 0x0010: Name: ${name} Flags: none Version: 3
47 +`),
48 + ).toThrow(name);
49 +});
50 +
51 +// Minimal ELF64 with a linked string table and a version NEEDS section, for both release CPUs.
52 +function elfFixture(machine: number, version: string): Buffer {
53 + const strings = Buffer.from(`\0libc.so.6\0GLIBC_${version}\0`);
54 + const names = Buffer.from("\0.shstrtab\0.dynstr\0.gnu.version_r\0");
55 + const stringsOffset = 64;
56 + const namesOffset = stringsOffset + strings.length;
57 + const needsOffset = namesOffset + names.length;
58 + const sectionsOffset = needsOffset + 32;
59 + const elf = Buffer.alloc(sectionsOffset + 4 * 64);
60 + Buffer.from([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1]).copy(elf);
61 + elf.writeUInt16LE(3, 16);
62 + elf.writeUInt16LE(machine, 18);
63 + elf.writeUInt32LE(1, 20);
64 + elf.writeBigUInt64LE(BigInt(sectionsOffset), 40);
65 + elf.writeUInt16LE(64, 52);
66 + elf.writeUInt16LE(64, 58);
67 + elf.writeUInt16LE(4, 60);
68 + elf.writeUInt16LE(1, 62);
69 + strings.copy(elf, stringsOffset);
70 + names.copy(elf, namesOffset);
71 + elf.writeUInt16LE(1, needsOffset);
72 + elf.writeUInt16LE(1, needsOffset + 2);
73 + elf.writeUInt32LE(1, needsOffset + 4);
74 + elf.writeUInt32LE(16, needsOffset + 8);
75 + elf.writeUInt16LE(2, needsOffset + 16 + 6);
76 + elf.writeUInt32LE(11, needsOffset + 16 + 8);
77 + for (const [index, name, type, offset, size, link] of [
78 + [1, 1, 3, namesOffset, names.length, 0],
79 + [2, 11, 3, stringsOffset, strings.length, 0],
80 + [3, 19, 0x6ffffffe, needsOffset, 32, 2],
81 + ] as const) {
82 + const section = sectionsOffset + index * 64;
83 + elf.writeUInt32LE(name, section);
84 + elf.writeUInt32LE(type, section + 4);
85 + elf.writeBigUInt64LE(BigInt(offset), section + 24);
86 + elf.writeBigUInt64LE(BigInt(size), section + 32);
87 + elf.writeUInt32LE(link, section + 40);
88 + elf.writeBigUInt64LE(1n, section + 48);
89 + }
90 + elf.writeUInt32LE(1, sectionsOffset + 3 * 64 + 44);
91 + return elf;
92 +}
93 +
94 +describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("packaged ELF scan", () => {
95 + it.each([62, 183])(
96 + "checks executable, addon and extensionless ELF requirements for machine %s",
97 + async (machine) => {
98 + const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-glibc-"));
99 + try {
100 + const app = NodePath.join(root, "app");
101 + const native = NodePath.join(app, "resources/app.asar.unpacked/node_modules/addon");
102 + await NodeFSP.mkdir(native, { recursive: true });
103 + await NodeFSP.writeFile(NodePath.join(app, "t3code"), elfFixture(machine, "2.25"));
104 + await NodeFSP.writeFile(NodePath.join(native, "pty.node"), elfFixture(machine, "2.34"));
105 + await NodeFSP.writeFile(NodePath.join(app, "not-elf"), "GLIBC_2.99");
106 + await NodeFSP.writeFile(NodePath.join(root, "outside"), elfFixture(machine, "2.99"));
107 + await NodeFSP.symlink("../outside", NodePath.join(app, "symlink"));
108 + expect(await scanGlibcNeeds(app)).toEqual({ minimum: "2.34", elfCount: 2 });
109 + const deb = { name: "deb", options: { depends: ["libnss3"] } };
110 + for (let arch = 0; arch < 2; arch++) {
111 + await afterPack({ appOutDir: app, electronPlatformName: "linux", targets: [deb] });
112 + }
113 + expect(deb.options.depends).toEqual(["libnss3", "libc6 (>= 2.34)"]);
114 + await NodeFSP.writeFile(NodePath.join(native, "helper"), elfFixture(machine, "2.40"));
115 + await expect(
116 + afterPack({ appOutDir: app, electronPlatformName: "linux", targets: [deb] }),
117 + ).rejects.toThrow(/helper.*GLIBC_2\.40.*2\.39/s);
118 + await NodeFSP.writeFile(NodePath.join(native, "helper"), Buffer.from("\x7fELFbroken"));
119 + await expect(scanGlibcNeeds(app)).rejects.toThrow(/helper/);
120 + } finally {
121 + await NodeFSP.rm(root, { recursive: true, force: true });
122 + }
123 + },
124 + );
125 +});
scripts/linux-glibc.ts new
+91
@@ -0,0 +1,91 @@
1 +// @effect-diagnostics nodeBuiltinImport:off globalConsole:off - Runs in electron-builder's Node afterPack hook.
2 +import * as NodeChildProcess from "node:child_process";
3 +import * as NodeFSP from "node:fs/promises";
4 +import * as NodePath from "node:path";
5 +import * as NodeUtil from "node:util";
6 +
7 +// Both Linux release jobs build on Ubuntu 24.04; this is a build ceiling, not a distro support promise.
8 +const GLIBC_BUILD_CEILING = "2.39";
9 +const readelf = NodeUtil.promisify(NodeChildProcess.execFile);
10 +
11 +function compareVersions(left: string, right: string): number {
12 + const a = left.split(".").map(Number);
13 + const b = right.split(".").map(Number);
14 + for (let i = 0; i < Math.max(a.length, b.length); i++) {
15 + const difference = (a[i] ?? 0) - (b[i] ?? 0);
16 + if (difference !== 0) return difference;
17 + }
18 + return 0;
19 +}
20 +
21 +export function parseGlibcNeeds(output: string): string | undefined {
22 + let inNeeds = false;
23 + let minimum: string | undefined;
24 + for (const line of output.split("\n")) {
25 + if (line.startsWith("Version ")) inNeeds = line.startsWith("Version needs section ");
26 + if (!inNeeds) continue;
27 + const name = /\bName:\s+(GLIBC_\S+)/.exec(line)?.[1];
28 + if (!name) continue;
29 + // DT_RELR's named ABI requirement was introduced in glibc 2.36.
30 + const version =
31 + name === "GLIBC_ABI_DT_RELR" ? "2.36" : /^GLIBC_(\d+(?:\.\d+)+)$/.exec(name)?.[1];
32 + if (!version) throw new Error(`Unhandled glibc requirement: ${name}`);
33 + if (!minimum || compareVersions(version, minimum) > 0) minimum = version;
34 + }
35 + return minimum;
36 +}
37 +
38 +export async function scanGlibcNeeds(appOutDir: string): Promise<{
39 + minimum: string;
40 + elfCount: number;
41 +}> {
42 + let minimum: string | undefined;
43 + let elfCount = 0;
44 + async function walk(directory: string): Promise<void> {
45 + for (const entry of await NodeFSP.readdir(directory, { withFileTypes: true })) {
46 + const file = NodePath.join(directory, entry.name);
47 + if (entry.isDirectory()) {
48 + await walk(file);
49 + continue;
50 + }
51 + if (!entry.isFile()) continue;
52 + const handle = await NodeFSP.open(file, "r");
53 + let isElf: boolean;
54 + try {
55 + const magic = Buffer.alloc(4);
56 + await handle.read(magic, 0, 4, 0);
57 + isElf = magic.equals(Buffer.from([0x7f, 0x45, 0x4c, 0x46]));
58 + } finally {
59 + await handle.close();
60 + }
61 + if (!isElf) continue;
62 + elfCount++;
63 + try {
64 + // readelf inspects either release architecture without executing the binary.
65 + const { stdout, stderr } = await readelf("readelf", ["--wide", "--version-info", file], {
66 + env: { ...process.env, LC_ALL: "C" },
67 + maxBuffer: 16 * 1024 * 1024,
68 + });
69 + if (stderr.trim()) throw new Error(stderr.trim());
70 + const required = parseGlibcNeeds(stdout);
71 + if (required && compareVersions(required, GLIBC_BUILD_CEILING) > 0) {
72 + throw new Error(
73 + `requires GLIBC_${required}, exceeding build ceiling ${GLIBC_BUILD_CEILING}`,
74 + );
75 + }
76 + if (required && (!minimum || compareVersions(required, minimum) > 0)) minimum = required;
77 + } catch (cause) {
78 + throw new Error(
79 + `Cannot validate glibc compatibility of ${file}: ${cause instanceof Error ? cause.message : String(cause)}`,
80 + { cause },
81 + );
82 + }
83 + }
84 + }
85 + await walk(appOutDir);
86 + if (elfCount === 0 || !minimum) throw new Error(`No glibc requirements found in ${appOutDir}`);
87 + console.log(
88 + `[linux-glibc] ${elfCount} ELF files; requires glibc >= ${minimum}; build ceiling ${GLIBC_BUILD_CEILING}`,
89 + );
90 + return { minimum, elfCount };
91 +}