Skip to content

Add LLVM 23 build support - #5782

Merged
dgryski merged 4 commits into
tinygo-org:devfrom
dgryski:dgryski/add-llvm23
Oct 19, 2026
Merged

dgryski merged 4 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.

Closes #5775

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)

@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
@dgryski

dgryski commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

Add some commits from @davecheney to make the condition branch argument stuff a bit nicer.

@davecheney

Copy link
Copy Markdown
Contributor

@dgryski awesome; i'm testing on arch and osx which have llvm23 as their default now

@davecheney

Copy link
Copy Markdown
Contributor

@dgryski tinygo-org/go-llvm#83 (and a stacked branch on dgryski#18) removes the aliasing of OpBr before / after llvm23; before llvm23 there is only OpBr, llvm23 and later there is only CondBr and UncondBr.

@davecheney

Copy link
Copy Markdown
Contributor

@dgryski dgryski#20 incorporates tinygo-org/go-llvm#83

0pcom added a commit to 0magnet/tinygo that referenced this pull request Oct 5, 2026
Lets the fork build on a system whose LLVM is 23, with
go build -tags llvm23. The conflicts were additions on one side only,
except makeStrongFromWeak, where both sides return the pointer as it is.
@0pcom

0pcom commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

The static build needed two more changes for LLVM 23, in case they are useful here. cc1as.cpp follows three MC API changes, as clang's cc1as_main.cpp did, which only the static build compiles: 0magnet@34fc049. The static link also lists the libraries LLVM 23 added (LLVMABI, clangDependencyScanning, the clangScalableStaticAnalysis libraries and clangUnifiedSymbolResolution): 0magnet@0f8bccc

@davecheney

Copy link
Copy Markdown
Contributor

@dgryski dgryski#21 fixes the go mod tidy break

@davecheney

Copy link
Copy Markdown
Contributor

@dgryski I've been testing this locally and its working well for me on osx with homebrews llvm22 and llvm23.

go-llvm has moved forward a few commits since the last push, could you please update this branch to use the latest there, make go mod tidy happy, and push again and I think we can land this.

@dgryski

dgryski commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

PTAL

@dgryski
dgryski force-pushed the dgryski/add-llvm23 branch from 174334d to 887ac2f Compare October 16, 2026 19:17
dgryski and others added 4 commits October 16, 2026 12:31
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 force-pushed the dgryski/add-llvm23 branch from 887ac2f to 47ad8e2 Compare October 16, 2026 19:32
@dgryski

dgryski commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Fixed the conflicts and then squashed all the interp patches that were working around the rapidly-changing go-llvm bits.

@davecheney davecheney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dgryski LGTM. Thank you very much. Lets land this before it bit rots again :)

% tinygo version
tinygo version 0.44.0-dev-6ff7684a darwin/arm64 (using go version go1.27.2 and LLVM version 23.1.3)

@dgryski
dgryski merged commit 58e1323 into tinygo-org:dev Oct 19, 2026
33 checks passed
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.

Add -tags llvm23

5 participants