[Assembly] How does linking work?

I was curious. I linked a program I made (using GCC) and disassembled it. The funny part is the imported functions are calling "imp_func" which is basically a NOP. How does it work?
It is due to the issues of static versus dynamic library imports. Somewhere in your compile chain something is misconfigured.

It appears that the imported library functions are expected (or thought) to be in a DLL, but you are linking them statically. So the automatically created thunks don't actually need to do anything.

This is only my best guess as to what is going on. Make sure your libraries are all properly static or dynamic and compile with the correct flags to make it go away.

Hmm, another thought: you may be compiling a program that uses a mixture of static and dynamic libraries? And some of those libraries are not playing nice?

You might get a better answer on the GCC mailing list or IRC channel. Find links here:
https://gcc.gnu.org/wiki/HomePage

Good luck!
No, It's a WinAPI hello world!
Perhaps it's what you saying. Anyways: in general, how does linking work?
__imp__ symbols come from the stub library in Windows which you must link against at compile-time. They then must be satisfied by a present DLL upon runtime.

I'm not sure the reason for this. On Unix-like systems, you have on library for dynamic and one for static. Windows has two for dynamic and one for static (technically, one for dynamic is static since it gets sucked into your binary... but I digress).

Anyways, I would suggest google: http://www.symantec.com/connect/articles/dynamic-linking-linux-and-windows-part-one
@NoXzema so basically: assembly has nothing to do it. (?) Those NOPs I see and these JMP and PUSH instructions are internal from linking, right?
No. The NOPs and JMP and PUSH are all part of the program.


Your executable's code and data are just like any other data -- a sequence of bytes/words that is used in some way -- code is stuff the hardware can understand -- data is stuff the code uses.

Linking takes one or more collections of these data and puts them together into a file in a way that fits a specific structure.

For functions that are statically linked, all the spots where some code 'calls' that function must be adjusted to 'call' to the correct address -- the place where the statically-linked code actually exists in memory.

For functions that are dynamically linked, there is a table of addresses, plus information about the function to be called and what module (DLL or SO) the function is found in. When the OS loads your executable into memory it also loads the DLL/SO and fills in the table with the addresses of where those functions are actually found in memory.

This is a dumbed-down version of what happens, but it is the basic idea behind linking.

Make sure to read through NoXzema's link. It will answer all your questions.

Hope this helps.
So if I want to understand Windows dynamic linking I must learn how the PE linking process work? If I'm right, could you guys give me some links? ^^ lazy
Topic archived. No new replies allowed.