When you compile C code into object files, the compiler faces a fundamental problem: it doesn't know the final addresses where functions and variables will reside in the finished executable. The compiler generates machine code that needs to reference these symbols, but their final locations won't be determined until the linking phase. The solution is relocations, which are essentially placeholders that tell the linker exactly how to patch the code once final addresses are known.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Relocations: How the Linker Patches Your Code

  • Mohit Mishra

摘要

When you compile C code into object files, the compiler faces a fundamental problem: it doesn't know the final addresses where functions and variables will reside in the finished executable. The compiler generates machine code that needs to reference these symbols, but their final locations won't be determined until the linking phase. The solution is relocations, which are essentially placeholders that tell the linker exactly how to patch the code once final addresses are known.