Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@ release-mode 调试仍可使用调试签名,调试签名包不能作为正式
macOS 桌面包使用 ad-hoc 签名,未配置 Apple Developer ID 或公证;首次使用时
可能需要在系统隐私与安全性设置中允许打开。iOS 需要分发证书与 provisioning,
未配置时不发布不可安装的 IPA。

## 在本地检查 Linux 包的 glibc 版本需求

解开最终归档后,把包含 `backend/` 的 `Panache` 目录交给脚本,并明确指定要验证的 glibc 上限。例如,在 Debian 13 上验证 2.41 可运行以下命令。

```sh
python3 scripts/check-linux-glibc.py /path/to/Panache --max-glibc 2.41
```

脚本使用 GNU `readelf` 读取包内 ELF 的版本需求。退出码 0 表示所有读到的数字 GLIBC 需求都在上限内,1 表示至少一个文件超界,2 表示参数有误,3 表示包或版本信息无法检查,4 表示缺少必需的 Rust 后端,5 表示找不到 `readelf`。无法换算成数字的 GLIBC 需求也会报错。检查通过后,仍需在目标系统上启动桌面程序,验证图形库和真实工具调用。

v1.21.0 官方 Linux x64 包以 2.41 为上限时,12 个 ELF 中有两个后端要求 `GLIBC_2.43`。在 Debian 13 从同一提交重建这两个后端后,同一个检查有 0 个文件超界。2.41 仅为这次对照使用的上限。
106 changes: 106 additions & 0 deletions scripts/check-linux-glibc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python3
"""Check ELF version requirements in an unpacked Panache Linux release."""
import argparse
import os
from pathlib import Path
import re
import shutil
import subprocess
import sys


BACKENDS = ('backend/handwriting-server', 'backend/panache-mcp')


def version(text):
if not re.fullmatch(r'[0-9]+(?:\.[0-9]+)+', text):
raise ValueError(f'expected a numeric version, got {text!r}')
parts = [int(n) for n in text.split('.')]
while len(parts) > 2 and parts[-1] == 0:
parts.pop()
return tuple(parts)


def requirements(output):
# readelf also prints names that the object defines or merely lists in .gnu.version.
needs = re.search(r'^Version needs section [^\n]+\n((?:[ \t]+[^\n]+\n?)*)', output, re.M)
block = needs[1] if needs else ''
if not needs and 'No version information found' not in output and not re.search(
r'^Version (?:symbols|definition) section ', output, re.M):
raise ValueError('unrecognized GNU readelf version output')
providers = re.findall(r'\bFile: \S+\s+Cnt: (\d+)', block)
names = re.findall(r'\bName: (\S+)\s+Flags:', block)
count = re.search(r'\(VERNEEDNUM\)\s+(\d+)', output)
if ('<corrupt' in block or bool(needs) != ('(VERNEED)' in output)
or len(providers) != (int(count[1]) if count else 0)
or len(names) != sum(map(int, providers))):
raise ValueError('incomplete ELF version needs')
return [n.removeprefix('GLIBC_') for n in names if n.startswith('GLIBC_')]


def raise_error(error):
raise error


def scan(root, tool, ceiling):
checked = 0
exceeded = 0
for directory, dirs, files in os.walk(root, onerror=raise_error):
dirs.sort()
for name in sorted(dirs + files):
path = Path(directory, name)
if path.is_symlink() and not path.resolve(strict=True).is_relative_to(root):
raise ValueError(f'{path}: link leaves bundle')
if path.is_dir():
continue
if not path.is_file():
raise ValueError(f'{path}: expected a regular file')
relative = path.relative_to(root).as_posix()
with path.open('rb') as stream:
if stream.read(4) != b'\x7fELF':
if relative in (*BACKENDS, 'backend/panache-updater', 'handwriting_app') or re.search(r'\.so(?:\.|$)', name):
raise ValueError(f'{relative}: expected ELF')
continue
result = subprocess.run([tool, '-W', '-d', '-V', str(path)], capture_output=True,
text=True, env={**os.environ, 'LC_ALL': 'C'})
if result.returncode or result.stderr.strip():
raise ValueError(f'{relative}: readelf: {result.stderr.strip() or result.returncode}')
try:
highest = max(requirements(result.stdout), key=version, default=None)
except ValueError as error:
raise ValueError(f'{relative}: {error}') from error
checked += 1
if highest and version(highest) > ceiling:
print(f'{relative}: requires GLIBC_{highest}')
exceeded += 1
print(f'{checked} ELF files checked, {exceeded} above the requested ceiling')
return int(bool(exceeded))


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('bundle', type=Path, help='unpacked directory containing backend/')
parser.add_argument('--max-glibc', required=True, type=version, metavar='VERSION')
args = parser.parse_args()
tool = shutil.which('readelf')
if not tool:
print('GNU readelf not found', file=sys.stderr)
return 5
try:
root = args.bundle.resolve(strict=True)
if not root.is_dir():
raise ValueError('expected an unpacked bundle directory')
missing = [name for name in BACKENDS if not (root / name).exists()]
if missing:
print('missing required backend: ' + ', '.join(missing), file=sys.stderr)
return 4
if not (root / 'handwriting_app').is_file():
raise ValueError('missing desktop executable handwriting_app')
return scan(root, tool, args.max_glibc)
except (OSError, ValueError, RuntimeError) as error:
print(error, file=sys.stderr)
return 3


if __name__ == '__main__':
sys.exit(main())
73 changes: 73 additions & 0 deletions scripts/tests/test_linux_glibc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""Run on Linux with a C compiler and GNU binutils."""
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
import unittest


SCRIPT = Path(__file__).resolve().parents[1] / 'check-linux-glibc.py'


@unittest.skipUnless(sys.platform.startswith('linux') and shutil.which('cc') and shutil.which('readelf'),
'requires Linux cc and GNU readelf')
class LinuxGlibcTest(unittest.TestCase):
def setUp(self):
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
self.root = Path(tmp.name)
self.bundle = self.root / 'Panache'
self.backend = self.bundle / 'backend'
self.backend.mkdir(parents=True)
# The provider defines a high version and contains an unrelated version string.
# Only an ELF that imports its function should count against the ceiling.
(self.root / 'provider.c').write_text('const char *probe(void) { return "GLIBC_99.99"; }')
(self.root / 'versions').write_text('GLIBC_2.10 { global: probe; };')
self.provider = self.bundle / 'provider.so'
subprocess.run(['cc', '-shared', '-fPIC', '-nostdlib', 'provider.c',
'-Wl,--version-script=versions', '-o', self.provider], cwd=self.root, check=True)
for rel in ('handwriting_app', 'backend/panache-mcp', 'backend/handwriting-server'):
shutil.copyfile(self.provider, self.bundle / rel)

def check(self, *args, path=None):
env = os.environ.copy()
if path is not None:
env['PATH'] = path
return subprocess.run([sys.executable, SCRIPT, self.bundle, *args],
capture_output=True, text=True, env=env)

def test_definition_string_and_real_import(self):
self.assertEqual(self.check('--max-glibc', '2.9').returncode, 0)
(self.root / 'consumer.c').write_text('extern const char *probe(void);'
'const char *call(void) { return probe(); }')
subprocess.run(['cc', '-shared', '-fPIC', '-nostdlib', 'consumer.c',
self.provider, '-o', self.bundle / 'extra.so'], cwd=self.root, check=True)
result = self.check('--max-glibc', '2.9')
self.assertEqual(result.returncode, 1, result.stderr)
self.assertIn('extra.so: requires GLIBC_2.10', result.stdout)
self.assertEqual(self.check('--max-glibc', '2.10.0').returncode, 0)

def test_missing_backend(self):
(self.backend / 'panache-mcp').unlink()
result = self.check('--max-glibc', '2.41')
self.assertEqual(result.returncode, 4)
self.assertIn('backend/panache-mcp', result.stderr)

def test_damaged_elf(self):
(self.backend / 'handwriting-server').write_bytes(b'\x7fELF')
result = self.check('--max-glibc', '2.41')
self.assertEqual(result.returncode, 3)
self.assertIn('backend/handwriting-server', result.stderr)

def test_missing_tool(self):
self.assertEqual(self.check('--max-glibc', '2.41', path=str(self.root)).returncode, 5)

def test_ceiling_required_and_numeric(self):
self.assertEqual(self.check().returncode, 2)
self.assertEqual(self.check('--max-glibc', 'latest').returncode, 2)


if __name__ == '__main__':
unittest.main()