[llvm] d17d50e - [llvm-objcopy][MachO] Copy LC_ENCRYPT_INFO/LC_ENCRYPT_INFO_64 load commands

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 20 16:39:15 PDT 2020


Author: Alexander Shaposhnikov
Date: 2020-04-20T16:34:46-07:00
New Revision: d17d50ebc6ee5f0bda1db303b7da0a27bed5c7c1

URL: https://github.com/llvm/llvm-project/commit/d17d50ebc6ee5f0bda1db303b7da0a27bed5c7c1
DIFF: https://github.com/llvm/llvm-project/commit/d17d50ebc6ee5f0bda1db303b7da0a27bed5c7c1.diff

LOG: [llvm-objcopy][MachO] Copy LC_ENCRYPT_INFO/LC_ENCRYPT_INFO_64 load commands

Copy LC_ENCRYPT_INFO/LC_ENCRYPT_INFO_64 load commands.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78339

Added: 
    llvm/test/tools/llvm-objcopy/MachO/encrypt_info_64_lc.test
    llvm/test/tools/llvm-objcopy/MachO/encrypt_info_lc.test

Modified: 
    llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objcopy/MachO/encrypt_info_64_lc.test b/llvm/test/tools/llvm-objcopy/MachO/encrypt_info_64_lc.test
new file mode 100644
index 000000000000..acbcc4edcd49
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/MachO/encrypt_info_64_lc.test
@@ -0,0 +1,22 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objcopy %t %t.copy
+# RUN: cmp %t %t.copy
+
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x0100000C
+  cpusubtype:      0x00000000
+  filetype:        0x00000002
+  ncmds:           1
+  sizeofcmds:      24
+  flags:           0x00002000
+  reserved:        0x00000000
+LoadCommands:
+  - cmd:             LC_ENCRYPTION_INFO_64
+    cmdsize:         24
+    cryptoff:        0
+    cryptsize:       0
+    cryptid:         0
+    pad:             0
+...

diff  --git a/llvm/test/tools/llvm-objcopy/MachO/encrypt_info_lc.test b/llvm/test/tools/llvm-objcopy/MachO/encrypt_info_lc.test
new file mode 100644
index 000000000000..fbe0adaef6a8
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/MachO/encrypt_info_lc.test
@@ -0,0 +1,20 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objcopy %t %t.copy
+# RUN: cmp %t %t.copy
+
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACE
+  cputype:         0x0000000C
+  cpusubtype:      0x00000009
+  filetype:        0x00000001
+  ncmds:           1
+  sizeofcmds:      20
+  flags:           0x00002000
+LoadCommands:
+  - cmd:             LC_ENCRYPTION_INFO
+    cmdsize:         20
+    cryptoff:        0
+    cryptsize:       0
+    cryptid:         0
+...

diff  --git a/llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp b/llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp
index 9ac02eb213b7..102482e5005c 100644
--- a/llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp
@@ -315,6 +315,19 @@ Error MachOLayoutBuilder::layoutTail(uint64_t Offset) {
           O.Exports.Trie.empty() ? 0 : StartOfExportTrie;
       MLC.dyld_info_command_data.export_size = O.Exports.Trie.size();
       break;
+    // Note that LC_ENCRYPTION_INFO.cryptoff despite its name and the comment in
+    // <mach-o/loader.h> is not an offset in the binary file, instead, it is a
+    // relative virtual address. At the moment modification of the __TEXT
+    // segment of executables isn't supported anyway (e.g. data in code entries
+    // are not recalculated). Moreover, in general
+    // LC_ENCRYPT_INFO/LC_ENCRYPTION_INFO_64 are nontrivial to update because
+    // without making additional assumptions (e.g. that the entire __TEXT
+    // segment should be encrypted) we do not know how to recalculate the
+    // boundaries of the encrypted part. For now just copy over these load
+    // commands until we encounter a real world usecase where
+    // LC_ENCRYPT_INFO/LC_ENCRYPTION_INFO_64 need to be adjusted.
+    case MachO::LC_ENCRYPTION_INFO:
+    case MachO::LC_ENCRYPTION_INFO_64:
     case MachO::LC_LOAD_DYLINKER:
     case MachO::LC_MAIN:
     case MachO::LC_RPATH:


        


More information about the llvm-commits mailing list