Hi there, I am currently working on the native port of an embedded OS and trying to get static initialization to work. We have our own startup code to handle things before the main is called. When using gcc I acquire the function pointers to the initializer array and iterate over them. I asked on the llvm IRC channel and got this helpful guide [1] for gcc. Apparently it works in a similar way on clang, but remains silent on the details. Is there a more detailed documentation I have overlooked or could you give me a hint how to acquire function pointers? Thanks Raphael [1] http://wiki.osdev.org/Calling_Global_Constructors
Hi Raphael, On 25 November 2014 at 23:48, Hiesgen, Raphael <Raphael.Hiesgen at haw-hamburg.de> wrote:> Apparently it works in a similar way on clang, but remains silent on the details.The main issue I saw is that Clang doesn't supply a crtbegin.o/crtend.o. Actually, I think most of that bit is documenting the Linux platform ABI rather than any universal truths. When compiling for Linux, Clang uses GCC's version of those files. But it sounds like you're creating your own anyway, so it probably doesn't matter.> Is there a more detailed documentation I have overlooked or could you give me a hint how to acquire function pointers?All the sections and so on are ABI details so they should be identical when targeting the same platform. Are you seeing some particular problem with the code emitted by Clang? Across CPUs main difference to watch out for is whether .init_array (newer systems) or .ctors (the traditional way) is being used primarily. But both Clang and GCC should agree in each case. Cheers. Tim.
Hi Tim, sorry it took me so lang to reply.>> Apparently it works in a similar way on clang, but remains silent on the details. > > The main issue I saw is that Clang doesn't supply a > crtbegin.o/crtend.o. Actually, I think most of that bit is documenting > the Linux platform ABI rather than any universal truths. When > compiling for Linux, Clang uses GCC's version of those files. > > But it sounds like you're creating your own anyway, so it probably > doesn't matter.My target platform is OS X and later different embedded devices. For the gcc build it is indeed not necessary to provide the crt*.o files. I simply defined __init_array_{start, end} as extern and called all contained functions>> Is there a more detailed documentation I have overlooked or could you give me a hint how to acquire function pointers? > > All the sections and so on are ABI details so they should be identical > when targeting the same platform. Are you seeing some particular > problem with the code emitted by Clang? > > Across CPUs main difference to watch out for is whether .init_array > (newer systems) or .ctors (the traditional way) is being used > primarily. But both Clang and GCC should agree in each case.I have a newer system and .init_array is probably the section in use. I searched online for crt* files (and how to write or use them). While I found some, they did not work for or I used them wrong. I guess my understanding of how the whole thing is supposed to work is not that good yet. Thanks Raphael