Hey all, it’s been a while since I have posted on llvm-dev, but that’s mainly because I have been making good progress with my LLVM project.
In any case, I’d like some advice on implementing my own version of appending linkage as a linker plugin. As I have pointed out on this list before, the existing appending linkage type isn’t useful for me for two reasons:
There’s no way for the compiled code to determine the length of the combined array. Appending linkage concatenates all of the array fragments with the same name together, but there’s no simple way to get a count of the number of elements, or even to insert a sentinel value at the end of the list (Some have suggested solutions involving mucking about with linker sections, but that’s too complicated and fragile IMHO).
If your appended array contains pointer references to globals that would otherwise be dead and stripped from the code, having them in the array will keep them alive. In other words, what I need for my use case is to eliminate dead globals, and then only afterward take the live globals remaining and put them into the array.
To give an example of my use case, suppose I want to create an array of static roots for the garbage collector - that is, I want an array of pointers to all statically-allocated data structures which themselves contains object references. Ideally, the way this would work is as follows: Each time the compiler outputs a static data structure, it would check the type information to see if that structure contains any object references that need to be traced. If so, it would “mark” that structure somehow (how, I am not certain). Then at link time, after dead global elimination, it would collect all of the marked structures and create an array of pointers to those structures, with a NULL pointer at the end of the list. The address of this array would then be passed into the garbage collector when it is first initialized.
Really, all I need to make this work is some way to ‘mark’ a global so that my custom pass can query for all marked globals. Any ideas on this?