How to iterate over all functions at Link Time Optimization?

I am looking for a way to identify all functions in llvm that are declared externally (there is no definition of the function at compile time, it will be linked at runtime). I can’t do this analysis on a module basis, since a function could be declared in one module and defined in another module. So I need a way to somehow iterate over all modules. The only possibility I see here is to somehow do this during Link Time Optimization. I read that during LTO all modules are combined into one, and further optimizations are applied. How can I add an “LTOPass”, if something like that exists?
Thanks for your time and help!

In FullLTO mode all modules are merged into one. You could add a normal pass to the resp. pass pipeline.

You cannot trick the linker to reveal the necessary information?

1 Like

Hi, thanks for the answer!

Do you have a link or small example on how to add a pass to the FullLTO pipeline?

I am also not sure what you mean with “tricking” the linker. Could you explain further what you mean?

The linker knows which symbols came from the objects files and which came from shared libraries?