feat(selfhost): achieve binary-identical selfhost loop
- Add -Wl,--build-id=none to C compilation flags (removes non-deterministic build ID) - Update Makefile selfhost-loop to strip debug info before ELF comparison - Bootstrap compiler and selfhost compiler both deterministic
This commit is contained in:
@@ -123,14 +123,16 @@ selfhost-loop: build
|
||||
else \
|
||||
echo " C output: DIFFERENT ✗"; \
|
||||
fi
|
||||
@echo "Comparing ELF binaries..."
|
||||
@if diff build/selfhost-loop-a/build/buxc2 build/selfhost-loop-b/build/buxc2 > /dev/null 2>&1; then \
|
||||
@echo "Comparing ELF binaries (stripped)..."
|
||||
@cp build/selfhost-loop-a/build/buxc2 /tmp/buxc2_a && strip -d /tmp/buxc2_a
|
||||
@cp build/selfhost-loop-b/build/buxc2 /tmp/buxc2_b && strip -d /tmp/buxc2_b
|
||||
@if diff /tmp/buxc2_a /tmp/buxc2_b > /dev/null 2>&1; then \
|
||||
echo " ELF binary: IDENTICAL ✓"; \
|
||||
echo "=== Selfhost loop PASSED ==="; \
|
||||
else \
|
||||
echo " ELF binary: DIFFERENT ✗ (may be due to timestamps)"; \
|
||||
echo " C output was identical — ELF difference is likely linker non-determinism"; \
|
||||
echo "=== Selfhost loop: C codegen deterministic ✓, ELF non-deterministic (expected) ==="; \
|
||||
echo " ELF binary: DIFFERENT ✗"; \
|
||||
echo "=== Selfhost loop FAILED ==="; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
lsp: tools/bux-lsp
|
||||
|
||||
+1
-1
@@ -488,7 +488,7 @@ proc cmdBuild*(args: seq[string], opts: GlobalOptions): int =
|
||||
# Compile with cc
|
||||
let outputName = if pctx.man.name != "": pctx.man.name else: "bux_out"
|
||||
let outputFile = buildDir / outputName
|
||||
let ccCmd = &"cc -O0 -g -pthread -o {outputFile} {cFile} {runtimeDst} {ioDst} -lm -lcrypto 2>&1"
|
||||
let ccCmd = &"cc -O0 -g -pthread -Wl,--build-id=none -o {outputFile} {cFile} {runtimeDst} {ioDst} -lm -lcrypto 2>&1"
|
||||
if opts.verbose:
|
||||
printInfo(&"running: {ccCmd}", useColor)
|
||||
let (output, exitCode) = execCmdEx(ccCmd)
|
||||
|
||||
+4
-4
@@ -255,13 +255,13 @@ func Cli_Build(srcPath: String, outPath: String, targetTriple: String, isRelease
|
||||
if !String_Eq(targetTriple, "") {
|
||||
StringBuilder_Append(&cmdBuf, "clang ");
|
||||
StringBuilder_Append(&cmdBuf, optFlags);
|
||||
StringBuilder_Append(&cmdBuf, " -pthread -target ");
|
||||
StringBuilder_Append(&cmdBuf, " -pthread -Wl,--build-id=none -target ");
|
||||
StringBuilder_Append(&cmdBuf, targetTriple);
|
||||
StringBuilder_Append(&cmdBuf, " ");
|
||||
} else {
|
||||
StringBuilder_Append(&cmdBuf, "cc ");
|
||||
StringBuilder_Append(&cmdBuf, optFlags);
|
||||
StringBuilder_Append(&cmdBuf, " -pthread ");
|
||||
StringBuilder_Append(&cmdBuf, " -pthread -Wl,--build-id=none ");
|
||||
}
|
||||
StringBuilder_Append(&cmdBuf, "-o ");
|
||||
StringBuilder_Append(&cmdBuf, outPath);
|
||||
@@ -1181,13 +1181,13 @@ func Cli_BuildProject(projectDir: String, targetTriple: String, isRelease: bool)
|
||||
if !String_Eq(targetTriple, "") {
|
||||
StringBuilder_Append(&ccBuf, "clang ");
|
||||
StringBuilder_Append(&ccBuf, optFlags2);
|
||||
StringBuilder_Append(&ccBuf, " -pthread -target ");
|
||||
StringBuilder_Append(&ccBuf, " -pthread -Wl,--build-id=none -target ");
|
||||
StringBuilder_Append(&ccBuf, targetTriple);
|
||||
StringBuilder_Append(&ccBuf, " ");
|
||||
} else {
|
||||
StringBuilder_Append(&ccBuf, "cc ");
|
||||
StringBuilder_Append(&ccBuf, optFlags2);
|
||||
StringBuilder_Append(&ccBuf, " -pthread ");
|
||||
StringBuilder_Append(&ccBuf, " -pthread -Wl,--build-id=none ");
|
||||
}
|
||||
StringBuilder_Append(&ccBuf, "-o ");
|
||||
StringBuilder_Append(&ccBuf, outBin);
|
||||
|
||||
Reference in New Issue
Block a user