Files
RedBear-OS/local/recipes/dev/libclc/source/lld/test/COFF/arm64ec-patchable-thunks.test
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

106 lines
4.3 KiB
Plaintext

REQUIRES: aarch64, x86
RUN: split-file %s %t.dir && cd %t.dir
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows arm64ec-patchable.s -o arm64ec-patchable.obj
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows arm64ec-alias.s -o arm64ec-alias.obj
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows test-sec.s -o test-sec.obj
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o loadconfig-arm64ec.obj
RUN: llvm-mc -filetype=obj -triple=aarch64-windows %S/Inputs/loadconfig-arm64.s -o loadconfig-arm64.obj
RUN: lld-link -out:test.dll -machine:arm64ec arm64ec-patchable.obj test-sec.obj loadconfig-arm64ec.obj -dll -noentry
RUN: llvm-objdump -d test.dll | FileCheck -check-prefix=PATCH-DISASM %s
PATCH-DISASM: Disassembly of section .text:
PATCH-DISASM-EMPTY:
PATCH-DISASM-NEXT: 0000000180001000 <.text>:
PATCH-DISASM-NEXT: 180001000: 52800040 mov w0, #0x2 // =2
PATCH-DISASM-NEXT: 180001004: d65f03c0 ret
PATCH-DISASM-EMPTY:
PATCH-DISASM-NEXT: Disassembly of section .hexpthk:
PATCH-DISASM-EMPTY:
PATCH-DISASM-NEXT: 0000000180002000
PATCH-DISASM-NEXT: 180002000: 48 8b c4 movq %rsp, %rax
PATCH-DISASM-NEXT: 180002003: 48 89 58 20 movq %rbx, 0x20(%rax)
PATCH-DISASM-NEXT: 180002007: 55 pushq %rbp
PATCH-DISASM-NEXT: 180002008: 5d popq %rbp
PATCH-DISASM-NEXT: 180002009: e9 f2 ef ff ff jmp 0x180001000 <.text>
PATCH-DISASM-NEXT: 18000200e: cc int3
PATCH-DISASM-NEXT: 18000200f: cc int3
RUN: llvm-readobj --hex-dump=.test test.dll | FileCheck -check-prefix=RVA %s
RVA: 0x180006000 00200000
RUN: llvm-readobj --coff-load-config test.dll | FileCheck -check-prefix=PATCH-CHPE %s
PATCH-CHPE: CodeMap [
PATCH-CHPE-NEXT: 0x1000 - 0x1008 ARM64EC
PATCH-CHPE-NEXT: 0x2000 - 0x2010 X64
PATCH-CHPE-NEXT: ]
PATCH-CHPE-NEXT: CodeRangesToEntryPoints [
PATCH-CHPE-NEXT: 0x2000 - 0x2010 -> 0x2000
PATCH-CHPE-NEXT: ]
PATCH-CHPE-NEXT: RedirectionMetadata [
PATCH-CHPE-NEXT: 0x2000 -> 0x1000
PATCH-CHPE-NEXT: ]
RUN: lld-link -out:test2.dll -machine:arm64ec arm64ec-alias.obj test-sec.obj loadconfig-arm64ec.obj -dll -noentry
RUN: llvm-objdump -d test2.dll | FileCheck -check-prefix=PATCH-DISASM %s
RUN: llvm-readobj --hex-dump=.test test2.dll | FileCheck -check-prefix=RVA %s
RUN: llvm-readobj --coff-load-config test2.dll | FileCheck -check-prefix=PATCH-CHPE %s
RUN: lld-link -out:test3.dll -machine:arm64ec arm64ec-alias.obj test-sec.obj loadconfig-arm64ec.obj -dll -noentry -export:patchable_func
RUN: llvm-objdump -d test3.dll | FileCheck -check-prefix=PATCH-DISASM %s
RUN: llvm-readobj --hex-dump=.test test3.dll | FileCheck -check-prefix=RVA %s
RUN: llvm-readobj --coff-load-config test3.dll | FileCheck -check-prefix=PATCH-CHPE %s
RUN: not lld-link -out:test4.dll -machine:arm64ec test-sec.obj loadconfig-arm64ec.obj -dll -noentry 2>&1 | FileCheck --check-prefix=ERR %s
ERR: error: undefined symbol: EXP+#patchable_func (EC symbol)
RUN: lld-link -out:testx.dll -machine:arm64x arm64ec-patchable.obj test-sec.obj \
RUN: loadconfig-arm64.obj loadconfig-arm64ec.obj -dll -noentry
RUN: llvm-objdump -d testx.dll | FileCheck -check-prefix=PATCH-DISASM %s
RUN: llvm-readobj --coff-load-config testx.dll | FileCheck -check-prefix=PATCH-CHPE %s
RUN: lld-link -out:testx2.dll -machine:arm64x arm64ec-alias.obj loadconfig-arm64.obj \
RUN: loadconfig-arm64ec.obj -dll -noentry
RUN: llvm-objdump -d testx2.dll | FileCheck -check-prefix=PATCH-DISASM %s
RUN: llvm-readobj --coff-load-config testx2.dll | FileCheck -check-prefix=PATCH-CHPE %s
#--- arm64ec-patchable.s
.section ".text", "x", discard, "#patchable_func$hp_target"
.globl "#patchable_func$hp_target"
.p2align 2, 0x0
"#patchable_func$hp_target":
mov w0, #2
ret
.def "EXP+#patchable_func"
.scl 2
.type 32
.endef
#--- arm64ec-alias.s
.section ".text", "x", discard, "#patchable_func$hp_target"
.globl "#patchable_func$hp_target"
.p2align 2, 0x0
"#patchable_func$hp_target":
mov w0, #2
ret
.def "EXP+#patchable_func"
.scl 2
.type 32
.endef
.weak patchable_func
patchable_func = "EXP+#patchable_func"
#--- test-sec.s
.section ".test", "rd"
.rva "EXP+#patchable_func"