Skip to content

llvm-objcopy calculates section locations incorrectly for MachO files #141494

Open
@peledins-zimperium

Description

@peledins-zimperium

https://github.com/llvm/llvm-project/pull/130517/files introduced a change

          if (RequiresFirstSectionOutsideFirstPage) {
            SectOffset = alignToPowerOf2(SectOffset, PageSize);
            RequiresFirstSectionOutsideFirstPage = false;
          }

This is an issue for several reasons:

  1. If the first section is outside of first page (0x4000), but starts at (0x4004), then this gets aligned to (0x8000), which is not necessary. Here a fix could be
if (RequiresFirstSectionOutsideFirstPage && SectOffset < PageSize) {
  1. However, if the block is actually entered, then trouble happens with next sections: they do not get moved together with this section. Then we can get to a state of truncated or malformed object (section contents at offset 20160 with a size of 111316, overlaps section contents at offset 32768 with a size of 228)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions