[llvm] ddc0908 - [ObjCopy][NFC] Refactor handling of linkedit_data_command

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 9 18:23:53 PDT 2022


Author: Alexander Shaposhnikov
Date: 2022-04-10T01:20:45Z
New Revision: ddc09089496ec0a0cdc73ad50b388f7e11cc401a

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

LOG: [ObjCopy][NFC] Refactor handling of linkedit_data_command

Added: 
    

Modified: 
    llvm/lib/ObjCopy/MachO/MachOWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
index d5d7c0275d351..cdaffe3e171e0 100644
--- a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
@@ -94,64 +94,18 @@ size_t MachOWriter::totalSize() const {
                      sizeof(uint32_t) * O.IndirectSymTable.Symbols.size());
   }
 
-  if (O.CodeSignatureCommandIndex) {
-    const MachO::linkedit_data_command &LinkEditDataCommand =
-        O.LoadCommands[*O.CodeSignatureCommandIndex]
-            .MachOLoadCommand.linkedit_data_command_data;
-    if (LinkEditDataCommand.dataoff)
-      Ends.push_back(LinkEditDataCommand.dataoff +
-                     LinkEditDataCommand.datasize);
-  }
-
-  if (O.DataInCodeCommandIndex) {
-    const MachO::linkedit_data_command &LinkEditDataCommand =
-        O.LoadCommands[*O.DataInCodeCommandIndex]
-            .MachOLoadCommand.linkedit_data_command_data;
-
-    if (LinkEditDataCommand.dataoff)
-      Ends.push_back(LinkEditDataCommand.dataoff +
-                     LinkEditDataCommand.datasize);
-  }
-
-  if (O.LinkerOptimizationHintCommandIndex) {
-    const MachO::linkedit_data_command &LinkEditDataCommand =
-        O.LoadCommands[*O.LinkerOptimizationHintCommandIndex]
-            .MachOLoadCommand.linkedit_data_command_data;
-
-    if (LinkEditDataCommand.dataoff)
-      Ends.push_back(LinkEditDataCommand.dataoff +
-                     LinkEditDataCommand.datasize);
-  }
-
-  if (O.FunctionStartsCommandIndex) {
-    const MachO::linkedit_data_command &LinkEditDataCommand =
-        O.LoadCommands[*O.FunctionStartsCommandIndex]
-            .MachOLoadCommand.linkedit_data_command_data;
-
-    if (LinkEditDataCommand.dataoff)
-      Ends.push_back(LinkEditDataCommand.dataoff +
-                     LinkEditDataCommand.datasize);
-  }
-
-  if (O.ChainedFixupsCommandIndex) {
-    const MachO::linkedit_data_command &LinkEditDataCommand =
-        O.LoadCommands[*O.ChainedFixupsCommandIndex]
-            .MachOLoadCommand.linkedit_data_command_data;
-
-    if (LinkEditDataCommand.dataoff)
-      Ends.push_back(LinkEditDataCommand.dataoff +
-                     LinkEditDataCommand.datasize);
-  }
-
-  if (O.ExportsTrieCommandIndex) {
-    const MachO::linkedit_data_command &LinkEditDataCommand =
-        O.LoadCommands[*O.ExportsTrieCommandIndex]
-            .MachOLoadCommand.linkedit_data_command_data;
-
-    if (LinkEditDataCommand.dataoff)
-      Ends.push_back(LinkEditDataCommand.dataoff +
-                     LinkEditDataCommand.datasize);
-  }
+  for (Optional<size_t> LinkEditDataCommandIndex :
+       {O.CodeSignatureCommandIndex, O.DataInCodeCommandIndex,
+        O.LinkerOptimizationHintCommandIndex, O.FunctionStartsCommandIndex,
+        O.ChainedFixupsCommandIndex, O.ExportsTrieCommandIndex})
+    if (LinkEditDataCommandIndex) {
+      const MachO::linkedit_data_command &LinkEditDataCommand =
+          O.LoadCommands[*LinkEditDataCommandIndex]
+              .MachOLoadCommand.linkedit_data_command_data;
+      if (LinkEditDataCommand.dataoff)
+        Ends.push_back(LinkEditDataCommand.dataoff +
+                       LinkEditDataCommand.datasize);
+    }
 
   // Otherwise, use the last section / reloction.
   for (const LoadCommand &LC : O.LoadCommands)


        


More information about the llvm-commits mailing list