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

link/uprobe: fix offsets for statically linked binaries #385

Merged
merged 2 commits into from
Sep 7, 2021

Conversation

mmat11
Copy link
Contributor

@mmat11 mmat11 commented Aug 23, 2021

Copy link
Collaborator

@lmb lmb left a comment

Choose a reason for hiding this comment

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

Can you add a commit description that explains what is going on? Right now it's just copy pasta from bcc which is a great start, but we should have an understanding why this is the right thing to do.

return &s, nil
func (ex *Executable) offset(symbol string) (uint64, error) {
if off, ok := ex.offsets[symbol]; ok {
// Symbols with location 0 from section undef are shared library calls and
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you break this change into a separate commit and explain why moving it makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning is: since we have to do operations on the offsets, we either store a fake elf.Symbol with the modified offset value or store the offset values directly. I decided to go for the latter and move this check where we get the value.
Since I don't have an elf.Symbol to check anymore, I am now assuming that if the offset value is 0, we have an external symbol. (I am not 100% sure about this assumption so the error text may be misleading here)

Let me know if you have a better idea

@mmat11 mmat11 force-pushed the matt/fix-uprobe-offsets branch 2 times, most recently from b2e7af2 to 27067b1 Compare August 26, 2021 22:23
@mmat11 mmat11 marked this pull request as ready for review August 26, 2021 22:26
@mmat11 mmat11 force-pushed the matt/fix-uprobe-offsets branch 2 times, most recently from db1e24a to 5aa637b Compare August 27, 2021 07:31
@mmat11
Copy link
Contributor Author

mmat11 commented Aug 27, 2021

Putting back as draft, the test is failing on 4.9 (tracefs) but I can't reproduce locally even if I force that path, I'll investigate

@lmb
Copy link
Collaborator

lmb commented Sep 2, 2021

the test is failing on 4.9 (tracefs) but I can't reproduce locally even if I force that path

What do you mean by that? You can't repro locally on 4.9, or you can't reproduce if you force tracefs usage on a newer kernel?

@mmat11
Copy link
Contributor Author

mmat11 commented Sep 2, 2021

the test is failing on 4.9 (tracefs) but I can't reproduce locally even if I force that path

What do you mean by that? You can't repro locally on 4.9, or you can't reproduce if you force tracefs usage on a newer kernel?

The latter. If I modify the code and force tracefs, the test passes on all kernels except 4.9.

I wrote "can't reproduce locally" because I assumed the kernel version was not a problem, but it is.

@lmb
Copy link
Collaborator

lmb commented Sep 2, 2021

Maybe @brycekahle or @Gui774ume have an idea what this could be? ebpf-manager seems to have similar code to this.

@lmb
Copy link
Collaborator

lmb commented Sep 7, 2021

I think it's worth getting this merged if it fixes stuff on newer kernels. How about we skip the failing test on 4.9 and create an issue that contains a reproducer?

An unrelated idea: could we instrument the go binary instead of shipping a pre-compiled elf?

$ nm /usr/local/bin/go | grep mainUsage
00000000008c17a0 T main.mainUsage

@mmat11
Copy link
Contributor Author

mmat11 commented Sep 7, 2021

I think it's worth getting this merged if it fixes stuff on newer kernels. How about we skip the failing test on 4.9 and create an issue that contains a reproducer?

Makes sense, my plan was to manually test the same binary on a 4.9 kernel VM. I can do this later and eventually add some comments (or a fix, depending on what's causing it to fail).

An unrelated idea: could we instrument the go binary instead of shipping a pre-compiled elf?

$ nm /usr/local/bin/go | grep mainUsage
00000000008c17a0 T main.mainUsage

Good idea, I'll explore this option later today or tomorrow

@mmat11 mmat11 force-pushed the matt/fix-uprobe-offsets branch from a928b86 to c2c4534 Compare September 7, 2021 12:15
Use the following function to calculate the start address of a function:

    fn symbol offset = fn symbol VA - .text VA + .text offset

Store raw offsets instead of elf.Symbol in the Executable struct.

Signed-off-by: Mattia Meleleo <[email protected]>
@mmat11 mmat11 force-pushed the matt/fix-uprobe-offsets branch from c2c4534 to c488609 Compare September 7, 2021 12:27
@mmat11 mmat11 marked this pull request as ready for review September 7, 2021 12:27
@mmat11
Copy link
Contributor Author

mmat11 commented Sep 7, 2021

@lmb I skipped the test on 4.9 and opened #406 to keep track of it.

I think #399 and #358 can be closed after this is merged

Copy link
Collaborator

@lmb lmb left a comment

Choose a reason for hiding this comment

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

LGTM! Can you add a reproducer + some context to the issue?

@lmb lmb merged commit 1192a95 into cilium:master Sep 7, 2021
@mmat11 mmat11 deleted the matt/fix-uprobe-offsets branch November 1, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants