136 miscellaneous binary utilities
Thu, 14 Dec Sat, 13 Jan Thu, 11 Feb Mon, 5 Aug Thu, 9 Mar Fri, 20 Jan Sat, 19 Jun Wed, 21 Aug Sun, 8 Jun Thu, 30 Jun Thu, 27 Oct Sat, 1 May Tue, 27 Apr Wed, 22 Feb Sun, 28 Jul Sun, 16 Oct Wed, 16 Nov GCC 6's --enable-default-pie breaks gprof Reported by: Thu, 9 Feb Thu, 18 Jan Minor nit in strings manpage Reported by: Wed, 21 Nov Fri, 22 Feb Wed, 25 Jan Sun, 9 Jun Nonrepresentable section on output Reported by: Mon, 22 May Thu, 3 Aug Sun, 18 Apr Fri, 16 Jan Tue, 20 Feb Wed, 7 Feb Mon, 15 Nov It takes assembly code human readable text of machine code and turns it into a binary that a processor can execute.
When you invoke gcc and tell it to generate a binary e. Almost all executables you run in Linux, for example, are ELF. ELF includes not only machine code the E part but also symbols , names that provide information on where different variables and functions reside see nm and objdump below. That way, when you compile a program that invokes the library function, binutils can find where it is and link the two files together correctly see ld below.
Just as the input to as might not be a executable program, the output of as might not be executable. For example, a library is a set of functions that other programs can call, but does not have any entry point main function. It can also be that the compiled assembly code references functions that are in another binary file. For example, your program that calls a library, when compiled into machine code, does not have the actual instructions of those library calls.
The tool that takes multiple binary files and links them together is ld , described below. This tells the assembler that code. If you do not include -o code. If you do not include code. These two invocations are therefore equivalent:. For example, when you have a library written in multiple source files, you typically compile each source file independently into an ELF object file, then link all of those files together into a larger ELF object file for the library.
When you compile a program that uses the library, you compile your program code into one or more object files, then link those against the library, producing a final executable. The linker operates by resolving symbols. Whenever your code creates or uses a name that is not on the stack e.
Some symbols, such as those your program defines, are resolved and exist. For example, when you define a variable int a; in global scope, this creates a symbol for a , which says at what memory address a resides. When the linker links your program to the library, it sees that f is an unresolved symbol, sees that f is defined in the library, then fixes the binary code in your program so that when it calls f it jumps to where f exists. This takes two object files, links them together, and outputs the result as code.
When you invoke GCC without the -c option, it typically runs ld as its last step. The most commonly used options for ld are -l and -L. The -l option tells ld to link a library, which is basically just an object file.
The -L option tells ld what directories to look for libraries in. You can pass multiple -l and -L options. Displays the symbol table of a binary file. It takes one or more file names as parameters and outputs their symbol tables. The output looks like this:. The first column states the address of the symbol. For a function, this is the first instruction to jump to when you call the function. For a variable, this is its location in memory.
The second column states what kind of symbol it is. So in the above example, the object file defines a function f , a function main , and a variable a. Lists the size of sections and total size of object files.
Can be invoked on multiple files at once simply by listing the desired files,. Under text you see the size of the actual machine code that makes up your program. Similarly to the symbol types listed under nm above, the data section is the size of storing your initialized global variables, and bss is the size of storing your uninitialized global variables.
The options for the size command are mostly to change the format of the output. For example, to see the section sizes in hexadecimal, use the -x option size -x test.