-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test | ||
*.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.PHONY: clean | ||
|
||
LIBS = -lmikey | ||
CFLAGS = -Wall -Wextra -pedantic -std=c99 | ||
OBJECTS = addone.o | ||
|
||
all: test | ||
|
||
test: test.c $(OBJECTS) | ||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) | ||
|
||
clean: | ||
rm -f test | ||
rm -f *.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
#include <mikey/common.h> | ||
|
||
int addone(int x) { | ||
return x + 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef _ADDONE_H | ||
#define _ADDONE_H | ||
|
||
int addone(int x); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
* notes | ||
|
||
I am running this on OSX; this is the llvm =objdump= which is | ||
quite different from the linux utility (I believe). | ||
|
||
* print the symbol table | ||
|
||
For instance, on the =test= executable: | ||
|
||
#+BEGIN_SRC sh :results verbatim | ||
objdump -t test | ||
#+END_SRC | ||
|
||
#+RESULTS: | ||
#+begin_example | ||
|
||
test: file format Mach-O 64-bit x86-64 | ||
|
||
SYMBOL TABLE: | ||
0000000100001018 l __DATA,__data _TESTING | ||
0000000100000000 g F __TEXT,__text __mh_execute_header | ||
0000000100000f40 g F __TEXT,__text _addone | ||
0000000100000ee0 g F __TEXT,__text _main | ||
0000000000000000 *UND* _printf | ||
0000000000000000 *UND* dyld_stub_binder | ||
#+end_example | ||
|
||
here there is a reference to the static text in the data segment, | ||
=TESTING=, the functions in the text segment, =addone= and | ||
=main=. Note that =addone= comes from the =addone.o= object file: | ||
|
||
#+begin_src sh :results verbatim | ||
objdump -t addone.o | ||
#+end_src | ||
|
||
#+RESULTS: | ||
: | ||
: addone.o: file format Mach-O 64-bit x86-64 | ||
: | ||
: SYMBOL TABLE: | ||
: 0000000000000000 g F __TEXT,__text _addone | ||
|
||
There are also references to the dynamically linked =printf=. I think | ||
(but not sure) =*UND*= means undefined, as the dynamic linker will | ||
determine at runtime the location of this function. | ||
|
||
* disassembling | ||
|
||
we can disassemble a particular symbol, for instance: | ||
|
||
#+begin_src sh :results verbatim | ||
objdump -D -macho -dis-symname=_addone addone.o | ||
#+end_src | ||
|
||
#+RESULTS: | ||
#+begin_example | ||
addone.o: | ||
(__TEXT,__text) section | ||
_addone: | ||
0: 55 pushq %rbp | ||
1: 48 89 e5 movq %rsp, %rbp | ||
4: 89 7d fc movl %edi, -4(%rbp) | ||
7: 8b 7d fc movl -4(%rbp), %edi | ||
a: 83 c7 01 addl $1, %edi | ||
d: 89 f8 movl %edi, %eax | ||
f: 5d popq %rbp | ||
10: c3 retq | ||
#+end_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <stdio.h> | ||
#include <mikey/common.h> | ||
#include "addone.h" | ||
|
||
static char* TESTING = "This is a static string.\n"; | ||
|
||
int main() | ||
{ | ||
printf("Foo.\n"); | ||
printf("%s", TESTING); | ||
printf("One plus two is: %d", addone(2)); | ||
return EXIT_SUCCESS; | ||
} |