diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h --- a/lld/COFF/Chunks.h +++ b/lld/COFF/Chunks.h @@ -486,7 +486,9 @@ class ImportThunkChunkARM : public ImportThunkChunk { public: - explicit ImportThunkChunkARM(Defined *s) : ImportThunkChunk(s) {} + explicit ImportThunkChunkARM(Defined *s) : ImportThunkChunk(s) { + setAlignment(2); + } size_t getSize() const override { return sizeof(importThunkARM); } void getBaserels(std::vector *res) override; void writeTo(uint8_t *buf) const override; @@ -494,14 +496,16 @@ class ImportThunkChunkARM64 : public ImportThunkChunk { public: - explicit ImportThunkChunkARM64(Defined *s) : ImportThunkChunk(s) {} + explicit ImportThunkChunkARM64(Defined *s) : ImportThunkChunk(s) { + setAlignment(4); + } size_t getSize() const override { return sizeof(importThunkARM64); } void writeTo(uint8_t *buf) const override; }; class RangeExtensionThunkARM : public NonSectionChunk { public: - explicit RangeExtensionThunkARM(Defined *t) : target(t) {} + explicit RangeExtensionThunkARM(Defined *t) : target(t) { setAlignment(2); } size_t getSize() const override; void writeTo(uint8_t *buf) const override; diff --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp --- a/lld/COFF/DLL.cpp +++ b/lld/COFF/DLL.cpp @@ -365,7 +365,9 @@ class ThunkChunkARM : public NonSectionChunk { public: - ThunkChunkARM(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) {} + ThunkChunkARM(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) { + setAlignment(2); + } size_t getSize() const override { return sizeof(thunkARM); } @@ -385,7 +387,9 @@ class TailMergeChunkARM : public NonSectionChunk { public: - TailMergeChunkARM(Chunk *d, Defined *h) : desc(d), helper(h) {} + TailMergeChunkARM(Chunk *d, Defined *h) : desc(d), helper(h) { + setAlignment(2); + } size_t getSize() const override { return sizeof(tailMergeARM); } @@ -405,7 +409,9 @@ class ThunkChunkARM64 : public NonSectionChunk { public: - ThunkChunkARM64(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) {} + ThunkChunkARM64(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) { + setAlignment(4); + } size_t getSize() const override { return sizeof(thunkARM64); } @@ -422,7 +428,9 @@ class TailMergeChunkARM64 : public NonSectionChunk { public: - TailMergeChunkARM64(Chunk *d, Defined *h) : desc(d), helper(h) {} + TailMergeChunkARM64(Chunk *d, Defined *h) : desc(d), helper(h) { + setAlignment(4); + } size_t getSize() const override { return sizeof(tailMergeARM64); } diff --git a/lld/test/COFF/arm64-import2.test b/lld/test/COFF/arm64-import2.test --- a/lld/test/COFF/arm64-import2.test +++ b/lld/test/COFF/arm64-import2.test @@ -11,18 +11,20 @@ # BEFORE: 0: 00 00 00 94 bl 0x0 # BEFORE: 4: 00 00 00 94 bl 0x4 # BEFORE: 8: c0 03 5f d6 ret +# BEFORE: c: ff # AFTER: Disassembly of section .text: # AFTER-EMPTY: -# AFTER: 140001000: 03 00 00 94 bl 0x14000100c -# AFTER: 140001004: 05 00 00 94 bl 0x140001018 +# AFTER: 140001000: 04 00 00 94 bl 0x140001010 +# AFTER: 140001004: 06 00 00 94 bl 0x14000101c # AFTER: 140001008: c0 03 5f d6 ret -# AFTER: 14000100c: 10 00 00 b0 adrp x16, #4096 -# AFTER: 140001010: 10 32 40 f9 ldr x16, [x16, #96] -# AFTER: 140001014: 00 02 1f d6 br x16 -# AFTER: 140001018: 10 00 00 b0 adrp x16, #4096 -# AFTER: 14000101c: 10 3a 40 f9 ldr x16, [x16, #112] -# AFTER: 140001020: 00 02 1f d6 br x16 +# AFTER: 14000100c: ff cc cc cc +# AFTER: 140001010: 10 00 00 b0 adrp x16, #4096 +# AFTER: 140001014: 10 32 40 f9 ldr x16, [x16, #96] +# AFTER: 140001018: 00 02 1f d6 br x16 +# AFTER: 14000101c: 10 00 00 b0 adrp x16, #4096 +# AFTER: 140001020: 10 3a 40 f9 ldr x16, [x16, #112] +# AFTER: 140001024: 00 02 1f d6 br x16 # IMPORTS: Import { # IMPORTS: Name: library.dll @@ -45,7 +47,7 @@ - Name: .text Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] Alignment: 4 - SectionData: 0000009400000094C0035FD6 + SectionData: 0000009400000094C0035FD6FF Relocations: - VirtualAddress: 0 SymbolName: function