Skip to content

Commit 6dac04b

Browse files
committed
Address review comments.
- Fix a case where a section can be larger that 4GB - Fix comments to be a bit more clear - Don't only do this for dSYM files
1 parent 1673e1b commit 6dac04b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,9 +1674,9 @@ void ObjectFileMachO::ProcessSegmentCommand(
16741674
uint32_t segment_sect_idx;
16751675
const lldb::user_id_t first_segment_sectID = context.NextSectionIdx + 1;
16761676

1677-
// dSYM files can create sections whose data exceeds the 4GB barrier, but
1678-
// mach-o sections only have 32 bit offsets. So keep track of when we
1679-
// overflow and fix the sections offsets as we iterate.
1677+
// 64 bit mach-o files have sections with 32 bit file offsets. If any section
1678+
// data end will exceed UINT32_MAX, then we need to do some bookkeeping to
1679+
// ensure we can access this data correctly.
16801680
uint64_t section_offset_adjust = 0;
16811681
const uint32_t num_u32s = load_cmd.cmd == LC_SEGMENT ? 7 : 8;
16821682
for (segment_sect_idx = 0; segment_sect_idx < load_cmd.nsects;
@@ -1701,14 +1701,15 @@ void ObjectFileMachO::ProcessSegmentCommand(
17011701
// isn't stored in the abstracted Sections.
17021702
m_mach_sections.push_back(sect64);
17031703

1704-
// Make sure we can load dSYM files whose __DWARF sections exceed the 4GB
1705-
// barrier. llvm::MachO::section_64 have only 32 bit file offsets for the
1706-
// section contents.
1704+
// Make sure we can load sections in mach-o files where some sections cross
1705+
// a 4GB boundary. llvm::MachO::section_64 have only 32 bit file offsets
1706+
// for the file offset of the section contents, so we need to track and
1707+
// sections that overflow and adjust the offsets accordingly.
17071708
const uint64_t section_file_offset = sect64.offset + section_offset_adjust;
1708-
// If this section overflows a 4GB barrier, then we need to adjust any
1709-
// subsequent the section offsets.
1710-
if (is_dsym && ((uint64_t)sect64.offset + sect64.size) >= UINT32_MAX)
1711-
section_offset_adjust += 0x100000000ull;
1709+
const uint64_t end_section_offset = (uint64_t)sect64.offset + sect64.size;
1710+
if (end_section_offset >= UINT32_MAX)
1711+
section_offset_adjust += end_section_offset & 0xFFFFFFFF00000000ull;
1712+
17121713
if (add_section) {
17131714
ConstString section_name(
17141715
sect64.sectname, strnlen(sect64.sectname, sizeof(sect64.sectname)));

0 commit comments

Comments
 (0)