Skip to content

Replace startup code block with loop to call all entry stubs.#13217

Open
tmcgilchrist wants to merge 1 commit intoocaml:trunkfrom
tmcgilchrist:startup_hack
Open

Replace startup code block with loop to call all entry stubs.#13217
tmcgilchrist wants to merge 1 commit intoocaml:trunkfrom
tmcgilchrist:startup_hack

Conversation

@tmcgilchrist
Copy link
Contributor

This is a small improvement to rewrite the entry_point code generated by cmm_helpers.ml to be data driven.

When starting a native OCaml program the call stack goes through C functions (caml_main, caml_startup_common and caml_startup_common, in startup_nat.c before jumping to the processor specific assembly in runtime/arm64.s (or whatever architecture you have) starting at caml_start_program. Before it jumps to caml_program which calls the module .entry point for the modules included in an executable. At this point currently OCaml generates a block of assembly code for each module entry point that needs to be called, 35 for a minimal program that just relies on the Stdlib (potentially more?). This change re-writes this code to be a loop equivalent to this C code:

 {
   int id = 0;
   while (true) {
     if (id == len_caml_globals_entry_functions) goto out;
     caml_globals_entry_functions[id]();
     caml_globals_inited += 1;
     id += 1;
   }
   out:
   return 1;
 }

What is gained by making this change? More compact assembly code that is data driven using a loop and lookup table of symbols. Possibly faster startup but I have no data to back this up. The work was done original in PR oxcaml/oxcaml#1425 by @poechsel, I have only cherry picked it here after noticing the repeated assembly code blocks.

@poechsel please correct any attribution as you see fit.

@tmcgilchrist tmcgilchrist force-pushed the startup_hack branch 3 times, most recently from 694053a to 11d20eb Compare June 5, 2024 04:54
@shindere
Copy link
Contributor

shindere commented Jun 5, 2024 via email

@tmcgilchrist
Copy link
Contributor Author

Good idea @shindere I have not as yet, but I will do so.

@shindere
Copy link
Contributor

shindere commented Jun 5, 2024 via email

@tmcgilchrist tmcgilchrist force-pushed the startup_hack branch 2 times, most recently from 13f36fb to 4b94477 Compare June 18, 2024 12:10
@tmcgilchrist
Copy link
Contributor Author

@shindere testing with frame-pointers on macOS and Linux is passing.

@shindere
Copy link
Contributor

shindere commented Jun 19, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants