[llvm] [llvm-objcopy] Always update indirectsymoff in MachO (#117723) (PR #117726)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 07:34:07 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-binary-utilities

Author: Richard Dzenis (RIscRIpt)

<details>
<summary>Changes</summary>

Let's say we've run llvm-strip over some MachO. The resulting MachO became smaller and there are no indirect symbols anymore.

Then according to previous code we would not update indirectsymoff field. This would lead to `MachOWriter::totalSize()` report size that is larger than the new MachO. As a result we would get MachO that has zero bytes past contents of the very last load command.

Codesign has a strict check that size of MachO file must be equal to

    lastLoadCommand.offset + lastLoadCommand.size

If this is not satisfied codesign reports the following error

    main executable failed strict validation

---
Full diff: https://github.com/llvm/llvm-project/pull/117726.diff


1 Files Affected:

- (modified) llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp (+4-5) 


``````````diff
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index a3d4ba3a94f7ac..551ff4501a66fb 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -361,11 +361,10 @@ Error MachOLayoutBuilder::layoutTail(uint64_t Offset) {
         return createStringError(llvm::errc::not_supported,
                                  "shared library is not yet supported");
 
-      if (!O.IndirectSymTable.Symbols.empty()) {
-        MLC.dysymtab_command_data.indirectsymoff = StartOfIndirectSymbols;
-        MLC.dysymtab_command_data.nindirectsyms =
-            O.IndirectSymTable.Symbols.size();
-      }
+      MLC.dysymtab_command_data.nindirectsyms =
+          O.IndirectSymTable.Symbols.size();
+      MLC.dysymtab_command_data.indirectsymoff =
+          O.IndirectSymTable.Symbols.empty() ? 0 : StartOfIndirectSymbols;
 
       updateDySymTab(MLC);
       break;

``````````

</details>


https://github.com/llvm/llvm-project/pull/117726


More information about the llvm-commits mailing list