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

libmcount: support no-plt binary #1820

Merged
merged 2 commits into from
Oct 10, 2023
Merged

libmcount: support no-plt binary #1820

merged 2 commits into from
Oct 10, 2023

Conversation

ChoKyuWon
Copy link
Contributor

Issue #1777 reported that no-plt binary is handled as plt-enable binary because some functions are still left in plt section. The patch fixes this bug by comparing the name of self with a list of known functions.

@namhyung
Copy link
Owner

namhyung commented Sep 2, 2023

I need to refresh my memory on this. Please expect some delays..

@ChoKyuWon ChoKyuWon force-pushed the master branch 3 times, most recently from 4b712b5 to cd2f88c Compare September 3, 2023 17:34
Copy link
Owner

@namhyung namhyung left a comment

Choose a reason for hiding this comment

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

From a quick glance, it looks good. Let me test it more..

arch/x86_64/mcount-noplt.c Outdated Show resolved Hide resolved
utils/symbol.c Show resolved Hide resolved
libmcount/plthook.c Outdated Show resolved Hide resolved
arch/x86_64/symbol.c Outdated Show resolved Hide resolved
libmcount/plthook.c Outdated Show resolved Hide resolved
libmcount/plthook.c Show resolved Hide resolved
@@ -93,6 +93,7 @@ int arch_load_dynsymtab_noplt(struct uftrace_symtab *dsymtab, struct uftrace_elf
pr_dbg3("[%zd] %c %lx + %-5u %s\n", dsymtab->nr_sym, sym->type, sym->addr,
sym->size, sym->name);
}
sort_dynsymtab(dsymtab);
Copy link
Owner

Choose a reason for hiding this comment

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

I think this change can be applied separately.

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, actually I meant the sort_dynsymtab() only. I think you can split the changes in the following way.

  1. add sort_dynsymtab() at the end of arch_load_dynsymtab_noplt(). It's an independent issue and can go separately.
  2. add arch_load_dynsymtab_noplt() to load_dynsymtab(). This should have no effect to normal PLT binaries.
  3. check PLT with additional skip symbols and read from .rela.dyn.

@ChoKyuWon ChoKyuWon force-pushed the master branch 6 times, most recently from 2561230 to 4893696 Compare September 6, 2023 06:51
@ChoKyuWon ChoKyuWon force-pushed the master branch 2 times, most recently from 73dda35 to ad939be Compare September 15, 2023 18:56
Copy link
Owner

@namhyung namhyung left a comment

Choose a reason for hiding this comment

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

Looks good, can you update the TBU part in the first commit message?


for (size_t i = 0; i < jmprel_nr; i += (is_rela ? sizeof(Elf64_Rela) : sizeof(Elf64_Rel))) {
bool found = false;
Elf64_Rela *rel = (void *)jmprel_addr + i;
Copy link
Owner

Choose a reason for hiding this comment

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

I prefer having a blank line after the declaration.

@ChoKyuWon ChoKyuWon force-pushed the master branch 2 times, most recently from 028f43b to 5ad537b Compare September 16, 2023 20:00
Copy link
Owner

@namhyung namhyung left a comment

Choose a reason for hiding this comment

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

Would you please rebase your changes onto the current master? It's already encouraged to do so (at least for uftrace) when you update your branch, thanks!

Issue reported that no-plt binary is handled as plt-enable
binary because some functions are still left in plt section.
The patch fixes this bug by comparing the name of self with
a list of known functions.

Fixes: namhyung#1777

Signed-off-by: ChoKyuWon <[email protected]>
`load_dynsymtab` only loaded the dynamic symbols from `dynsym` and
PLTs(`.rel(a).plt` and `.plt`). this commit fixes it to call the
`arch_load_dynsymtab_noplt` in the `load_dynsymtab`, so it also loads the
dynamic symbols from the `rel(a).dyn`, which normally saves the symbols
in case of no-plt option.

Signed-off-by: ChoKyuWon <[email protected]>
@namhyung namhyung merged commit 800139d into namhyung:master Oct 10, 2023
@namhyung
Copy link
Owner

Sorry about the long delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants