Skip to content

Fix the standalone SourceHook test build - #283

Open
makadore wants to merge 3 commits into
alliedmodders:1.12-devfrom
makadore:fix/sourcehook-test-build
Open

makadore wants to merge 3 commits into
alliedmodders:1.12-devfrom
makadore:fix/sourcehook-test-build

Conversation

@makadore

Copy link
Copy Markdown

The standalone core/sourcehook/test/Makefile had drifted from test/AMBuilder far enough that it no longer linked. Since AMBuilder builds these tests for x86 only and neither CI workflow runs them, nothing noticed. Five things were missing: the architecture-specific hook generator source and its symlink, added when hookmangen was split; SOURCEHOOK_TESTS, without which SH_DEBUG_LOG pulls in g_SHPtr that only core/metamod.cpp defines; core/ on the include path; and -fno-devirtualize.

That last one is worth calling out on its own. Without it the suite builds and then fails ten of its sixteen tests and segfaults, which reads as SourceHook being broken rather than as a missing flag — devirtualisation assumes the vtable entries SourceHook swaps cannot change. With all five the suite is green at 16/16, on both CPP="gcc -m32" and CPP=i686-linux-gnu-gcc.

x86_64 stays out, matching AMBuilder: that generator includes metamod.h and the HL2SDK, which a standalone build does not have. Building natively on x86_64 now says so instead of failing on a missing interface.h.

Two warnings the revived build surfaced are fixed in their own commits. CHookContext's constructor set m_CleanupTask and left eleven members indeterminate; nothing reads them today, since SetupHookLoop writes them before use, and it costs nothing on the dispatch path because contexts there come from CStack::make_next() out of an already-constructed sector. ModuleInMemory scanned /proc/curproc/map into long while using %lx and comparing against unsigned values, which the Linux branch five lines above already gets right; behaviour is unchanged, and that branch does not run on Linux so it is compile-tested only.

Not related to #191, which is about orig_ret in SH_SETUPCALLS. That one looks like it needs initialising a return value on every hooked call, so it seemed worth leaving to you rather than paying for it on the dispatch path.

@Kenzzer

Kenzzer commented Aug 26, 2026

Copy link
Copy Markdown
Member

Any reason you've decided not to use #223 ?

Personally I'm not against merging this, but if we do, the other PR is going to blow up sourcehook anyways. Still this is nice to have so perhaps the PR should be retargetted towards 1.12-dev branch

The Makefile had drifted from test/AMBuilder far enough that it no longer
linked, and since AMBuilder only builds these tests for x86 and CI does not
run them at all, nothing noticed. Five things were missing: the
architecture-specific hook generator source and its symlink, added when
hookmangen was split; SOURCEHOOK_TESTS, without which SH_DEBUG_LOG pulls in
g_SHPtr, defined only in core/metamod.cpp; core/ on the include path; and
-fno-devirtualize.

That last one is worth calling out. Without it the suite builds and then
fails ten of its sixteen tests and segfaults, which looks like SourceHook is
broken rather than like a missing flag: devirtualisation assumes the vtable
entries SourceHook swaps cannot change. AMBuilder passes it from gcc-4.9 on.
With all five, the suite is green.

x86_64 is left out on purpose, matching AMBuilder: that generator includes
metamod.h and the HL2SDK, which a standalone build does not have. Building
natively on x86_64 now says so instead of failing on a missing interface.h.
The constructor set m_CleanupTask and left the other eleven indeterminate.
SetIgnoreHooks pushes a context with only m_State filled in, so GCC warns
that the rest may be used uninitialized.

Nothing reads them today: SetupHookLoop writes pVfnPtr and the others before
any use, which the compiler cannot see. So this is removing a trap rather
than fixing a fault, and it costs nothing on the dispatch path, where
contexts come from CStack::make_next() out of an already-constructed sector
rather than from this constructor.

This is not the warning in alliedmodders#191, which is about orig_ret in SH_SETUPCALLS.
ModuleInMemory reads /proc/curproc/map into long, though it scans with %lx,
which takes unsigned long, and compares against lower and upper, which are
unsigned. The Linux branch five lines above already declares them unsigned.

Behaviour is unchanged: the bit patterns match and the comparison converts
to unsigned anyway. It is the format specifier and 22 warnings. Compile
tested only, as the branch does not run on Linux.
@makadore
makadore force-pushed the fix/sourcehook-test-build branch from 1fe8920 to e4629a0 Compare August 26, 2026 20:53
@makadore
makadore changed the base branch from master to 1.12-dev August 26, 2026 20:53
@makadore

Copy link
Copy Markdown
Author

Started from what was in front of me: I hit this while working on the x86_64 generator, fixed it there, and only looked at the open PR list afterwards, which was the wrong order. #223 is clearly the direction and I am not trying to work around it.

1.12-dev works. Rebased onto it and retargeted. The hunk in sh_memory.h is identical on both branches even though the file is not, so the three commits apply unchanged. Checked there too: on a clean 1.12-dev the standalone test build fails at link, and with these it builds and the suite runs 16 of 16.

The same question applies to #285, which makes the x86_64 generator work on Linux. Its value is on the Source 2 side, which is the side #223 replaces. Worth landing before that, or would you rather I close it? Happy either way, I would just rather ask than leave it sitting.

@Kenzzer

Kenzzer commented Aug 27, 2026

Copy link
Copy Markdown
Member

I think both PRs are very valuable to have regardless and we should merge them in 1.12 if we can.

MMS is going to/has diverge(d) starting with version 2.0, but version 1.X is still gonna stick around. I can't review either PR for now, and its probably going to sit like this for a few weeks. But should I find any issues, I will most likely commit the requested changes.

Thanks again for your work.

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.

2 participants