[llvm] 4d87344 - [ObjCopy][NFC] Refactor handling of linkedit_data_command in MachOWriter
Alexander Shaposhnikov via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 9 19:10:02 PDT 2022
Author: Alexander Shaposhnikov
Date: 2022-04-10T02:09:11Z
New Revision: 4d87344e8c235b8ce6c15d148457075630e8169f
URL: https://github.com/llvm/llvm-project/commit/4d87344e8c235b8ce6c15d148457075630e8169f
DIFF: https://github.com/llvm/llvm-project/commit/4d87344e8c235b8ce6c15d148457075630e8169f.diff
LOG: [ObjCopy][NFC] Refactor handling of linkedit_data_command in MachOWriter
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 cdaffe3e171e0..307b2ac0b70ad 100644
--- a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
@@ -612,64 +612,26 @@ void MachOWriter::writeTail() {
&MachOWriter::writeIndirectSymbolTable);
}
- if (O.CodeSignatureCommandIndex) {
- const MachO::linkedit_data_command &LinkEditDataCommand =
- O.LoadCommands[*O.CodeSignatureCommandIndex]
- .MachOLoadCommand.linkedit_data_command_data;
-
- if (LinkEditDataCommand.dataoff)
- Queue.emplace_back(LinkEditDataCommand.dataoff,
- &MachOWriter::writeCodeSignatureData);
- }
-
- if (O.DataInCodeCommandIndex) {
- const MachO::linkedit_data_command &LinkEditDataCommand =
- O.LoadCommands[*O.DataInCodeCommandIndex]
- .MachOLoadCommand.linkedit_data_command_data;
-
- if (LinkEditDataCommand.dataoff)
- Queue.emplace_back(LinkEditDataCommand.dataoff,
- &MachOWriter::writeDataInCodeData);
- }
-
- if (O.LinkerOptimizationHintCommandIndex) {
- const MachO::linkedit_data_command &LinkEditDataCommand =
- O.LoadCommands[*O.LinkerOptimizationHintCommandIndex]
- .MachOLoadCommand.linkedit_data_command_data;
-
- if (LinkEditDataCommand.dataoff)
- Queue.emplace_back(LinkEditDataCommand.dataoff,
- &MachOWriter::writeLinkerOptimizationHint);
- }
-
- if (O.FunctionStartsCommandIndex) {
- const MachO::linkedit_data_command &LinkEditDataCommand =
- O.LoadCommands[*O.FunctionStartsCommandIndex]
- .MachOLoadCommand.linkedit_data_command_data;
-
- if (LinkEditDataCommand.dataoff)
- Queue.emplace_back(LinkEditDataCommand.dataoff,
- &MachOWriter::writeFunctionStartsData);
- }
-
- if (O.ChainedFixupsCommandIndex) {
- const MachO::linkedit_data_command &LinkEditDataCommand =
- O.LoadCommands[*O.ChainedFixupsCommandIndex]
- .MachOLoadCommand.linkedit_data_command_data;
-
- if (LinkEditDataCommand.dataoff)
- Queue.emplace_back(LinkEditDataCommand.dataoff,
- &MachOWriter::writeChainedFixupsData);
- }
-
- if (O.ExportsTrieCommandIndex) {
- const MachO::linkedit_data_command &LinkEditDataCommand =
- O.LoadCommands[*O.ExportsTrieCommandIndex]
- .MachOLoadCommand.linkedit_data_command_data;
-
- if (LinkEditDataCommand.dataoff)
- Queue.emplace_back(LinkEditDataCommand.dataoff,
- &MachOWriter::writeExportsTrieData);
+ std::initializer_list<std::pair<Optional<size_t>, WriteHandlerType>>
+ LinkEditDataCommandWriters = {
+ {O.CodeSignatureCommandIndex, &MachOWriter::writeCodeSignatureData},
+ {O.DataInCodeCommandIndex, &MachOWriter::writeDataInCodeData},
+ {O.LinkerOptimizationHintCommandIndex,
+ &MachOWriter::writeLinkerOptimizationHint},
+ {O.FunctionStartsCommandIndex, &MachOWriter::writeFunctionStartsData},
+ {O.ChainedFixupsCommandIndex, &MachOWriter::writeChainedFixupsData},
+ {O.ExportsTrieCommandIndex, &MachOWriter::writeExportsTrieData}};
+ for (const auto &W : LinkEditDataCommandWriters) {
+ Optional<size_t> LinkEditDataCommandIndex;
+ WriteHandlerType WriteHandler;
+ std::tie(LinkEditDataCommandIndex, WriteHandler) = W;
+ if (LinkEditDataCommandIndex) {
+ const MachO::linkedit_data_command &LinkEditDataCommand =
+ O.LoadCommands[*LinkEditDataCommandIndex]
+ .MachOLoadCommand.linkedit_data_command_data;
+ if (LinkEditDataCommand.dataoff)
+ Queue.emplace_back(LinkEditDataCommand.dataoff, WriteHandler);
+ }
}
llvm::sort(Queue, [](const WriteOperation &LHS, const WriteOperation &RHS) {
More information about the llvm-commits
mailing list