[llvm-branch-commits] [llvm] release/20.x: [objcopy][MachO] Revert special handling of encryptable binaries (#144058) (PR #144449)
https://github.com/drodriguez approved this pull request. https://github.com/llvm/llvm-project/pull/19 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [objcopy][MachO] Revert special handling of encryptable binaries (#144058) (PR #144449)
llvmbot wrote: @dianqk What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/19 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [objcopy][MachO] Revert special handling of encryptable binaries (#144058) (PR #144449)
https://github.com/llvmbot created
https://github.com/llvm/llvm-project/pull/19
Backport a0662ceba83cf8782da4047b8ee6d175591f168f
Requested by: @dianqk
>From 5016e20c7002d5f93e0843129f4a4679ce4c088b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez=20Troiti=C3=B1o?=
Date: Mon, 16 Jun 2025 12:06:25 -0700
Subject: [PATCH] [objcopy][MachO] Revert special handling of encryptable
binaries (#144058)
Code originally added in #120995 and later corrected in #130517 but
apparently still not correct according to #141494 and
rust-lang/rust#141913.
Revert the special handling because the test written in #120995 and
#130517 still passes without those changes. Kept the test and improved
it with a `__DATA` section to keep the current behaviour checked in case
other changes modify the behaviour and break this edge case.
(cherry picked from commit a0662ceba83cf8782da4047b8ee6d175591f168f)
---
llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp | 8 -
llvm/lib/ObjCopy/MachO/MachOObject.cpp| 4 -
llvm/lib/ObjCopy/MachO/MachOObject.h | 3 -
llvm/lib/ObjCopy/MachO/MachOReader.cpp| 4 -
.../MachO/strip-with-encryption-info.test | 156 --
5 files changed, 106 insertions(+), 69 deletions(-)
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index 8ecd669e67178..93bc6631e64c8 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -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;
@@ -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);
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
index e0819d89d24ff..8d2c02dc37c99 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
@@ -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;
}
}
}
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.h
b/llvm/lib/ObjCopy/MachO/MachOObject.h
index 79eb0133c2802..a454c4f502fd6 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.h
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.h
@@ -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 TextSegmentCommandIndex;
- /// The index of the LC_ENCRYPTION_INFO or LC_ENCRYPTION_INFO_64 load command
- /// if present.
- std::optional EncryptionInfoCommandIndex;
BumpPtrAllocator Alloc;
StringSaver NewSectionsContents;
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index ef0e0262f9395..2b344f36d8e78 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -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:
\
diff --git a/llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
b/llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
index 2b2bd670613de..d6f6fe10d88c2 100644
--- a/llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
+++ b/llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
@@ -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) { r
[llvm-branch-commits] [llvm] release/20.x: [objcopy][MachO] Revert special handling of encryptable binaries (#144058) (PR #144449)
llvmbot wrote:
@llvm/pr-subscribers-llvm-binary-utilities
Author: None (llvmbot)
Changes
Backport a0662ceba83cf8782da4047b8ee6d175591f168f
Requested by: @dianqk
---
Full diff: https://github.com/llvm/llvm-project/pull/19.diff
5 Files Affected:
- (modified) llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp (-8)
- (modified) llvm/lib/ObjCopy/MachO/MachOObject.cpp (-4)
- (modified) llvm/lib/ObjCopy/MachO/MachOObject.h (-3)
- (modified) llvm/lib/ObjCopy/MachO/MachOReader.cpp (-4)
- (modified) llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
(+106-50)
``diff
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index 8ecd669e67178..93bc6631e64c8 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -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;
@@ -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);
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
index e0819d89d24ff..8d2c02dc37c99 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
@@ -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;
}
}
}
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.h
b/llvm/lib/ObjCopy/MachO/MachOObject.h
index 79eb0133c2802..a454c4f502fd6 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.h
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.h
@@ -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 TextSegmentCommandIndex;
- /// The index of the LC_ENCRYPTION_INFO or LC_ENCRYPTION_INFO_64 load command
- /// if present.
- std::optional EncryptionInfoCommandIndex;
BumpPtrAllocator Alloc;
StringSaver NewSectionsContents;
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index ef0e0262f9395..2b344f36d8e78 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -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:
\
diff --git a/llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
b/llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
index 2b2bd670613de..d6f6fe10d88c2 100644
--- a/llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
+++ b/llvm/test/tools/llvm-objcopy/MachO/strip-with-encryption-info.test
@@ -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).
@@ -26,8 +30,8 @@ FileHeader:
cputype: 0x10C
cpusubtype: 0x0
filetype:0x2
- ncmds: 15
- sizeofcmds: 696
+ ncmds: 18
+ sizeofcmds: 920
flags: 0x200085
reserved:0x0
LoadCommands:
@@ -69,7 +73,7 @@ LoadCommands:
- sectname:__unwind_info
segname: __TEXT
addr:0x14020
-size:41
[llvm-branch-commits] [llvm] release/20.x: [objcopy][MachO] Revert special handling of encryptable binaries (#144058) (PR #144449)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/19 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
