Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ jobs:
OKRUN_PLACE=0 "$okrun" "$image" one two | tee anywhere.log
grep -q "image ok: 3 args" anywhere.log || { echo "::error::the image placed anywhere"; exit 1; }

- name: ThinLTO keeps thread-local storage emulated
working-directory: checks/lto
run: |
t='${{ matrix.arch }}-openkal'
other=x86_64; [ '${{ matrix.arch }}' = x86_64 ] && other=aarch64
mcpp run --release --target "$t" | tee lto.log
grep -q 'LTO TLS ok' lto.log || { echo "::error::LTO TLS isolation failed"; exit 1; }
mcpp build --release --target "$other-openkal"
py=python3; command -v python3 > /dev/null 2>&1 && python3 -c '' 2>/dev/null || py=python
"$py" - <<'PY'
from pathlib import Path
for arch in ('x86_64', 'aarch64'):
objects = list(Path('target', arch + '-openkal').rglob('main.o'))
if not any(p.read_bytes()[:4] == b'BC\xc0\xde' for p in objects):
raise SystemExit('no ThinLTO bitcode object for ' + arch)
PY

- name: A snapshot of a C++ program's initialisers (0.23.0)
working-directory: checks/snapshot
run: |
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ mcpp pack --target x86_64-openkal --pkg-format okb # one file okrun runs
| hosted | the toolchain and the layers for the host triples, over the system's openkal implementation |
| versions | the release group of the openkal family |

Platform 0.23.6 also sets emulated TLS for the linker's LTO code generation.
Compiling bitcode with `-femulated-tls` alone does not retain that choice at the
final link. Both ordinary object files and ThinLTO builds use the platform's
emulated thread-local storage.

A project overrides any group under `[target.<selector>]`, for example
`[target.'cfg(platform = "openkal")'.layers] "c++-abi" = false`, and selects
another platform, or none, with `platform = "..."` or `--platform`.
Expand Down
16 changes: 16 additions & 0 deletions checks/lto/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "image-lto"
version = "0.1.0"

[language]
standard = "c++23"

[build]
cxxflags = ["-flto=thin"]

[target.'cfg(os = "openkal")']
platform = { path = "../.." }

[targets.image-lto]
kind = "bin"
main = "src/main.cpp"
17 changes: 17 additions & 0 deletions checks/lto/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <cstdio>
#include <thread>

// Volatile accesses keep the TLS operations present under LTO, including the
// main thread's read after a worker changes its own instance.
thread_local volatile int tls_value = 7;

int main() {
int worker_value = 0;
std::thread worker([&] {
tls_value = 9;
worker_value = tls_value;
});
worker.join();
if (worker_value != 9 || tls_value != 7) return 1;
std::puts("LTO TLS ok");
}
5 changes: 3 additions & 2 deletions mcpp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[package]
namespace = "mcpplibs"
name = "openkal-platform"
version = "0.23.5"
version = "0.23.6"
description = "The platform of ok images (<arch>-openkal): their toolchain, C library and C++ run-time, tools, compile and link conventions, seal, runner and carrier, as one versioned statement mcpp reads."
license = "Apache-2.0"
authors = ["mcpplibs"]
Expand Down Expand Up @@ -137,7 +137,8 @@ asmflags = ["-ffixed-x18", "-mno-outline-atomics", "-mbranch-protection=pac-ret+
driver = "lld"
start = "ok_main"
flags = ["-shared", "-z", "max-page-size=65536", "-z", "pack-relative-relocs", "-z", "now", "-z", "noexecstack",
"--hash-style=both", "--gc-sections", "--icf=safe", "--eh-frame-hdr", "--build-id=sha1"]
"--hash-style=both", "--gc-sections", "--icf=safe", "--eh-frame-hdr", "--build-id=sha1",
"-mllvm", "-emulated-tls"]
inputs = [{ from = ["okld", "note-source"], as = "ok-notes.S" }]
exe = "{name}.oke"
shared = "lib{name}.okso"
Expand Down
Loading