Skip to content

Conversation

@flyingrobots
Copy link
Owner

M2: Minimal Linux CRT shim (_start) and freestanding CI job (opt‑in)

Summary

  • Add a tiny Linux x86_64 CRT entry (crt/linux/x86_64/crt0.S) that calls main(argc, argv) and exits via SYS_exit.
  • Provide an opt‑in freestanding smoke executable (gitledger_ffs_smoke) that exercises version APIs without libc.
  • Wire CMake and Meson to only build the freestanding smoke when explicitly enabled:
    • CMake: -DGITLEDGER_USE_NOSTDLIB=ON injects crt0.S and -nostdlib for the smoke.
    • Meson: -Dexec_nostdlib=true builds the smoke with crt0.S and -nostdlib.
  • Keep the library linked with -nostdlib on non‑MSVC to maintain “pure” object files.
  • Add a new CI lane (freestanding-linux) that builds and runs the smoke on Ubuntu.

Guardrails (as discussed)

  • No libc emulation, malloc, or printf.
  • Ubuntu-only CI lane; macOS and Windows untouched.
  • Target is “build & exit 0”; argv/envp and I/O can come later.

CI expectations

  • Default matrix remains unchanged (flag OFF).
  • The freestanding-linux job validates the opt‑in path.

References

Policy note

  • GITLEDGER_USE_NOSTDLIB stays default‑OFF in the main matrix until we promote enforcement in a follow‑up.

…NOLINT; local tidy override

What and why
- Prevent double-free/UAF by making contexts registries, not owners.
- Snapshot allocator in gitledger_error_t so release is safe post-context teardown.
- Enforce lifecycle: in debug, abort if context has live errors; in release, refuse to destroy and log.
- Remove all NOLINT and refactor to satisfy clang-tidy: split teardown helpers, safe snprintf+fwrite logging, named constants.
- Restore global .clang-tidy and localize the bugprone-easily-swappable-parameters disable under libgitledger/core/ to account for C callback signatures.
- Reaffirm host execution guard in AGENTS.md.

Validation
- Format + clang-tidy: clean locally.
- Unit tests + ASAN/UBSAN + TSAN: green locally (macOS leak detection disabled as unsupported).

Follow-ups
- Add a unit test to assert teardown refusal semantics.
- Optional single-shot structured diagnostic for lifecycle violations.

No rebase, no amend, no force. Logged activity before committing.
…d API updates, test for teardown refusal

- Build config: switch to C99, set strict flags (-Wall -Wextra -Werror -pedantic -std=c99 -Wno-fun), add -nostdlib to lib and executables.
- Docs: memoizes -> memoizes; clarify Release refusal + stderr diagnostic; contexts register but don’t own errors.
- Headers: remove unused gitledger_status_t; update lifetime comment to debug abort / release refusal; replace inline creators with caller-location macros; add try_release prototype.
- Context: always-on diagnostic logging; lock errors list before destroy decision; add gitledger_context_try_release(); rename count helper to *_locked.
- Error JSON: add rationale comments; CAS-publish json_cache and free via atomic exchange to avoid races.
- Tests: safer malloc idiom; add Release-only teardown refusal test using try_release.
- Activity: fix legacy epoch timestamps to RFC 3339 strings.
- Meson: add strict c_args and -nostdlib link_args for test executables.
- Container: export sanitizer/analyzer support env hints; Makefile: add frame pointers and TSAN -O1.
- Remove -nostdlib from executables (CMake) to link libc in tests.
- Make macros portable: avoid GNU ##__VA_ARGS__ by capturing fmt via __VA_ARGS__ only.
…ibility=hidden) and add -nostdlib to all executables (gated for non‑MSVC)
…on returns required length and NUL-terminates
…ics (return required length; NUL on truncation; n=0 no write)
…ck-use-after-return); proper scan-build wrapping
…d OOM tracking diagnostic and destroy-path invariant comment; clarify header docs
…lu); dedupe Meson std flag; add optional -nostdlib for executables (CMake+Meson); prune duplicate container env exports
…ten .clang-tidy (clang-diagnostic, security, magic-numbers); MSVC to C99
…onfigured hooks via core.hooksPath, verified tools/hooks/pre-commit runs the same containerised clang-format check as CI, and updated CONTRIBUTING with install/escape instructions. Local matrix green after check.\n\nThis keeps style drift out of the ledger and spares reviewers the churn.
… blurb under Contributing that points newcomers to:\n- make hooks-install (pre-commit runs the containerised format-check),\n- SKIP_FORMAT_CHECK escape hatch for WIP commits,\n- make test-both and make lint to mirror CI locally.\n\nCONTRIBUTING.md remains the canonical detailed guide.
…an ISSUE-DRAFT describing a minimal Linux x86_64 _start shim and a dedicated CI job that builds executables with -nostdlib via GITLEDGER_USE_NOSTDLIB/exec_nostdlib, keeping the main matrix unchanged.
…0\n\nRemoves the literal 10 from the loop to match write_decimal() and the enum constants; behavior unchanged.
… CI job\n\nCreated GitHub issue #47 with labels milestone::M2, area::build, type::enhancement.\nReferences PR #46; notes that GITLEDGER_USE_NOSTDLIB stays default-OFF until closure.
… and constraints on PR #46 and issue #47; keep GITLEDGER_USE_NOSTDLIB default-OFF in main matrix and add freestanding-linux CI lane targeting minimal _start→main with exit 0.
…t/linux/x86_64/crt0.S (_start → main → SYS_exit)\n- Add tests/ffs_smoke.c (no libc; exercises version APIs)\n- CMake: gate -nostdlib + CRT to the smoke via GITLEDGER_USE_NOSTDLIB=ON; keep library -nostdlib\n- Meson: add gitledger_ffs_smoke only under -Dexec_nostdlib=true\n- CI: new freestanding-linux job builds and runs ffs_smoke on Ubuntu\n\nScope intentionally minimal; main matrix remains unchanged.
@flyingrobots flyingrobots added milestone::M2 Tasks for milestone M2 area::build Build system and CI type::enhancement Enhancement / feature request labels Oct 31, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 31, 2025

