Skip to content

Commit

Permalink
Change dwarf_mips64el.c to not use globals
Browse files Browse the repository at this point in the history
Now we don't depend on whether relocations on globals in .o should be performed or not.
  • Loading branch information
Noam Yorav-Raphael committed Aug 25, 2023
1 parent bde61d8 commit d81a765
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
19 changes: 6 additions & 13 deletions test/run_dwarfdump_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from multiprocessing import Pool
import os
import platform
import re
import sys
import time

Expand Down Expand Up @@ -43,15 +44,6 @@ def discover_testfiles(rootdir):
if ext == '.elf':
yield os.path.join(rootdir, filename)

def fix_llvm_dwarfdump_bug(output):
""" For some reason, llvm-dwarfdump misses a relocation for the MIPS64 .o file.
However, gcc's objdump does the relocation like pyelftools.
So just fix the output. Very ugly.
"""
# Assert there are 2 'DW_OP_addr 0x0' strings. Replace the first one with 'DW_OP_addr 0x4'.
parts = output.split('DW_OP_addr 0x0')
assert len(parts) == 3
return parts[0] + 'DW_OP_addr 0x4' + parts[1] + 'DW_OP_addr 0x0' + parts[2]

def run_test_on_file(filename, verbose=False, opt=None):
""" Runs a test on the given input filename. Return True if all test
Expand Down Expand Up @@ -88,8 +80,6 @@ def run_test_on_file(filename, verbose=False, opt=None):
stdouts.append(stdout)
if verbose: testlog.info('....comparing output...')
t1 = time.time()
if 'mips64' in filename:
stdouts[0] = fix_llvm_dwarfdump_bug(stdouts[0])
rc, errmsg = compare_output(*stdouts)
if verbose: testlog.info("....elapsed: %s" % (time.time() - t1,))
if rc:
Expand All @@ -112,11 +102,14 @@ def compare_output(s1, s2):
and errmsg is empty. Otherwise success is False and errmsg holds a
description of the mismatch.
"""
def remove_zero_address_symbol(s):
return s.replace('(0x0000000000000000 ".text")', '(0x0000000000000000)')

def prepare_lines(s):
return [line for line in s.lower().splitlines() if line.strip() != '']

lines1 = prepare_lines(s1)
lines2 = prepare_lines(s2)
lines1 = prepare_lines(remove_zero_address_symbol(s1))
lines2 = prepare_lines(remove_zero_address_symbol(s2))

if len(lines1) != len(lines2):
return False, 'Number of lines different: %s vs %s' % (
Expand Down
Binary file modified test/testfiles_for_dwarfdump/dwarf_mips64el.o.elf
Binary file not shown.
7 changes: 5 additions & 2 deletions test/testfiles_for_dwarfdump/dwarf_mips64el/dwarf_mips64el.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
int var1 = 3;
int var2 = 5;
int f() {
int var1 = 3;
int var2 = 5;
return var1 + var2;
}

0 comments on commit d81a765

Please sign in to comment.