Skip to content

release/20.x: [objcopy][MachO] Revert special handling of encryptable binaries (#144058) #144449

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

Open
wants to merge 1 commit into
base: release/20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ uint64_t MachOLayoutBuilder::layoutSegments() {
const bool IsObjectFile =
O.Header.FileType == MachO::HeaderFileType::MH_OBJECT;
uint64_t Offset = IsObjectFile ? (HeaderSize + O.Header.SizeOfCmds) : 0;
// If we are emitting an encryptable binary, our load commands must have a
// separate (non-encrypted) page to themselves.
bool RequiresFirstSectionOutsideFirstPage =
O.EncryptionInfoCommandIndex.has_value();
for (LoadCommand &LC : O.LoadCommands) {
auto &MLC = LC.MachOLoadCommand;
StringRef Segname;
Expand Down Expand Up @@ -173,10 +169,6 @@ uint64_t MachOLayoutBuilder::layoutSegments() {
if (!Sec->hasValidOffset()) {
Sec->Offset = 0;
} else {
if (RequiresFirstSectionOutsideFirstPage) {
SectOffset = alignToPowerOf2(SectOffset, PageSize);
RequiresFirstSectionOutsideFirstPage = false;
}
Sec->Offset = SegOffset + SectOffset;
Sec->Size = Sec->Content.size();
SegFileSize = std::max(SegFileSize, SectOffset + Sec->Size);
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/ObjCopy/MachO/MachOObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ void Object::updateLoadCommandIndexes() {
case MachO::LC_DYLD_EXPORTS_TRIE:
ExportsTrieCommandIndex = Index;
break;
case MachO::LC_ENCRYPTION_INFO:
case MachO::LC_ENCRYPTION_INFO_64:
EncryptionInfoCommandIndex = Index;
break;
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/ObjCopy/MachO/MachOObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,6 @@ struct Object {
/// The index of the LC_SEGMENT or LC_SEGMENT_64 load command
/// corresponding to the __TEXT segment.
std::optional<size_t> TextSegmentCommandIndex;
/// The index of the LC_ENCRYPTION_INFO or LC_ENCRYPTION_INFO_64 load command
/// if present.
std::optional<size_t> EncryptionInfoCommandIndex;

BumpPtrAllocator Alloc;
StringSaver NewSectionsContents;
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/ObjCopy/MachO/MachOReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ Error MachOReader::readLoadCommands(Object &O) const {
case MachO::LC_DYLD_CHAINED_FIXUPS:
O.ChainedFixupsCommandIndex = O.LoadCommands.size();
break;
case MachO::LC_ENCRYPTION_INFO:
case MachO::LC_ENCRYPTION_INFO_64:
O.EncryptionInfoCommandIndex = O.LoadCommands.size();
break;
}
#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
case MachO::LCName: \
Expand Down
156 changes: 106 additions & 50 deletions llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
# CHECK: fileoff: 0

# The YAML below is the following code
# ```
# static int foo = 12345;
# int bar = 4567;
# int main(int argc, char **argv) { return 0; }
# ```
# Compiled on macOS against the macOS SDK and passing `-Wl,-encryptable`
# Contents are removed, since they are not important for the test. We need a
# small text segment (smaller than a page).
Expand All @@ -26,8 +30,8 @@ FileHeader:
cputype: 0x100000C
cpusubtype: 0x0
filetype: 0x2
ncmds: 15
sizeofcmds: 696
ncmds: 18
sizeofcmds: 920
flags: 0x200085
reserved: 0x0
LoadCommands:
Expand Down Expand Up @@ -69,7 +73,7 @@ LoadCommands:
- sectname: __unwind_info
segname: __TEXT
addr: 0x100004020
size: 4152
size: 88
offset: 0x4020
align: 2
reloff: 0x0
Expand All @@ -79,37 +83,61 @@ LoadCommands:
reserved2: 0x0
reserved3: 0x0
- cmd: LC_SEGMENT_64
cmdsize: 72
segname: __LINKEDIT
cmdsize: 152
segname: __DATA
vmaddr: 4295000064
vmsize: 592
vmsize: 16384
fileoff: 32768
filesize: 592
filesize: 16384
maxprot: 3
initprot: 3
nsects: 1
flags: 0
Sections:
- sectname: __data
segname: __DATA
addr: 0x100008000
size: 4
offset: 0x8000
align: 2
reloff: 0x0
nreloc: 0
flags: 0x0
reserved1: 0x0
reserved2: 0x0
reserved3: 0x0
- cmd: LC_SEGMENT_64
cmdsize: 72
segname: __LINKEDIT
vmaddr: 4295016448
vmsize: 16384
fileoff: 49152
filesize: 768
maxprot: 1
initprot: 1
nsects: 0
flags: 0
- cmd: LC_DYLD_CHAINED_FIXUPS
cmdsize: 16
dataoff: 32768
datasize: 48
dataoff: 49152
datasize: 56
- cmd: LC_DYLD_EXPORTS_TRIE
cmdsize: 16
dataoff: 32816
datasize: 48
dataoff: 49208
datasize: 64
- cmd: LC_SYMTAB
cmdsize: 24
symoff: 32872
nsyms: 2
stroff: 32904
strsize: 32
symoff: 49280
nsyms: 3
stroff: 49328
strsize: 40
- cmd: LC_DYSYMTAB
cmdsize: 80
ilocalsym: 0
nlocalsym: 0
iextdefsym: 0
nextdefsym: 2
iundefsym: 2
nextdefsym: 3
iundefsym: 3
nundefsym: 0
tocoff: 0
ntoc: 0
Expand All @@ -123,45 +151,57 @@ LoadCommands:
nextrel: 0
locreloff: 0
nlocrel: 0
- cmd: LC_ENCRYPTION_INFO_64
cmdsize: 24
cryptoff: 16384
cryptsize: 16384
cryptid: 0
pad: 0
- cmd: LC_LOAD_DYLINKER
cmdsize: 32
name: 12
Content: '/usr/lib/dyld'
ZeroPadBytes: 7
- cmd: LC_UUID
cmdsize: 24
uuid: 4C4C4447-5555-3144-A18A-01E9EB7E7D92
uuid: ADDA943C-657A-3A49-9580-168E17A40FFB
- cmd: LC_BUILD_VERSION
cmdsize: 32
platform: 1
minos: 983040
sdk: 983552
sdk: 984320
ntools: 1
Tools:
- tool: 4
version: 1310720
- tool: 3
version: 76481537
- cmd: LC_SOURCE_VERSION
cmdsize: 16
version: 0
- cmd: LC_MAIN
cmdsize: 24
entryoff: 16384
stacksize: 0
- cmd: LC_ENCRYPTION_INFO_64
cmdsize: 24
cryptoff: 16384
cryptsize: 16384
cryptid: 0
pad: 0
- cmd: LC_LOAD_DYLIB
cmdsize: 56
dylib:
name: 24
timestamp: 2
current_version: 88539136
compatibility_version: 65536
Content: '/usr/lib/libSystem.B.dylib'
ZeroPadBytes: 6
- cmd: LC_FUNCTION_STARTS
cmdsize: 16
dataoff: 32864
dataoff: 49272
datasize: 8
- cmd: LC_DATA_IN_CODE
cmdsize: 16
dataoff: 32872
dataoff: 49280
datasize: 0
- cmd: LC_CODE_SIGNATURE
cmdsize: 16
dataoff: 32944
datasize: 416
dataoff: 49376
datasize: 544
LinkEditData:
ExportTrie:
TerminalSize: 0
Expand All @@ -173,51 +213,67 @@ LinkEditData:
ImportName: ''
Children:
- TerminalSize: 0
NodeOffset: 5
NodeOffset: 25
Name: _
Flags: 0x0
Address: 0x0
Other: 0x0
ImportName: ''
Children:
- TerminalSize: 2
NodeOffset: 9
Name: _mh_execute_header
Flags: 0x0
Address: 0x0
Other: 0x0
ImportName: ''
- TerminalSize: 4
NodeOffset: 33
Name: main
NodeOffset: 13
Name: bar
Flags: 0x0
Address: 0x4000
Address: 0x8000
Other: 0x0
ImportName: ''
- TerminalSize: 2
NodeOffset: 39
Name: _mh_execute_header
- TerminalSize: 4
NodeOffset: 19
Name: main
Flags: 0x0
Address: 0x0
Address: 0x4000
Other: 0x0
ImportName: ''
NameList:
- n_strx: 2
n_type: 0xF
n_sect: 1
n_desc: 16
n_value: 4294967296
- n_strx: 22
n_type: 0xF
n_sect: 3
n_desc: 0
n_value: 4294983680
- n_strx: 8
n_value: 4295000064
- n_strx: 27
n_type: 0xF
n_sect: 1
n_desc: 16
n_value: 4294967296
n_desc: 0
n_value: 4294983680
StringTable:
- ' '
- _main
- __mh_execute_header
- _bar
- _main
- ''
- ''
- ''
- ''
- ''
- ''
- ''
FunctionStarts: [ 0x4000 ]
ChainedFixups: [ 0x0, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x30, 0x0,
0x0, 0x0, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
ChainedFixups: [ 0x0, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x34, 0x0,
0x0, 0x0, 0x34, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
...

Loading