Cleanup repository

This commit is contained in:
Théophile Bastian 2019-07-15 14:12:13 +02:00
parent f81ca9e33b
commit 77f937a368
10 changed files with 2681 additions and 1 deletions

2
.gitignore vendored
View file

@ -23,3 +23,5 @@ setup.log
*.plugin *.plugin
ml_dwarf_write.bin ml_dwarf_write.bin
tmp.marshal tmp.marshal
dwarfsynth.tar.gz
tmp

4
csmith/.gitignore vendored
View file

@ -1 +1,3 @@
0[0-9]/ platform.info
investigation
kept_tests

14
test/rec.c Normal file
View file

@ -0,0 +1,14 @@
#include <stdio.h>
int fac(int n) {
if(n <= 0)
return 0;
if(n == 1)
return 1;
return n * fac(n-1);
}
int main(void) {
printf("%d\n", fac(4));
return 0;
}

1
tools/check_rbp_rsp_shift/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.log

View file

@ -0,0 +1,8 @@
TARGETS:= \
$(shell find /usr/bin -executable) \
$(shell find /usr/lib -executable)
all: $(TARGETS:=.elf)
%.elf:
@readelf -wF "$*" 2>/dev/null | ./check_rbp_rsp_shift.py "$*"

View file

@ -0,0 +1,94 @@
#!/usr/bin/python
from enum import IntEnum
import sys
""" Parse a `readelf -wF` output, trying to locate CFA=f(rbp) to CFA=g(rsp) changes,
and to detect the offset applied to rsp in such cases. """
class Eof(Exception):
pass
program_name = sys.argv[1]
def log_entry(entry):
print("[{}] {}".format(program_name, entry))
def parse_line(line):
spl = line.strip().split(" ")
addr = int(spl[0], 16)
cfa = spl[1]
return addr, cfa
def match_fde_header(line):
spl = line.strip().split()
if len(spl) == 6 and spl[3] == "FDE":
return True
return False
class CfaType(IntEnum):
OTHER = 0
RSP_BASED = 1
RBP_BASED = 2
def get_cfa_type(cfa):
if cfa.startswith("rsp"):
return CfaType.RSP_BASED
if cfa.startswith("rbp"):
return CfaType.RBP_BASED
return CfaType.OTHER
def parse_fde(lines):
# Read until FDE head
for line in lines:
if match_fde_header(line):
break
try:
post_header = next(lines) # Waste a line — FDE columns head
if not post_header.strip(): # Empty FDE — return now
return True
except StopIteration:
return False
# Read each row until an empty line is found
prev_rbp = False # Was the last line rbp indexed?
closed_rbp_block = False # Was there already a rbp-indexed block which is over?
for line in lines:
line = line.strip()
if not line: # Empty line — FDE end
return True
addr, cfa = parse_line(line)
cfa_type = get_cfa_type(cfa)
if cfa_type == CfaType.RSP_BASED and prev_rbp:
closed_rbp_block = True
if cfa != "rsp+8":
log_entry(
"(E) {}: CFA={} after %rbp-based index".format(hex(addr), cfa)
)
if cfa_type == CfaType.RBP_BASED:
prev_rbp = True
if closed_rbp_block:
log_entry("(W) {}: two %rbp blocks in function".format(addr))
else:
prev_rbp = False
return False
if __name__ == "__main__":
handle = sys.stdin
while parse_fde(handle):
pass

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
import sys
for line in sys.stdin:
if not line.startswith("["):
print(line, end="") # not our lines?
continue
firstpar = line.find(")")
if firstpar < 0:
print(line, end="")
continue
addr_beg = firstpar + 2
addr_end = line.find(":", addr_beg)
addr = line[addr_beg:addr_end]
hexaddr = hex(int(addr))
repl = line[:addr_beg] + hexaddr + line[addr_end:]
print(repl, end="")

View file

@ -0,0 +1,20 @@
#!/usr/bin/env python
import sys
import subprocess
def fetch_disasm(elfpath, addr):
output = subprocess.check_output([' # TODO
for line in sys.stdin:
line_data = line.strip().split(":")[0]
elfpath, kind, addr = line_data.split()
elfpath = elfpath[1:-1] # Remove '[]'
if kind != "(E)":
continue
print(line, end="")
print(fetch_disasm(elfpath, addr), end="")
print("------")

View file

@ -0,0 +1,10 @@
#!/bin/bash
grep "(E)" | while read line; do
elf=$(echo "$line" | cut -d' ' -f1 | sed 's/\[\(.*\)\]/\1/g')
addr=$(echo "$line" | sed 's/^.*0x\([0-9a-fA-F]*\):.*$/\1/g')
echo "$line"
objdump -d "$elf" | grep -C 1 -e "^ *$addr:"
echo "-----"
done