-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests of jump and function tables. (#13)
* Added code snippets for jumptables. * Added -fno-plt mode for %rip-based calls. * Added todo. * Use itertools.product instead of nested loops. * Added tests for indirect pointers.
- Loading branch information
Showing
7 changed files
with
279 additions
and
65 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,5 @@ | ||
int bar(int x, void (*f[])(int x)) { | ||
if (x > 0) | ||
f[0](x); | ||
f[1](x); | ||
} |
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
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,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Generate different flavors of input assembly for testing. | ||
""" | ||
|
||
import os.path | ||
import itertools | ||
|
||
from common import set_basename, gcc, disasm, grep | ||
|
||
set_basename(os.path.basename(__file__)) | ||
|
||
for gdb, pic, strip in itertools.product([False, True], | ||
[False, True], # Do we need to test PIE too? | ||
[False, True]): | ||
# Print config | ||
|
||
disasm_type = 'GDB' if gdb else 'objdump' | ||
pic_type = 'position-INdependent' if pic else 'position-dependent' | ||
stripped = 'stripped' if strip else 'UNstripped' | ||
print(f"Checking {disasm_type} {pic_type} {stripped}") | ||
|
||
# Generate object code | ||
|
||
flags = ['funtable.c', '-o', 'a.out', | ||
'-Wl,--defsym,_start=0', '-nostdlib', '-nostartfiles', '-O2'] | ||
# DLL or executable? | ||
if pic: | ||
flags += ['-fPIC', '-shared'] | ||
# Include debuginfo? | ||
if not strip: | ||
flags.append('-g') | ||
|
||
gcc(flags) | ||
|
||
# Generate disasm | ||
|
||
caller = 'bar' | ||
out = disasm('a.out', not gdb, strip, caller) | ||
|
||
# Print snippets | ||
|
||
jumps = grep(out, r'\bcall') | ||
print('''\ | ||
table calls: | ||
{} | ||
'''.format('\n '.join(jumps))) |
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
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,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Generate different flavors of input assembly for testing. | ||
""" | ||
|
||
import os.path | ||
import itertools | ||
|
||
from common import set_basename, gcc, disasm, grep | ||
|
||
set_basename(os.path.basename(__file__)) | ||
|
||
for gdb, pic, strip in itertools.product([False, True], | ||
[False, True], # Do we need to test PIE too? | ||
[False, True]): | ||
# Print config | ||
|
||
disasm_type = 'GDB' if gdb else 'objdump' | ||
pic_type = 'position-INdependent' if pic else 'position-dependent' | ||
stripped = 'stripped' if strip else 'UNstripped' | ||
print(f"Checking {disasm_type} {pic_type} {stripped}") | ||
|
||
# Generate object code | ||
|
||
flags = ['jumptable.c', '-o', 'a.out', | ||
'-Wl,--defsym,_start=0', '-nostdlib', '-nostartfiles', '-O2'] | ||
# DLL or executable? | ||
if pic: | ||
flags += ['-fPIC', '-shared'] | ||
# Include debuginfo? | ||
if not strip: | ||
flags.append('-g') | ||
|
||
gcc(flags) | ||
|
||
# Generate disasm | ||
|
||
caller = 'bar' | ||
out = disasm('a.out', not gdb, strip, caller) | ||
|
||
# Print snippets | ||
|
||
jumps = grep(out, r'\bjmp') | ||
print('''\ | ||
table jumps: | ||
{} | ||
'''.format('\n '.join(jumps))) |
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,27 @@ | ||
__attribute__((noinline)) void foo() {} | ||
__attribute__((noinline)) void baz() {} | ||
|
||
int bar(int x) { | ||
// Should generate jumptable | ||
switch (x) { | ||
case 0: | ||
return 10; | ||
case 1: | ||
baz("-14"); | ||
case 3: | ||
return -25; | ||
case 4: | ||
return -27; | ||
case 5: | ||
return 35; | ||
case 6: | ||
return 99; | ||
case 7: | ||
return 33; | ||
case 8: | ||
return 12; | ||
case 9: | ||
foo(); | ||
return 12; | ||
} | ||
} |
Oops, something went wrong.