[lld-macho] Have all load commands aligned to the word size
authorJez Ng <jezng@fb.com>
Wed, 11 Jan 2023 07:23:15 +0000 (02:23 -0500)
committerJez Ng <jezng@fb.com>
Wed, 25 Jan 2023 01:11:04 +0000 (20:11 -0500)
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

lld/MachO/Writer.cpp

index b88f99c..a099206 100644 (file)
@@ -328,7 +328,8 @@ public:
   }
 
   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 {