Skip to content

closure: add ppc64 ELFv1 support#26749

Merged
JalonSolov merged 3 commits into
vlang:masterfrom
tankf33der:second_ppc64
Mar 20, 2026
Merged

closure: add ppc64 ELFv1 support#26749
JalonSolov merged 3 commits into
vlang:masterfrom
tankf33der:second_ppc64

Conversation

@tankf33der

Copy link
Copy Markdown
Contributor

Second step to add ppc64 support for closure.
Patch manually tested on x64 and ppc64.

Only ELFv2 has been supported all this time — now and always — and the assembly code for each architecture operated under this memory model. Because of ppc64, additional code had to be written for the closure itself to make it work with ELFv1 as well. All closure tests pass, which is a very good sign to start with.

tankf33der@cfarm121:~/v$ VTEST_ONLY=closure v test vlib/
---- Testing... ----------------------------------------------------------------------------------------------------------------------------
 OK    [ 1/31] C:  1101.3 ms, R:     4.721 ms vlib/v/tests/fns/closure_in_if_guard_2_test.v
 OK    [ 2/31] C:  1113.0 ms, R:     5.135 ms vlib/v/tests/comptime/comptime_call_method_closure_test.v
 OK    [ 3/31] C:  1119.0 ms, R:     5.209 ms vlib/v/tests/generics/generics_return_closure_test.v
 OK    [ 4/31] C:  1132.7 ms, R:     4.056 ms vlib/v/tests/closure_with_fn_ref_var_test.v
 OK    [ 5/31] C:  1156.2 ms, R:     5.232 ms vlib/v/tests/builtin_arrays/array_filter_using_direct_closure_test.v
 OK    [ 6/31] C:  1152.0 ms, R:     3.351 ms vlib/v/tests/generics/return_closure_f64_test.v
 OK    [ 7/31] C:  1218.4 ms, R:     4.042 ms vlib/v/tests/arrays_closure_fixed_array_test.v
 OK    [ 8/31] C:  1215.0 ms, R:     3.345 ms vlib/v/tests/generics/generics_closure_fn_direct_call_test.v
 OK    [ 9/31] C:  1239.8 ms, R:     5.390 ms vlib/v/tests/fns/closure_in_if_guard_1_test.v
 OK    [10/31] C:  1248.1 ms, R:     3.859 ms vlib/v/tests/assign/assign_literal_with_closure_test.v
 OK    [11/31] C:  1245.8 ms, R:     3.190 ms vlib/v/tests/generics/generics_closures_with_different_generic_types_test.v
 OK    [12/31] C:  1254.8 ms, R:     7.260 ms vlib/v/tests/fns/go_call_anon_fn_with_closure_test.v
 OK    [13/31] C:  1294.2 ms, R:     4.208 ms vlib/v/tests/generics/generics_closure_fn_test.v
 OK    [14/31] C:  1301.2 ms, R:     4.451 ms vlib/v/tests/fns/closure_fn_arg_in_map_test.v
 OK    [15/31] C:  1299.2 ms, R:     3.548 ms vlib/v/tests/interfaces/interface_closure_test.v
 OK    [16/31] C:  1302.1 ms, R:     2.675 ms vlib/v/tests/match_multi_return_closure_heap_test.v
 OK    [17/31] C:  1320.7 ms, R:     3.680 ms vlib/v/tests/comptime/comptime_closure_field_access_test.v
 OK    [18/31] C:  1362.9 ms, R:     3.934 ms vlib/v/tests/fns/closure_with_fixed_array_var_test.v
 OK    [19/31] C:  1367.2 ms, R:     4.048 ms vlib/v/tests/fns/closure_data_with_gc_test.c.v
 OK    [20/31] C:  1367.4 ms, R:     2.712 ms vlib/v/tests/fns/closure_option_direct_call_test.v
 OK    [21/31] C:  1408.2 ms, R:     3.160 ms vlib/v/tests/fns/anon_c_keywords_closure_test.v
 OK    [22/31] C:  1416.1 ms, R:     3.153 ms vlib/v/tests/fns/closure_variable_in_smartcast_test.v
 OK    [23/31] C:  1420.2 ms, R:     2.884 ms vlib/v/tests/fns/closure_of_method_defined_on_alias_test.v
 OK    [24/31] C:  1463.0 ms, R:     3.556 ms vlib/v/tests/generics/return_closure_int_test.v
 OK    [25/31] C:  1465.0 ms, R:     2.590 ms vlib/v/tests/interfaces/interface_method_closure_test.v
 OK    [26/31] C:  1472.9 ms, R:     3.664 ms vlib/v/tests/fns/closure_of_instance_method_passed_to_voidptr_parameter_test.v
 OK    [27/31] C:  1487.2 ms, R:     2.840 ms vlib/v/tests/builtin_arrays/array_ops_create_just_one_closure_test.c.v
 OK    [28/31] C:  1508.1 ms, R:     3.894 ms vlib/v/tests/fns/closure_with_sumtype_var_test.v
 OK    [29/31] C:  1518.8 ms, R:     2.775 ms vlib/v/tests/fns/closure_test.v
 OK    [30/31] C:  1691.8 ms, R:     4.607 ms vlib/v/tests/fns/closure_struct_init_cov_regression_test.v
 OK    [31/31] C:  1309.4 ms, R:  3490.082 ms vlib/v/tests/fns/closure_generator_test.v
