When compiling, C produces object code before linking time. I wonder if object code is in the form of binary yet? If so, what happened 开发者_StackOverflow社区next in the linking time?
Wikipedia says,
In computer science, an object file is an organised collection of named objects, and typically these objects are sequences of computer instructions in a machine code format, which may be directly executed by a computer's CPU.
Object files are typically produced by a compiler as a result of processing a source code file. Object files contain compact code, and are often called "binaries".
A linker is typically used to generate an executable or library by amalgamating parts of object files together. Object files for embedded systems typically contain nothing but machine code but generally, object files also contain data for use by the code at runtime: relocation information, stack unwinding information, comments, program symbols (names of variables and functions) for linking and/or debugging purposes, and other debugging information.
Another great site has much more detailed info and a useful diagram, here:
Object files as produced by the C compiler essentially contain binary code with holes in each place where an address should go that is yet unknown (addresses of function from other files -- including libraries -- called, addresses of variables from other files that are accessed in this one, ...).
It also contains a table indexed by symbol names ("x" or "_x" for variable x
, "f" or "_f" for function f
). For each such symbol, there is a status code ("defined here", "not defined here but used", ...) and the addresses of holes in the binary code that need to be filed with each address when it becomes known.
If you are using Unix (or gcc on Windows), you can print the later table with the command "nm file.o".
Yes, object code is usually in binary form. Just try opening it in your favorite text editor.
You can learn what linkers do here or here.
精彩评论