-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
dl_iterate_phdr implementation #2354
Conversation
This looks good. I'm taking a look into the extern weak thing and see if I can resolve that, then I'll merge. |
Ah - I do think it would be valuable to get some test coverage for this. Related: Lines 20 to 26 in 75d42ac
|
Some fix ups for you to look at, and then I do think we should have tests for this, and then I think it will be good to merge. |
std/os/linux/test.zig
Outdated
@@ -42,3 +44,39 @@ test "timer" { | |||
// TODO implicit cast from *[N]T to [*]T | |||
err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1); | |||
} | |||
|
|||
export fn iter_fn(info: *linux.dl_phdr_info, size: usize, data: ?*usize) i32 { | |||
var counter = data orelse @panic("???"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just be orelse unreachable
I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I went with .?
It should not matter since lld produces that symbol (and so does binutils I've added a simple test for the non-libc case that should be quite exhaustive. A few notes:
|
4c69524
to
2e70b9c
Compare
std/os/linux/test.zig
Outdated
var counter: usize = 0; | ||
const r = linux.dl_iterate_phdr(usize, iter_fn, &counter); | ||
expect(r == 0); | ||
expect(counter == 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this liable to break in future if we somehow end up using other libraries in the test suite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, but the test is easy to change when/if that happens.
Test failure on the CI:
|
2e70b9c
to
a095db0
Compare
@daurnimator was right, the test was too flakey. I've replaced it with one inspired by this one and now the CI is green :) |
Also comes with a libc-less version that should work just fine in most cases.
I guess the code is portable enough to work on *BSDs too, I'd be happy to move it out of the linux namespace if somebody tests it.
I didn't manage to mark the
__ehdr_entry
as weak, similar to how you'd do with this C declaration:I'll squash the spurious commit once the review is over.