--------------------------------------------------------------------------------------------------------------------------------------------
Summary for all V _test.v files: 31 passed, 31 total. Elapsed time: 4829 ms, on 31 parallel jobs. Comptime: 40971 ms. Runtime: 3607 ms.
tankf33der@cfarm121:~/v$ uname  -a
Linux cfarm121 6.19.6+deb14-powerpc64 #1 SMP PREEMPT Debian 6.19.6-1 (2026-03-06) ppc64 GNU/Linux
tankf33der@cfarm121:~/v$ file ./v
./v: ELF 64-bit MSB pie executable, 64-bit PowerPC or cisco 7500, Power ELF V1 ABI, version 1 (SYSV), dynamically linked, interpreter /lib64/ld64.so.1, BuildID[sha1]=381f6b9ad31819ac0d4b694fbb1826ea55e1324d, for GNU/Linux 3.2.0, not stripped

Note Nr1337 for future me — ppc64 has this peculiarity that in our galaxy there exist versions for two ELF versions. If someone ever requests ppc64 support in ELFv2, add comptime support for elfv1 ($if elfv1 ...) and just reverse the stub from ppc64le. Get access to a system for testing to be sure idea is ok.

@tankf33der

Copy link
Copy Markdown
Contributor Author

@JalonSolov FYI, CI must be green.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a35793e6ce

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +111 to +115
} $else $if ppc64 {
[
u8(0x7C), 0x08, 0x02, 0xA6, // mflr %r0
0x48, 0x00, 0x00, 0x05, // bl here
0x7D, 0xC8, 0x02, 0xA6, // here: mflr %r14

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep first closure thunk variant longest

The file-level note says translated/bootstrap C mode (vc/v.c) infers a fixed C array size from the first $if branch, but this new ppc64 thunk is longer than the first ppc64le thunk. On ELFv1 ppc64 bootstrap builds, that mismatch can produce an undersized initializer (or truncated thunk bytes), which breaks closure trampolines at runtime. Please make the first branch the longest one again (or pad it) so bootstrap sizing remains safe.

Useful? React with 👍 / 👎.

@JalonSolov

JalonSolov commented Mar 19, 2026

Copy link
Copy Markdown
Collaborator

Some issues with native backend.

@JalonSolov

Copy link
Copy Markdown
Collaborator

Bounce for final check.

@JalonSolov JalonSolov closed this Mar 20, 2026
@JalonSolov JalonSolov reopened this Mar 20, 2026
@JalonSolov JalonSolov merged commit f91d734 into vlang:master Mar 20, 2026
150 of 178 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.

2 participants