Skip to content

drm: stop obfuscating the strings, and gate PRs on a warning-free build - #66

Merged
joshuatam merged 3 commits into
masterfrom
refactor/drm-structure
Nov 11, 2026
Merged

joshuatam merged 3 commits into
masterfrom
refactor/drm-structure

Conversation

@joshuatam

@joshuatam joshuatam commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Two commits on top of master, both structural: the codebase stops hiding its own text, and a PR gate starts checking that it builds clean.

1. String obfuscation is gone (1c7ec59)

gndrm-obf and gndrm-obf-macros XOR-encoded every message literal and decoded it into a stack buffer at the use site, so strings over a shipped artifact found nothing. The project is open source; a diagnostic a user can pull out of the .so is worth more than one they cannot.

Both crates are deleted, with every dependency on them. 585 gndrm_obf::obf! and one obfc! across the ICD shim, the daemon and the app side collapse to the message they carried:

  • a literal with no placeholders is the literal;
  • anything else is the message and its arguments.

The log macros absorb the formatting: logf!, logi! and log_reason! take $($arg:tt)* and pass them to format_args!, so a call site reads logf!("proxy pool: fourcc 0x{:x} route={}", …) instead of wrapping a wrapper. log_reason! still builds and stores the line, because it is reported as the reason a process got no driver.

log.rs's logcat tag was the single obfc! use — six gate tags decoded into a NUL-terminated buffer. They are c"…" literals now, and tag! takes an expression rather than a string literal.

Four Display impls were formatting into a String and writing that; they write the message straight now.

C side: tools/obf-shim.py rewrote each LOG(...) site in the LD_PRELOAD shim at build time and build-shim.sh compiled the generated copy from target/shim/gen/. The script is deleted; the shim compiles its source as written, so the shipped libgndrm_shim.so carries intercepting %s for %s in %s and the rest.

Manifests: the crate entries leave the workspace, and the dependency lines — with the comments that explained why the obfuscation existed — leave gndrm-android, gndrm-daemon, gndrm-lsfg, gndrm-uapi and icd_shim.

Prose that described the removed behaviour is corrected: the log module docs, the daemon's two logger thunks ("stack decode"), asc.rs's refusal labels, and docs/performance/05's "no heap" row, which justified itself by pointing at gndrm-obf/src/lib.rs:46. The historical diff hunks in 05 and 06 are left alone — they record patches as applied.

THIRD_PARTY_NOTICES listed "the obfuscation crates" in the licence scope; it lists the ICD shim.

47 files changed, 835 insertions(+), 2228 deletions(-)

2. A PR gate that builds with warnings as errors (9aa1364)

cargo build  --workspace --all-targets --locked          # RUSTFLAGS=-D warnings
cargo clippy --workspace --all-targets --locked -- -D warnings

--all-targets is the part that earns its keep: test and bench targets compile too, so a change that only breaks a test build fails the gate rather than the reviewer. No artifacts, no report — the job status is the output.

Host build only, and the workflow header says why: tools/build-android.sh and build-shim.sh android need the NDK, the gamescope termux prefix and the export / undefined-symbol audits that read the cross build's output. No cargo fmt --check either — the tree is hand-formatted.

Verified

From a cold target directory, which is the closest local proxy for a first CI run:

cargo build  --workspace --all-targets --locked   rc 0, 0 warnings   (RUSTFLAGS=-D warnings)
cargo clippy --workspace --all-targets --locked   rc 0, 0 warnings/errors
cargo test   --workspace                          340 passed, 0 failed (30 suites)
tools/build-android.sh                            rc 0, check-exports PASS (20 / 3 / 14 exports)
tools/build-shim.sh android                       rc 0, check-exports PASS
actionlint 1.7.12                                 0 parse errors, 0 errors

The gate itself runs green on this PR, third commit and after: host build, no warnings — cargo build and cargo clippy both finished with no output beyond the compile lines, run 42954604587.

Its first run failed, and the failure is why the workflow now installs six dev packages: gn-utils and icd_shim/src/x11.rs carry #[link] attributes for the host's Vulkan, wayland and xcb, so on a bare runner the build died at link time — unable to find library -lvulkan / -lwayland-client — rather than in the code. Fixed in 49bcdb3, verified in a clean ubuntu:24.04 container that had only those packages added.

And the point of part 1, in the rebuilt libraries:

$ strings libadrenotools_gamescope.so
gn-vkshim: override target: named=0x
gn-vkshim: override: XID
gn-vkshim: proxy pool: fourcc …
$ strings libgndrm_shim.so
intercepting %s for %s in %s

Not in this PR

  • No device run. The change is a representation change: the same strings reach the same sinks with the same gates. The two shipped libraries were rebuilt and their log text verified with strings, but nothing ran on hardware.
  • No cargo test in CI yet. One line in the workflow when it is wanted; it was scoped to "build with no warnings".
  • The THIRD_PARTY_NOTICES copyright line still names Utkarsh Dalal while README and Cargo.toml name Joshua Tam and GameNative Inc. after licence: GPL-3.0-or-later, and both copyright holders named #52. Left alone rather than change a holder inside a refactor.

