[lld] 4f2a461 - [lld-macho] Have all load commands aligned to the word size

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 17:11:12 PST 2023


Author: Jez Ng
Date: 2023-01-24T20:11:04-05:00
New Revision: 4f2a4617936fd73a5fe18f8e12a02b0975ce7643

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

LOG: [lld-macho] Have all load commands aligned to the word size

This is what ld64 does, and also what we already do for most of the
other load commands. I'm not aware of a good way to test this, but I
don't think it really matters.

Differential Revision: https://reviews.llvm.org/D141462

Added: 
    

Modified: 
    lld/MachO/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index b88f99c920f6..a09920687c55 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -328,7 +328,8 @@ class LCDylib final : public LoadCommand {
   }
 
   uint32_t getSize() const override {
-    return alignTo(sizeof(dylib_command) + path.size() + 1, 8);
+    return alignToPowerOf2(sizeof(dylib_command) + path.size() + 1,
+                           target->wordSize);
   }
 
   void writeTo(uint8_t *buf) const override {
@@ -362,7 +363,8 @@ uint32_t LCDylib::instanceCount = 0;
 class LCLoadDylinker final : public LoadCommand {
 public:
   uint32_t getSize() const override {
-    return alignTo(sizeof(dylinker_command) + path.size() + 1, 8);
+    return alignToPowerOf2(sizeof(dylinker_command) + path.size() + 1,
+                           target->wordSize);
   }
 
   void writeTo(uint8_t *buf) const override {


        


More information about the llvm-commits mailing list