Skip to content

Resolver for GSYM format. - #22

Merged
ThinkerYzu1 merged 1 commit into
libbpf:masterfrom
ThinkerYzu1:resolver-gsym
Jan 6, 2023
Merged

Resolver for GSYM format.#22
ThinkerYzu1 merged 1 commit into
libbpf:masterfrom
ThinkerYzu1:resolver-gsym

Conversation

@ThinkerYzu1

Copy link
Copy Markdown
Collaborator

Parse GSYM format to symbolize addresses.

@danielocfb

Copy link
Copy Markdown
Collaborator

Many thanks for splitting the pull request into smaller bits! Do you intend to address the comments that I raised over in #17?

@ThinkerYzu1

Copy link
Copy Markdown
Collaborator Author

Fixed feedbacks in #17.

@ThinkerYzu1
ThinkerYzu1 force-pushed the resolver-gsym branch 3 times, most recently from 41447ee to 741ed43 Compare December 6, 2022 23:02

@danielocfb danielocfb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Gave it a first pass. Overall it looks okay, but I left a few comments that I think we should address.

Comment thread src/gsym.rs
Comment thread src/gsym.rs
Comment thread src/gsym.rs Outdated
Comment thread src/gsym/parser.rs
Comment thread src/gsym/parser.rs Outdated
Comment thread src/gsym/parser.rs Outdated
Comment thread src/gsym/parser.rs Outdated
gsym_fo.read_to_end(&mut data).unwrap();
let ctx = GsymContext::parse_header(&data).unwrap();

assert_eq!(ctx.addr_at(1), 0x00000000004004b0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Similar comment about usage of a linker script as I have below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't see it. What comment are you saying?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't see it. What comment are you saying?

#22 (comment)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Looks like GitHub doesn't work properly.

Comment thread src/gsym/parser.rs
Comment thread src/gsym/parser.rs
Comment thread src/gsym/types.rs Outdated
@ThinkerYzu1
ThinkerYzu1 force-pushed the resolver-gsym branch 2 times, most recently from b1b2301 to 78c54a3 Compare December 13, 2022 01:21
@danielocfb

Copy link
Copy Markdown
Collaborator

It seems as if CI is red for the change in question. Can you please check @ThinkerYzu1 ?

@ThinkerYzu1
ThinkerYzu1 force-pushed the resolver-gsym branch 2 times, most recently from 5c76553 to dba1869 Compare December 13, 2022 21:12
@ThinkerYzu1

Copy link
Copy Markdown
Collaborator Author

Fixed some issues caused by rebase.
Fixed issues raised by feedback.

Comment thread src/gsym/parser.rs Outdated
ctx.header.addr_off_size = 4;
ctx.header.base_address = 0;
// Share the same buffer.
ctx.addr_tab = unsafe { mem::transmute(addr_tab.as_slice()) };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Safety comment is missing and this operation is not safe at all. Rust does not allow the presence of shared reference while a mutable one is outstanding and you create a mutable one below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Got it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I just wrote a safety comment in the test case. Please check it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unfortunately not. It does not matter if both execute at the same time or not. It's not about data races, it's about aliasing. Can you instantiate a new test case fixture for each iteration, perhaps?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure what you expect in safety comments. Rust doesn't like to have mutable and immutable references to the same object at the same time. The problem is not aliasing. The problem is how we use references. Here, the comment is to address the potential problem to explain why it is safe.

By the way, I will create a new instance of ctx every time to avoid this.

Comment thread src/gsym/parser.rs Outdated
Comment on lines +370 to +360
let copy_to_addr_tab = |values: &[u32], addr_tab: &mut [u8]| {
let mut off = 0;
for v in values {
let dst = (&mut addr_tab[off]) as *mut u8;
let src = v as *const u32 as *const u8;
unsafe { copy(src, dst, 4) };
off += 4;
}
};

@danielocfb danielocfb Dec 14, 2022

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So you want to write a couple of u32 into a [u8]? You should be able to use Write in conjunction with u32::to_le_bytes. Please avoid unsafe code and pointer casts and arithmetic, if possible.

@ThinkerYzu1 ThinkerYzu1 Dec 15, 2022

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Although, we support only LE now. Using u32::to_le_bytes() means this test case will only run with LE platform. So, I will change it to to_ne_bytes().

@danielocfb

Copy link
Copy Markdown
Collaborator

Still seeing outstanding open issues. Will wait until those are addressed before giving it a hopefully final pass.

@ThinkerYzu1
ThinkerYzu1 force-pushed the resolver-gsym branch 3 times, most recently from df4a2a9 to 0b7c4c4 Compare December 21, 2022 19:33
@ThinkerYzu1

ThinkerYzu1 commented Dec 22, 2022

Copy link
Copy Markdown
Collaborator Author

I have changed the code in the way I mentioned earlier.

@danielocfb

Copy link
Copy Markdown
Collaborator

Still seeing outstanding open issues. Will wait until those are addressed before giving it a hopefully final pass.

@danielocfb danielocfb added invalid and removed invalid labels Jan 4, 2023
@ThinkerYzu1
ThinkerYzu1 force-pushed the resolver-gsym branch 2 times, most recently from a533840 to 3e9d46e Compare January 4, 2023 23:51
Comment thread data/gsym-example.c
* a custom toolchain. However, it is overkilled.
*
* The recipe is fragile due to the differences between toolchains and
* versions.

@ThinkerYzu1 ThinkerYzu1 Jan 5, 2023

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I try to make it happen. However, it is fragile and complicated (a lot of details).
Someone may be able to make it stable and portable.

Parse GSYM format to symbolize addresses.

Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
@ThinkerYzu1
ThinkerYzu1 merged commit e7e4327 into libbpf:master Jan 6, 2023
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.

4 participants