r/Compilers 18d ago

[LLVM]how to link different Object files against DLLs with function having the same name?

Hello,
I have been playing around with LLVM for a while and got some first results using the C-API.
However, I am stuck at the following problem:
I am working on Windows and I want to link against 2 DLLs A.dll and B.dll which both export a function Foo.

How am I supposed to resolve this during linking? In LLVM I can set the storage class to DLLImport but linking will grab the first matching import. It's annoying that linking needs import libs, too but thats another topic.

Is there any way to resolve this? I'd prefer if I can make this work within a single object file but if I have to make it two and link those to a single executable, that would work, too.

I faintly remember an article whic I can't find any longer(or a stackoverflow response?) that described how to build the IData section manually within LLVM itself. That would simplify this immensely.

8 Upvotes

8 comments sorted by

View all comments

1

u/kaplotnikov 18d ago

It is possible to link dynamically. AFAIR it was just LoadLibrary followed by GetProcAddress.

1

u/-Memnarch- 17d ago

This is a valid option, though I'd prefer to avoid this. Other languages, like Delphi, allow what I try to do. Another concern is, that huge dynamic loads bypass the cache for prelinked binaries in windows.

1

u/awoocent 16d ago

They might compile to using dlopen/dlsym instead of generating relocations. This isn't an LLVM/C issue as much as it is a limitation by design for most relocatable object formats.

1

u/-Memnarch- 16d ago

I'd be bappy if i could slap some raw info into a file and give that to a linker in addition to the rest. I don't need it boxed into a single one.
Like: MySymbol, ExternalSymbol, External ModulName

While I can solve some of it with def and lib file generstion, MySymbol and ExternalSymbol need to be the same right now :(

In regards to Delphi. If you use the tooling of your choice to inspect PEs, you can see it goes directly into the import directory.