![]() |
| | #1 |
| Registered User Join Date: May 2006
Posts: 1,579
| linker 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/ar...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 |
| George2 is offline |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| I couldn't be bothered to read all the text in the pages you linked to, but I know how it works from experience. The linker WILL change the code generated by the compiler when the compiler is producing function calls outside of the current compile unit [a compile unit is normally one .c/.cpp file], where the linker finds the referred function in a different object file (the result of a different compile unit being compiled). If it can't find the function, it will generate an error. The loader, when doing "fixup" will also modify these entries, when linking in the DLL's that the executable is using, e.g. C runtime library or Kernel32.dll. In the case of DLL's being loaded into the system, these will potentially need to be relocated too - as the default DLL address isn't always available in the system, and thus the DLL will have to be located at a different (virtual) address, and all the addresses within the DLL that refer to absolute (virtual) addresses within that DLL will have to be "fixed up". So, yes, the linker will definitely change what the compiler generated. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline |
| | #3 | |
| Registered User Join Date: May 2006
Posts: 1,579
| Thanks Mats, Your reply is great! My question is answered. Quote:
regards, George | |
| George2 is offline |
| | #4 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,439
| blogs.msdn.com contains personal opinions of various MS-associated people and does NOT constitute official documentation. In case of conflict, assume the core MSDN to be correct unless the article specifically mentions an error in the official docs.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline |
| | #5 | |
| Registered User Join Date: May 2006
Posts: 1,579
| Thanks CornedBee, Quote:
regards, George | |
| George2 is offline |
| | #6 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,439
| I posted them in the other thread.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline |
| | #7 |
| Registered User Join Date: May 2006
Posts: 1,579
| Thanks CornedBee, Do you mean #12 of topic dllimport? http://cboard.cprogramming.com/showt...219#post721219 If yes, I think you mean you agree with (2) in my original question. Right? regards, George |
| George2 is offline |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Linker problem... no idea | cyreon | C Programming | 2 | 04-03-2009 02:53 PM |
| Linker errors in VC++ 2005 | C+/- | C++ Programming | 0 | 05-18-2007 07:42 AM |
| Linker errors when compiling | The Wazaa | C++ Programming | 4 | 10-07-2006 12:55 PM |
| Linker error using system(*.*) | Winston4u | C Programming | 5 | 05-09-2003 05:54 PM |
| MSVis-Studio C++ libraries and linker errors | kellydj | Windows Programming | 10 | 03-12-2002 02:03 PM |