Add Linux (x64) support: presets and POSIX port#31
Conversation
Add x64-linux CMake presets mirroring the Windows/macOS structure and port the platform-specific code to Linux: pthread-based thread ids and getrusage thread times, TracerPid-based debugger detection, /proc/self/exe executable path, O_EXLOCK/O_SHLOCK guards, /proc-based process memory info, UTF-8 <-> wchar_t conversions for non-Apple POSIX, and the standard includes MSVC/AppleClang provided transitively. Also fixes issues surfaced by the port: two source file names with wrong casing in CMakeLists.txt, a strchr null-pointer dereference in CCPCallstack::Enumerate, and a queue::front() call on an empty queue in the telemetry fiber cleanup loop.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 04eed14812
ℹ️ 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".
BSD's O_EXLOCK/O_SHLOCK acquire a flock-style advisory lock atomically at open() time. On platforms without those flags (Linux, Android), apply the equivalent blocking flock() right after opening; if the lock cannot be acquired the descriptor is closed and -1 is returned, matching the failure behavior of the locked open.
sem_timedwait expects an absolute CLOCK_REALTIME timestamp; passing a relative value makes the wait return almost immediately instead of waiting for the requested timeout. Spotted by Patric Stout (TrueBrain) in his Linux port of the Carbon components: https://github.com/TrueBrain/carbonengine-linux
|
Ha, glad to hear it :) Your repo is a goldmine — thanks. I've already adopted your sem_timedwait absolute-time fix into this PR (credited, a795e00). Returning the favor: I put five patches on top of your carbon-core series — two latent bugs I hit while porting independently (a strchr null deref in CcpCallstack::Enumerate that glibc's backtrace_symbols triggers, and a queue::front() on an empty queue in the telemetry fiber cleanup that aborts under _GLIBCXX_ASSERTIONS), flock()-based share-mode locking instead of the O_EXLOCK=0 shims, a debugger-gated CCP_DEBUG_BREAK that re-enables the two memory-guard tests (side note: the old guard tested WIN32, which MSVC doesn't define, so they were off on Windows too), and a codecvt-free UTF-8 conversion (codecvt_utf8 is gone in C++26). Validated on top of your full series at 250df52 with your presets: 189/189 tests pass. GitHub won't let me open a PR against your repo (interaction limits?), so here's the branch, exported with your export-port-patches.sh: TrueBrain/carbonengine-linux@main...LelandJin:carbonengine-linux:core-fixes — feel free to pull it in however you prefer. |
The option existed but the build was broken with it: CcpSemaphore/CcpMutex/CcpStatistics include tracy headers unconditionally (no include path without find_package(Tracy)), CCPMemory and CcpSemaphore relied on tracy's include chain to reach the CcpSecureCrt shims, and the test target always compiled the Tracy client tests and linked Tracy::TracyClient. Guard the tracy includes behind CCP_TELEMETRY_ENABLED, include CcpSecureCrt.h explicitly, and only build/link the telemetry tests when WITH_TELEMETRY is on. The missing CcpSecureCrt.h include in CCPMemory.cpp was spotted by Patric Stout (TrueBrain) in his Linux port: https://github.com/TrueBrain/carbonengine-linux
|
Two more verified additions to this PR:
Validated on the x64-linux-debug preset in both configurations: default 184/184 tests pass, |
Summary
Adds Linux (x64) support to carbon core. Configures, builds, and passes the full test suite (184/184, GCC 15 / Fedora 43) with the new presets.
Build system
CMakePresets.json: new hiddenlinux/x64-linuxbase presets (conditionhostSystemName == Linux) and concretex64-linux-{debug,internal,release,trinitydev}presets, mirroring the Windows/macOS structure. Toolchain and triplets come from the companion vcpkg-registry PR.CMakeLists.txt: two file names fixed to their on-disk casing (CcpDefines.cpp,CcpMemoryTrackerMutex.h) — case-insensitive filesystems masked this; Linux fails to configure without it.Platform port (the existing POSIX
#elsebranches already cover most of Linux; these fill the gaps)include/CcpThread.h/CcpThread.cpp:__linux__uses the shared POSIX implementation withpthread_tids/handles andCcpGetThreadTimesviagetrusage(RUSAGE_THREAD)(same 100 ns units as other platforms).CCPAssert.cpp: LinuxCcpIsDebuggerPresent()readingTracerPidfrom/proc/self/status;include/CCPAssert.hnow uses the same debugger-gatedCCP_DEBUG_BREAKon Linux as on macOS.CcpFileUtils.cpp: guard BSD-onlyO_EXLOCK/O_SHLOCK;CcpExecutablePath()viareadlink("/proc/self/exe").CCPMemory.cpp:CcpGetProcessMemoryInfo()from/proc/self/status+getrusage.StringConversions.cpp: UTF-8 ⇄wchar_t(UTF-32) conversions for non-Apple POSIX (on macOS these overloads live inStringConversions.mm); passes the existing round-trip tests.<cstdint>,<climits>,<sys/time.h>,<cstring>,<atomic>,<cmath>).Bug fixes surfaced by the port (latent on all platforms)
CCPCallstack.cpp:strchrresult was dereferenced before the null check inEnumerate— glibcbacktrace_symbolslines without+crashed; macOS lines always contain+so it never fired there.CcpTelemetry.cpp: fiber-cleanup loop calledqueue::front()after popping the last element (UB; aborts under_GLIBCXX_ASSERTIONS).No behavior changes on Windows or macOS — all platform branches are additive.
Validation
cmake --preset x64-linux-debug.ctest: 184/184 tests pass (5 disabled upstream, unchanged).Notes
x64-linuxtriplets/toolchains; the vendored registry submodule needs a pointer bump once that merges.DT_INITof shared libraries emitted by newer binutils during its RPATH fixup (loader crash incall_init— first seen when python3's_ctypesloads libffi). Using patchelf ≥ 0.18 resolves it; worth pinning when Linux CI is set up.