Skip to content

Add build hardening and fix build-system inconsistencies - #16

Merged
mattsva merged 2 commits into
mnet-web:mainfrom
mattsva:build/hardening-consistency
Oct 11, 2026
Merged

mattsva merged 2 commits into
mnet-web:mainfrom
mattsva:build/hardening-consistency

Conversation

@mattsva

@mattsva mattsva commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #9. Two commits: build hardening + .gitignore hygiene.

  • Hardening added consistently in Make, CMake and Meson: -fstack-protector-strong; -D_FORTIFY_SOURCE=2 only in optimized build types (it requires optimization — glibc warns otherwise and -Werror would escalate); -Wl,-z,relro,-z,now on Linux only. MSVC needs none: /GS, /DYNAMICBASE and /NXCOMPAT are on by default. /sdl deliberately not added — unverifiable against the /WX Windows build without a Windows machine.
  • Meson gained the missing test_client and test_welcome targets (9 → 11 tests, matching Make/CMake).
  • CMake test targets compile with -UNDEBUG so assertions stay live in Release (previously the suite passed vacuously with NDEBUG).
  • test_mnet.c unused-variable warnings fixed (only triggered at -O2 with -Werror).
  • test_reentrancy moved to port 18780 — it collided with test_security's 18779 and meson runs tests in parallel (intermittent bind failure).
  • .gitignore: added the three missing test binaries, test_welcome and a build-*/ pattern.

Verified: full RELRO (BIND_NOW) + stack canaries on the built library; ctest Debug + Release 11/11; meson debug + release 11/11. Windows and macOS builds not verified locally — see #1.

Stacked on the previous PR in the series; merge in order.

@mattsva
mattsva force-pushed the build/hardening-consistency branch 3 times, most recently from 33bb62f to ff5607f Compare October 11, 2026 13:45
Hardening, consistently in Make, CMake and Meson:
  - -fstack-protector-strong for GCC/Clang
  - -D_FORTIFY_SOURCE=2 only where the build is optimized (at -O0 glibc
    emits a #warning that -Werror would escalate); the Makefile sets no
    -O by default, so FORTIFY is documented for optimized builds there
  - -Wl,-z,relro,-z,now on Linux only (ELF-only; macOS links fine
    without it)
  - MSVC: no new flags - /GS, /DYNAMICBASE and /NXCOMPAT are on by
    default, documented in both CMake and Meson. /sdl was deliberately
    not added because it cannot be verified without a Windows build.

Consistency fixes found while verifying:
  - Meson was missing test_client and test_welcome: it built 9 test
    binaries where Make and CMake build 11. Added.
  - CMake's Release config defines NDEBUG, which compiled every assert()
    out of the test binaries: the suite would have passed vacuously and
    the newly-unused variables failed the build with
    -Werror=unused-but-set-variable. Test targets now compile with
    -UNDEBUG so assertions stay active in every build type.
  - test_mnet.c had set-but-unused variables that only trip at -O2.

Verified: make test (pass), ctest default and Release (11/11, asserts
confirmed active via __assert_fail), meson debug and release (11/11),
full RELRO (BIND_NOW) and stack canaries present in the Make-built
libmnet.so.
test_starvation, test_reentrancy and test_http_edge were built by
make test but never added to .gitignore, so every git add -A swept
the freshly built binaries into the following commit; the build-rel
directory (a CMake build dir) matched nothing because only the exact
name build/ was listed.

Added the three missing test binaries and test_welcome to the test
binary list and build-*/ to the build directory list. The binaries
and build-rel were removed from the unpushed commits with
git filter-branch, so no build artifact is committed on this branch.
@mattsva
mattsva force-pushed the build/hardening-consistency branch from ff5607f to d3b9b1b Compare October 11, 2026 13:50
@mattsva
mattsva merged commit 1027ead into mnet-web:main Oct 11, 2026
8 checks passed
@mattsva
mattsva deleted the build/hardening-consistency branch October 11, 2026 14:10
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.

Build systems are inconsistent and unhardened; CMake Release compiles all assertions out

1 participant