#Equivalent of __attribute__((constructor)) ?

1 messages · Page 1 of 1 (latest)

rose harness
#

I want to create a shared object in zig that runs some code when it enters & exits a program via LD_PRELOAD, though I can't find much relating to this kind of thing.

The only way I can think of doing this is by just creating a 'wrapper' C program which has __attribute__((constructor)) and calls into my zig code, but it does seem a little clunky.

idle flume
#

I don't think you can do it from zig code, but you can mix zig and c, so link .c file into your dynamic lib to get that

smoky tiger
#

I mean you just need a globally unique symbol and

export const my_constructor_symbol: *const fn () callconv(.C) void linksection(".init_array") = &myConstructorFn;
fn myConstructorFn() callconv(.C) void {
}
idle flume
#

Heh i was looking for something like that

coarse socket
#

@typeName(@TypeOf(opaque{})) to the rescue for unique names

hardy kestrel
#

is there a @export builtin maybe?

coarse socket