Skip to content

Commit

Permalink
Merge branch 'namhyung:master' into doc-install
Browse files Browse the repository at this point in the history
  • Loading branch information
SEOKMIN83 authored Sep 16, 2023
2 parents 75d7acc + 58e7307 commit f3986c7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 38 deletions.
12 changes: 10 additions & 2 deletions arch/aarch64/mcount-dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ int mcount_setup_trampoline(struct mcount_dynamic_info *mdi)
mdi->trampoline -= sizeof(trampoline);

if (unlikely(mdi->trampoline < mdi->text_addr + mdi->text_size)) {
void *trampoline_check;

mdi->trampoline += sizeof(trampoline);
mdi->text_size += PAGE_SIZE;

pr_dbg("adding a page for fentry trampoline at %#lx\n", mdi->trampoline);

mmap((void *)mdi->trampoline, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
trampoline_check = mmap((void *)mdi->trampoline, PAGE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

if (trampoline_check != (void *)mdi->trampoline) {
pr_err("could not map trampoline at desired location %#lx, got %#lx: %m\n",
mdi->trampoline, (uintptr_t)trampoline_check);
}
}

page_offset = mdi->text_addr & (PAGE_SIZE - 1);
Expand Down
8 changes: 5 additions & 3 deletions arch/i386/mcount-dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ int mcount_setup_trampoline(struct mcount_dynamic_info *mdi)
pr_dbg2("adding a page for fentry trampoline at %#lx\n", mdi->trampoline);

trampoline_check = mmap((void *)mdi->trampoline, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

if (trampoline_check == MAP_FAILED)
pr_err("failed to mmap trampoline for setup");
if (trampoline_check != (void *)mdi->trampoline) {
pr_err("could not map trampoline at desired location %#lx, got %#lx: %m\n",
mdi->trampoline, (uintptr_t)trampoline_check);
}
}

if (mprotect((void *)mdi->text_addr, mdi->text_size, PROT_READ | PROT_WRITE)) {
Expand Down
9 changes: 6 additions & 3 deletions arch/x86_64/mcount-dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ int mcount_setup_trampoline(struct mcount_dynamic_info *mdi)

trampoline_check = mmap((void *)mdi->trampoline, PAGE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

if (trampoline_check == MAP_FAILED)
pr_err("failed to mmap trampoline for setup");
if (trampoline_check != (void *)mdi->trampoline) {
pr_err("could not map trampoline at desired location %#lx, got %#lx: %m\n",
mdi->trampoline, (uintptr_t)trampoline_check);
}
}

if (mprotect(PAGE_ADDR(mdi->text_addr), PAGE_LEN(mdi->text_addr, mdi->text_size),
Expand Down Expand Up @@ -623,6 +625,7 @@ int mcount_unpatch_func(struct mcount_dynamic_info *mdi, struct uftrace_symbol *

switch (mdi->type) {
case DYNAMIC_FENTRY:
case DYNAMIC_PATCHABLE:
result = unpatch_fentry_func(mdi, sym);
break;

Expand Down
14 changes: 13 additions & 1 deletion libmcount/dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ static void patch_patchable_func_matched(struct mcount_dynamic_info *mdi, struct
.size = UINT_MAX,
.name = namebuf,
};
bool found = false;
int match;
char *soname = get_soname(map->libname);

symtab = &map->mod->symtab;
Expand All @@ -531,9 +533,19 @@ static void patch_patchable_func_matched(struct mcount_dynamic_info *mdi, struct
continue;
}

mcount_patch_func_with_stats(mdi, sym);
found = true;
match = match_pattern_list(map, soname, sym->name);
if (!match)
continue;
else if (match == 1)
mcount_patch_func_with_stats(mdi, sym);
else
mcount_unpatch_func(mdi, sym, NULL);
}

if (!found)
stats.nomatch++;

free(soname);
}

Expand Down
48 changes: 19 additions & 29 deletions tests/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ def is_32bit(filename):
# e_ident[] indexes
EI_CLASS = 4

# EI_CLASS
ELFCLASSNONE = 0
# EI_CLASS: ELFCLASSNONE, ELFCLASS32, ELFCLASS64, ELFCLASSNUM
ELFCLASS32 = 1
ELFCLASS64 = 2
ELFCLASSNUM = 3

try:
with open(filename, 'rb') as f:
Expand All @@ -32,7 +29,7 @@ def is_32bit(filename):

if ei_class == ELFCLASS32:
return True
except:
except Exception:
pass

return False
Expand All @@ -59,11 +56,11 @@ def get_elf_machine(filename):

# read e_machine
e_machine = f.read(2)[0]
if type(e_machine) is str:
if isinstance(e_machine, str):
e_machine = ord(e_machine)

return machine[e_machine]
except:
except Exception:
pass

return None
Expand Down Expand Up @@ -144,7 +141,7 @@ def gen_port(self, start = 40000, end = 50000):
s.bind(("localhost", port))
self.port = port
return
except OSError as e:
except OSError:
pass
raise Exception("No available port found")

Expand All @@ -156,7 +153,7 @@ def test_feature(self):
for i in range(3, len(s) - 1):
self.feature.add(s[i])
return True
except:
except Exception:
return False

def convert_abs_path(self, build_cmd):
Expand Down Expand Up @@ -185,7 +182,7 @@ def build_it(self, build_cmd):
except OSError as e:
self.pr_debug(e.strerror)
return TestBase.TEST_BUILD_FAIL
except:
except Exception:
return TestBase.TEST_BUILD_FAIL

def build(self, name, cflags='', ldflags=''):
Expand All @@ -199,11 +196,9 @@ def build(self, name, cflags='', ldflags=''):

build_cflags = ' '.join(TestBase.default_cflags + [self.cflags, cflags, \
os.getenv(lang['flags'], '')])
build_ldflags = ' '.join([self.ldflags, ldflags, \
os.getenv('LDFLAGS', '')])
build_ldflags = ' '.join([self.ldflags, ldflags, os.getenv('LDFLAGS', '')])

build_cmd = '%s -o %s %s %s %s' % \
(lang['cc'], prog, build_cflags, src, build_ldflags)
build_cmd = '%s -o %s %s %s %s' % (lang['cc'], prog, build_cflags, src, build_ldflags)

self.pr_debug("build command: %s" % build_cmd)
return self.build_it(build_cmd)
Expand All @@ -213,8 +208,7 @@ def build_notrace_lib(self, dstname, srcname, cflags='', ldflags =''):

build_cflags = ' '.join(TestBase.default_cflags + [self.cflags, cflags, \
os.getenv(lang['flags'], '')])
build_ldflags = ' '.join([self.ldflags, ldflags, \
os.getenv('LDFLAGS', '')])
build_ldflags = ' '.join([self.ldflags, ldflags, os.getenv('LDFLAGS', '')])

lib_cflags = build_cflags + ' -shared -fPIC'

Expand All @@ -230,17 +224,15 @@ def build_libabc(self, cflags='', ldflags=''):

build_cflags = ' '.join(TestBase.default_cflags + [self.cflags, cflags, \
os.getenv(lang['flags'], '')])
build_ldflags = ' '.join([self.ldflags, ldflags, \
os.getenv('LDFLAGS', '')])
build_ldflags = ' '.join([self.ldflags, ldflags, os.getenv('LDFLAGS', '')])

lib_cflags = build_cflags + ' -shared -fPIC'

if '-fpatchable-function-entry' in cflags:
self.p_libs.append('libabc_test_lib.so')

# build libabc_test_lib.so library
build_cmd = '%s -o libabc_test_lib.so %s s-lib.c %s' % \
(lang['cc'], lib_cflags, build_ldflags)
build_cmd = '%s -o libabc_test_lib.so %s s-lib.c %s' % (lang['cc'], lib_cflags, build_ldflags)

self.pr_debug("build command for library: %s" % build_cmd)
return self.build_it(build_cmd)
Expand All @@ -250,8 +242,7 @@ def build_libfoo(self, name, cflags='', ldflags=''):

build_cflags = ' '.join(TestBase.default_cflags + [self.cflags, cflags, \
os.getenv(lang['flags'], '')])
build_ldflags = ' '.join([self.ldflags, ldflags, \
os.getenv('LDFLAGS', '')])
build_ldflags = ' '.join([self.ldflags, ldflags, os.getenv('LDFLAGS', '')])

lib_cflags = build_cflags + ' -shared -fPIC'

Expand Down Expand Up @@ -338,7 +329,7 @@ def task_sort(self, output, ignore_children=False):
m = pid_patt.match(ln)
try:
pid = int(m.group(1))
except:
except Exception:
continue

func = ln.split('|', 1)[-1]
Expand All @@ -358,7 +349,7 @@ def task_sort(self, output, ignore_children=False):
for p in pid_list:
result += '\n'.join(pids[p]['result']) + '\n'
result = result.strip()
except:
except Exception:
pass # this leads to a failure with 'NG'
return result

Expand Down Expand Up @@ -393,7 +384,7 @@ def report_sort(self, output, ignored):
try:
if line[-1].startswith('__'):
continue
except:
except Exception:
pass
result.append('%s %s' % (line[-2], line[-1]))

Expand Down Expand Up @@ -430,7 +421,6 @@ def graph_sort(self, output, ignored):
def dump_sort(self, output, ignored):
""" This function post-processes output of the test to be compared .
It ignores blank and comment (#) lines and remaining functions. """
mode = 1
result = []

# A (raw) dump result consists of following data
Expand Down Expand Up @@ -470,7 +460,7 @@ def chrome_sort(self, output, ignored):
result = []
try:
o = json.loads(output)
except:
except Exception:
return ''
for ln in o['traceEvents']:
if ln['name'].startswith('__'):
Expand Down Expand Up @@ -545,7 +535,7 @@ def check_perf_paranoid(self):

if v >= 3:
return False
except:
except Exception:
pass

return True
Expand Down Expand Up @@ -698,7 +688,7 @@ def timeout_handler(sig, frame):
dif = "%s: diff result of %s %s\n" % (name, compiler, cflags)
try:
p = sp.Popen(['colordiff', '-U1', 'expect', 'result'], stdout=sp.PIPE)
except:
except Exception:
p = sp.Popen(['diff', '-U1', 'expect', 'result'], stdout=sp.PIPE)
dif += p.communicate()[0].decode(errors='ignore')
os.remove('expect')
Expand Down

0 comments on commit f3986c7

Please sign in to comment.