From ddc09089496ec0a0cdc73ad50b388f7e11cc401a Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Sun, 10 Apr 2022 01:20:45 +0000 Subject: [PATCH] [ObjCopy][NFC] Refactor handling of linkedit_data_command --- llvm/lib/ObjCopy/MachO/MachOWriter.cpp | 70 +++++--------------------- 1 file changed, 12 insertions(+), 58 deletions(-) diff --git a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp index d5d7c0275d35..cdaffe3e171e 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 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)