Skip to content

Add LLVM 23 build support - #5782

Open
dgryski wants to merge 3 commits into
tinygo-org:devfrom
dgryski:dgryski/add-llvm23
Open

dgryski wants to merge 3 commits into
tinygo-org:devfrom
dgryski:dgryski/add-llvm23

Conversation

@dgryski

@dgryski dgryski commented Sep 28, 2026

Copy link
Copy Markdown
Member

Adds llvm23 build-tag config, mirroring the existing llvm22 support.
Requires tinygo-org/go-llvm#79, which is not yet merged/tagged, so go.mod
is left pointing at the current go-llvm commit for now.

Verified against real LLVM 23.1.1 headers and libraries (via Homebrew): both
a native build and a wasi build produce working binaries that run correctly.

LLVM 23 keeps the wasm32-unknown-wasi triple deprecation and the Xtensa
feature renames introduced in LLVM 22 (confirmed for the triple; the Xtensa
renames are assumed unchanged, not yet verified against an Xtensa-enabled
LLVM 23 toolchain).

LLVM 23 removed the Os/Oz pipeline levels from the new pass manager's
textual pipeline syntax ("thinlto-pre-link<Os>" now aborts with a fatal
LLVM error). transform/optimizer.go now runs the O2 pipeline level
instead on LLVM 23+, relying on the optsize/minsize function attributes
already set elsewhere to keep steering size-conscious passes.

LLVM 23 requires the llvm.returnaddress intrinsic's mangled name to include
its pointer type suffix (llvm.returnaddress.p0). Patches the linkName for
that specific //export pragma in compiler/symbol.go.

LLVM 23 splits the conditional/unconditional branch instruction into separate
opcodes and, more importantly, reorders a conditional branch's operands from
(cond, else, then) to (cond, then, else). interp/compiler.go hardcoded
the old order when building its own branch instruction, which silently
inverted every branch condition evaluated by the compile-time interpreter
under LLVM 23, sending essentially all packages into infinite recursion
during interp. Fixed with a version-gated operand read.

Also normalizes away the LLVM 23 nosync attribute (newly inferred for
llvm.memcpy/llvm.memmove) in the golden-IR test comparators in
compiler_test.go, transform_test.go and interp_test.go, and updates a
hardcoded "Oz" pipeline string in transform/unwind_test.go the same way
as the production code path.

Known gaps

  • A handful of golden-IR-text comparison tests in compiler_test.go show
    cosmetic diffs from LLVM 23's own output-formatting changes (float
    hex-constant syntax, a GEP-canonicalization preference change, and
    attribute-group renumbering). These are optimizer/printer text drift, not
    correctness bugs; fixing them properly needs per-LLVM-version golden
    fixtures, which is out of scope here.
  • The Xtensa feature-rename compatibility shim (compileopts/features_llvm22.go)
    is extended to LLVM 23 by assumption, not verified against a real
    Xtensa-enabled LLVM 23 toolchain.

🤖 Generated with Claude Code

Comment thread compileopts/features_default.go Outdated
@@ -1,4 +1,4 @@
//go:build !llvm22 && !llvm14 && !llvm15 && !llvm16 && !llvm17 && !llvm18 && !llvm19
//go:build !llvm22 && !llvm23 && !llvm14 && !llvm15 && !llvm16 && !llvm17 && !llvm18 && !llvm19

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Out of order here (why are some files one way, some the other)

Adds the llvm23 build-tag config files, mirroring the existing llvm22
ones. Requires go-llvm branch dgryski/add-llvm23, not yet merged, so
go.mod still points at the current go-llvm commit.

Verified against real LLVM 23.1.1: a native build and a wasi build
both produce working binaries.

LLVM 23 keeps the wasm32-unknown-wasi triple deprecation and the
Xtensa feature renames from LLVM 22.

LLVM 23 removed the Os/Oz pipeline levels from the new pass manager's
textual syntax. transform/optimizer.go now runs O2 instead on LLVM
23+, relying on the optsize/minsize function attributes already set
elsewhere to steer size-conscious passes.

LLVM 23 requires the llvm.returnaddress intrinsic's mangled name to
include its pointer type suffix. Patches the linkName for that
//export pragma in compiler/symbol.go.

LLVM 23 splits the branch instruction into separate opcodes and
reorders a conditional branch's operands from (cond, else, then) to
(cond, then, else). interp/compiler.go hardcoded the old order,
which silently inverted every branch condition the compile-time
interpreter evaluated, sending most packages into infinite recursion
during interp. Fixed with a version-gated operand read.

Also normalizes the LLVM 23 nosync attribute (newly inferred for
llvm.memcpy/llvm.memmove) in the golden IR test comparators, and
updates a hardcoded Oz pipeline string in transform/unwind_test.go.

Known gaps: a few golden IR comparison tests in compiler_test.go show
cosmetic diffs from LLVM 23 output formatting (float hex constants, a
GEP canonicalization change, attribute group renumbering). These are
printer text drift, not correctness bugs. The Xtensa feature rename
shim is extended to LLVM 23 by assumption, not verified against a
real Xtensa-enabled toolchain.
cgo/libclang_config_llvm23.go: also search Homebrew's unversioned
llvm formula, same reasoning as the matching go-llvm change.

builder/commands.go: same idea for locating clang/lld/wasm-ld/lldb at
run time, plus a bug fix this exposed. LookupCommand only recognized
a bare command missing from $PATH as a reason to try the next
candidate. A missing absolute path surfaces a different error and was
treated as fatal, aborting the search before it reached a working
fallback.
@dgryski

dgryski commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

This passes my test corpus as well as the stdlib tests on darwin/arm64 and wasip1.

@dgryski dgryski mentioned this pull request Sep 29, 2026
@dgryski

dgryski commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

Will need to merge tinygo-org/go-llvm#79 first for llvm23 support and then update go.mod.

@deadprogram deadprogram added this to the 0.44 milestone Sep 30, 2026
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.

3 participants