`gndrm-obf` and `gndrm-obf-macros` XOR-encoded every message literal and decoded
it into a stack buffer at the use site, so `strings` over a shipped artifact
found nothing. Both crates are deleted, with every dependency on them. The log
text is a plain literal again, and that is the point: a diagnostic a user can
grep out of the .so is worth more than one they cannot.

Rust call sites — 585 `gndrm_obf::obf!` and one `obfc!`, across the ICD shim,
the daemon and the app side:

- a literal with no placeholders is the literal;
- anything else is the message and its arguments, e.g.
  `logf!("proxy pool: fourcc 0x{:x} route={}", …)`.

The log macros do the formatting now: `logf!`, `logi!` and `log_reason!` take
`$($arg:tt)*` and pass them to `format_args!`, so a call site is the message and
not a wrapper around it. `log_reason!` still owns the line, because it stores it
as the reported reason.

`log.rs`'s logcat tag was the one `obfc!` use — six gate tags decoded into a
NUL-terminated buffer. They are `c"…"` literals now, and the `tag!` arm takes an
expression rather than a string literal.

Four `Display` impls were rewritten to write the message straight
(`write!(f, "{layout} (env)")`) instead of formatting into a `String` first.

C side: `tools/obf-shim.py` rewrote each `LOG(...)` site in the LD_PRELOAD shim
into an XOR-decode at build time, and `build-shim.sh` compiled the generated copy
from `target/shim/gen/`. The script is deleted and the shim compiles its source
as written, so the shipped `libgndrm_shim.so` now carries `intercepting %s for %s
in %s` and the rest.

Manifests: the two crate entries leave the workspace, and the dependency lines
(and the comments explaining why the obfuscation existed) leave
`gndrm-android`, `gndrm-daemon`, `gndrm-lsfg`, `gndrm-uapi` and `icd_shim`.

Text that described the removed behaviour: the log module docs said the tag is
decoded at runtime; `gndrm-daemon`'s two logger thunks explained a "stack
decode"; `asc.rs` said its refusal labels are owned because the literals are
obfuscated; `docs/performance/05` justified "no heap" by pointing at
`gndrm-obf/src/lib.rs:46`. All four now state what the code does. The historical
diff hunks in 05 and 06 are left as they were — they record patches as applied.

`THIRD_PARTY_NOTICES` listed "the obfuscation crates" in the licence scope; it
lists the ICD shim instead.

Verified: `cargo clippy --workspace --all-targets -- -D warnings` clean,
`cargo test --workspace` 340 passed / 0 failed across 30 suites,
`tools/build-android.sh` green through the export allowlist and undefined-symbol
audit, `tools/build-shim.sh android` green. `strings` on both rebuilt libraries
now shows the log text.
`cargo build --workspace --all-targets` under `RUSTFLAGS=-D warnings`, then
`cargo clippy --workspace --all-targets -- -D warnings`. Both `--locked`.

`--all-targets` is the part that earns its keep: it compiles the test and bench
targets too, so a change that only breaks a test build fails the gate instead of
failing at review. No artifacts are produced or uploaded — the job's status is
the output.

Host build only. `tools/build-android.sh` and `build-shim.sh android` need the
NDK, the gamescope termux prefix (`GAMESCOPE_TERMUX_PREFIX`) and the export /
undefined-symbol audits that read the cross build's output, which a hosted
runner cannot stand up; the workflow header says so, so nobody reads a green run
as covering the shipped artifacts.

No `cargo fmt --check`: the tree is hand-formatted, and a fmt gate would fail
every PR.

Verified from a cold target directory, which is the closest local proxy for a
first CI run: `cargo build` rc 0 with 0 warnings, `cargo clippy` rc 0, and
actionlint 1.7.12 reports 0 parse errors and 0 errors.
The first run failed at link time, not in the code:

    rust-lld: error: unable to find library -lvulkan
    rust-lld: error: unable to find library -lwayland-client
    error: could not compile `gn-utils` (bin "gn-device-probe" test)

`gn-utils` (and `icd_shim/src/x11.rs`) carry `#[link]` attributes for the host's
Vulkan, wayland and xcb, so `--all-targets` on a bare runner cannot link its
binaries. The runner now installs `libvulkan-dev`, `libwayland-dev`,
`libxcb1-dev`, `libxcb-dri3-dev`, `libxcb-present-dev` and `libxcb-sync-dev`
before building — the same set a developer machine has to have.

Verified in a clean `ubuntu:24.04` container with only those packages added,
which is what the runner is: `cargo build --workspace --all-targets --locked`
under `RUSTFLAGS=-D warnings` rc 0 with no warnings, and
`cargo clippy --workspace --all-targets --locked -- -D warnings` rc 0, both with
the current stable toolchain (1.99.1) rather than the local 1.98.0. actionlint
reports 0 errors.
@joshuatam
joshuatam merged commit b76de03 into master Nov 11, 2026
1 check passed
@joshuatam
joshuatam deleted the refactor/drm-structure branch November 11, 2026 03:48
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.

1 participant