sp1 icon indicating copy to clipboard operation
sp1 copied to clipboard

Runtime doesn't invoke C global constructors

Open chfast opened this issue 4 months ago • 0 comments

Component

sp1-sdk

Have you ensured that all of these are up to date?

  • [x] SP1 SDK
  • [x] cargo prove CLI/sp1up

What version of SP1 SDK are you on?

5.2.1

What version of the cargo prove CLI are you on?

cargo-prove sp1 (3209d54 2025-08-05T20:15:44.228807077Z)

Operating System

Linux (Ubuntu)

Describe the bug

SP1 runtime provides its own version of the _start function. This function don't call global constructors before calling main nor global destructors after. This makes C code linked in potentially work incorrectly.

Pointers to these are provided by linker as the following symbols:

extern void (*__preinit_array_start []) (void);
extern void (*__preinit_array_end []) (void);
extern void (*__init_array_start []) (void);
extern void (*__init_array_end []) (void);
extern void (*__fini_array_start []) (void);
extern void (*__fini_array_end []) (void);

chfast avatar Aug 29 '25 13:08 chfast