-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfind_tu.py
38 lines (31 loc) · 1.37 KB
/
find_tu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import re
import glob
import tqdm
def main():
addresses = {}
asm_files = glob.glob("asm/**/*.s", recursive=True)
for asm_file in tqdm.tqdm(asm_files, desc="Finding TUs"):
if asm_file.endswith("crt0.s"):
continue
with open(asm_file, mode="r") as fh:
for index, line in enumerate(fh):
# Check for %gp_rel
if match := re.match(r"^(.*)%gp_rel\(([^)]+)\)(.*)$", line):
instr_pre = match.group(1)
instr_post = match.group(3)
address_str = match.group(2)
if addresses.get(address_str) == "hi/lo":
print(f"Inconsistent data access detected at line {index} in {asm_file}")
else:
addresses[address_str] = "gp"
# Check for %hi or %lo
elif match := re.match(r"^(.*)%(hi|lo)\(([^)]+)\)(.*)$", line):
instr_pre = match.group(1)
instr_post = match.group(4)
address_str = match.group(3)
if addresses.get(address_str) == "gp":
print(f"Inconsistent data access detected at line {index} in {asm_file}")
else:
addresses[address_str] = "hi/lo"
if __name__ == "__main__":
main()