linker

G

George3

Hello everyone,


Here are two conflicting documents from MSDN. About whether linker will
modify code generated by compiler. I quote both of them here.

Document (1) mentioned linker can not modify any code generated by
compiler, but document (2) mentioned linker will replace address code
generated by compiler during fixup process.

Which one is correct?

1.

http://blogs.msdn.com/oldnewthing/archive/2006/07/21/673830.aspx

--------------------
But the linker can't rewrite the code generated by the compiler.
--------------------

2.

http://www.microsoft.com/msj/0797/hood0797.aspx

--------------------
Consider a call to a function named Foo in C++:


//...
Foo();
//...



The exact bytes emitted from a 32-bit C++ compiler will be this:


E8 00 00 00 00



The 0xE8 is the CALL instruction opcode. The next DWORD should contain
the offset to the Foo function (relative to the CALL instruction). It's
pretty clear that Foo probably isn't zero bytes away from the CALL
instruction. Simply put, this code wouldn't work as expected if you were
to execute it. The code is broken, and needs to be fixed up. In the
above example, the linker needs to replace the DWORD following the CALL
opcode with the correct address of Foo.
 
F

Frank Hickman

George3 said:
Hello everyone,


Here are two conflicting documents from MSDN. About whether linker will
modify code generated by compiler. I quote both of them here.

Document (1) mentioned linker can not modify any code generated by
compiler, but document (2) mentioned linker will replace address code
generated by compiler during fixup process.

Which one is correct?

1.

http://blogs.msdn.com/oldnewthing/archive/2006/07/21/673830.aspx

--------------------
But the linker can't rewrite the code generated by the compiler.
--------------------

2.

http://www.microsoft.com/msj/0797/hood0797.aspx

--------------------
Consider a call to a function named Foo in C++:


//...
Foo();
//...



The exact bytes emitted from a 32-bit C++ compiler will be this:


E8 00 00 00 00



The 0xE8 is the CALL instruction opcode. The next DWORD should contain
the offset to the Foo function (relative to the CALL instruction). It's
pretty clear that Foo probably isn't zero bytes away from the CALL
instruction. Simply put, this code wouldn't work as expected if you were
to execute it. The code is broken, and needs to be fixed up. In the
above example, the linker needs to replace the DWORD following the CALL
opcode with the correct address of Foo.
--------------------


thanks in advance,
George

Both statements are correct. The compiler creates tokens for address space
that the linker will use where appropriate. The linker is not changing
"code", simply performing it's function of address fixup.

--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top