Closed timokroeger closed 2 months ago
The init functions are a new addition because we want to support complex initialization like a pointer being assigned to a global variable. I agree they should not lend in externally linked blocks, they should just be provided. The main _init.. function for the entire program should still call the lib functions if they exist. In other words, the init function for an external should probably also be external
@mhasel
If I'm not mistaken, __<type_name>__init
is the global default initializer, not an init function.
True, this seems like the older init variable, we need to still declare init variables as external. For structs this won't work yet, we need a separate issue for that.
The compiler creates a
*__init
symbol in the read-only data section for each function block (even when marked as{external}
).Example:
The problem can be observed when statically linking to iec61163std. The linker complains that this
*__init
symbol exists multiple times.A possible solution could be to prevent the compiler from generating the
*__init
symbols for{external}
function blocks. The implementation of the function block then needs to provide the init symbol instead. I’m unsure where and how the init symbol is used and what the implications of such a change would mean.