Skip to content

[lldb] [ObjectFileMachO] BSS segments are loadable segments #96983

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6159,10 +6159,6 @@ Section *ObjectFileMachO::GetMachHeaderSection() {
bool ObjectFileMachO::SectionIsLoadable(const Section *section) {
if (!section)
return false;
const bool is_dsym = (m_header.filetype == MH_DSYM);
if (section->GetFileSize() == 0 && !is_dsym &&
section->GetName() != GetSegmentNameDATA())
return false;
if (section->IsThreadSpecific())
return false;
if (GetModule().get() != section->GetModule().get())
Expand Down Expand Up @@ -6202,6 +6198,7 @@ lldb::addr_t ObjectFileMachO::CalculateSectionLoadAddressForMemoryImage(

bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value,
bool value_is_offset) {
Log *log(GetLog(LLDBLog::DynamicLoader));
ModuleSP module_sp = GetModule();
if (!module_sp)
return false;
Expand All @@ -6217,17 +6214,33 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value,
// malformed.
const bool warn_multiple = true;

if (log) {
StreamString logmsg;
logmsg << "ObjectFileMachO::SetLoadAddress ";
if (GetFileSpec())
logmsg << "path='" << GetFileSpec().GetPath() << "' ";
if (GetUUID()) {
logmsg << "uuid=" << GetUUID().GetAsString();
}
LLDB_LOGF(log, "%s", logmsg.GetData());
}
if (value_is_offset) {
// "value" is an offset to apply to each top level segment
for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
// Iterate through the object file sections to find all of the
// sections that size on disk (to avoid __PAGEZERO) and load them
SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
if (SectionIsLoadable(section_sp.get()))
if (SectionIsLoadable(section_sp.get())) {
LLDB_LOGF(log,
"ObjectFileMachO::SetLoadAddress segment '%s' load addr is "
"0x%" PRIx64,
section_sp->GetName().AsCString(),
section_sp->GetFileAddress() + value);
if (target.GetSectionLoadList().SetSectionLoadAddress(
section_sp, section_sp->GetFileAddress() + value,
warn_multiple))
++num_loaded_sections;
}
}
} else {
// "value" is the new base address of the mach_header, adjust each
Expand All @@ -6242,6 +6255,10 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value,
CalculateSectionLoadAddressForMemoryImage(
value, mach_header_section, section_sp.get());
if (section_load_addr != LLDB_INVALID_ADDRESS) {
LLDB_LOGF(log,
"ObjectFileMachO::SetLoadAddress segment '%s' load addr is "
"0x%" PRIx64,
section_sp->GetName().AsCString(), section_load_addr);
if (target.GetSectionLoadList().SetSectionLoadAddress(
section_sp, section_load_addr, warn_multiple))
++num_loaded_sections;
Expand Down
Loading