I extended the LDC2 with a pragma to register a funcion in the llvm.global_ctors or llvm.global_dtors list.
On Linux, references to these functions are placed in .ctors and .dtors sections and everything runs fine.
On Windows, functions from llvm.global_ctors are placed in section .CRT$XCU, which is automatically called by the MS C Runtime. However, functions from llvm.global_dtors are placed in section .dtors which is unknown to the runtime. Therefore only ctors are called. Is this expected behaviour?
My expectation was that the dtors placed in .CRT$XTU which are the C terminator functions. Maybe there is a way to customize this?
Another question is how can I control section names and attributes.
Before I found the ctors/dtors variables I tried to implement this functionality by placing a variable in a section with a special name. This works because a global variable can have an optional section name.
But:
- How can I control section attributes and alingment? E.g. the .CRT$XU segment is read-only. How can I specify that?
- How can I place constant data in the .rdata section?
Hi Kai. I submitted the patch to use the .CRT$XCU section for ctors on
Win32; I did not do so for dtors because I was unaware of .CRT$XTU. My
apologies. If you look in lib/MC/MCObjectFileInfo.cpp:417, you can see
the following logic: