Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic: Fix -U for -fpatchable-function-entry #1799

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/x86_64/mcount-dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ int mcount_unpatch_func(struct mcount_dynamic_info *mdi, struct uftrace_symbol *

switch (mdi->type) {
case DYNAMIC_FENTRY:
case DYNAMIC_PATCHABLE:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there's nothing to unpatch for -fpatchable-function-entry as they are already NOPs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does its job in the following example.

$ g++ -fpatchable-function-entry=5 example.cpp

$ uftrace record -P. -U ^std:: a.out

Since -P. asks patching all the available functions, we need a way to suppress the previous patching request.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, multiple updates also make it useful.

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC I saw this change in the Ciena's work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it looks 151fb61 missed fixing patch_patchable_func_matched along with patch_normal_func_matched.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it has other problems, I think I can merge this one first.

}

if (!found)
stats.nomatch++;

free(soname);
}

Expand Down