Warning

Rate limit exceeded

@flyingrobots has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2bc3308 and 5b30308.

⛔ Files ignored due to path filters (3)
  • AGENTS.md is excluded by !*.md
  • CONTRIBUTING.md is excluded by !*.md
  • README.md is excluded by !*.md
📒 Files selected for processing (28)
  • .clang-tidy (2 hunks)
  • .github/workflows/ci.yml (3 hunks)
  • .gitignore (1 hunks)
  • ACTIVITY.log.jsonl (1 hunks)
  • CMakeLists.txt (3 hunks)
  • Makefile (4 hunks)
  • crt/linux/x86_64/crt0.S (1 hunks)
  • docs/ISSUE-DRAFTS.md (1 hunks)
  • docs/SPEC.md (1 hunks)
  • include/gitledger/context.h (1 hunks)
  • include/gitledger/error.h (1 hunks)
  • include/gitledger/export.h (1 hunks)
  • libgitledger/core/.clang-tidy (1 hunks)
  • libgitledger/core/context.c (1 hunks)
  • libgitledger/core/domain/error.c (1 hunks)
  • libgitledger/core/domain/gitledger.c (1 hunks)
  • libgitledger/core/internal/context_internal.h (1 hunks)
  • meson.build (5 hunks)
  • meson_options.txt (1 hunks)
  • src/version.c (3 hunks)
  • tests/error_test.c (1 hunks)
  • tests/ffs_smoke.c (1 hunks)
  • tests/version_test.c (3 hunks)
  • tools/container/Dockerfile (1 hunks)
  • tools/container/run-matrix.sh (5 hunks)
  • tools/hooks/pre-commit (1 hunks)
  • tools/lint/run_clang_tidy.sh (1 hunks)
  • tools/lint/validate_activity_log.sh (1 hunks)
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch task/m2-linux-crt-shim

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@flyingrobots flyingrobots marked this pull request as ready for review October 31, 2025 00:28
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +751 to +752
gitledger_context_track_error_internal(ctx, err);
return err;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle failure to register errors with context

When gitledger_context_alloc fails inside context_register_error, the helper logs a warning and returns without linking the error into the context’s registry. create_error_internal ignores that possibility and still returns the error with err->ctx pointing at the context. The context can subsequently be destroyed because it believes no errors are live, leaving the returned error with a dangling context pointer; any later call to gitledger_error_release or gitledger_error_json will dereference freed memory. The creation path should either detach the context on registration failure or propagate an error instead of returning an untracked object.

Useful? React with 👍 / 👎.

Comment on lines +20 to +24
lea 8(%rsp), %rsi // rsi = &argv[0]

// Call user main(argc, argv)
.extern main
call main

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Align stack before invoking main in freestanding CRT

The new _start for the freestanding Linux shim calls main with the stack pointer exactly as provided by the kernel. Because a call instruction pushes a return address, main receives %rsp misaligned (16n–8) and the System V AMD64 ABI requirement that the stack be 16‑byte aligned on function entry is violated. Any main compiled with stack‑aligned SSE instructions can fault. Adjust %rsp (e.g. subtract 8 or mask to 16) before the call to maintain ABI alignment.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area::build Build system and CI milestone::M2 Tasks for milestone M2 type::enhancement Enhancement / feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants