-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix reading metadata from ELF sections #33321
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
Conversation
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.
The relevant sections are read from the child process inside fieldELFSectionByName
, the code there is unchanged:
auto findELFSectionByName = [&](std::string Name)
-> std::pair<RemoteRef<void>, uint64_t> {
// Now for all the sections, find their name.
for (const typename T::Section *Hdr : SecHdrVec) {
uint32_t Offset = Hdr->sh_name;
auto SecName = std::string(StrTab + Offset);
if (SecName != Name)
continue;
auto SecStart =
RemoteAddress(ImageStart.getAddressData() + Hdr->sh_addr);
auto SecSize = Hdr->sh_size;
auto SecBuf = this->getReader().readBytes(SecStart, SecSize);
auto SecContents = RemoteRef<void>(SecStart.getAddressData(),
SecBuf.get());
savedBuffers.push_back(std::move(SecBuf));
return {SecContents, SecSize};
}
return {nullptr, 0};
};
097b540
to
75ec76e
Compare
75ec76e
to
34246dc
Compare
How do we get access to the file? There might not be one if the target is a running process. |
It's a good point to raise that we need to gracefully handle the case where the buffer is empty. For the debugger use-case LLDB knows how find the file for a process. |
@jckarter Right now, using the ObjectFile API in LLDB, see: swiftlang/llvm-project#1608 I think that if we'd like to do this using only the running process, we'd need to undo the stripping of Section Table Header and mark shstrtab as alloc. |
If that's a possibility, mapping the section table header sounds like an interesting thing to try, since it would allow ELF handling to behave more like Mach-O and PE handling on Mac/Windows, and let us avoid bugs/exploits where the binary on disk drifts from what was originally mapped into memory. |
34246dc
to
712541e
Compare
712541e
to
7d4fdf1
Compare
7d4fdf1
to
d228dfe
Compare
d228dfe
to
f8297a9
Compare
I think we're almost there! |
f8297a9
to
250874b
Compare
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.
Thank you!
@swift-ci smoke test |
@adrian-prantl thanks for iterating on this with me so quickly! |
@swift-ci smoke test |
@adrian-prantl It looks like some tests depended on the old |
be187ab
to
628529b
Compare
@adrian-prantl We actually need to keep I've updated the PR to read from the buffer if it's present, otherwise read using the |
628529b
to
7cd9204
Compare
@swift-ci smoke test |
1 similar comment
@swift-ci smoke test |
This PR fixes reading in the ELF sections related to metadata. Since the Section Table Header and String Table are not present in the process, we read them from the executable's file instead. We then read the relevant sections from the offset given by the Section Table Header in the process's address space.
@adrian-prantl @vedantk