From 2ed3bf9527b59d2f0bf535a8572484f9ccd688f6 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 29 Oct 2015 16:50:26 +0000 Subject: [PATCH] [lld][MachO] Make sure LC_RPATH command size is a multiple of the pointer size. llvm-svn: 251637 --- .../ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp | 4 ++-- lld/test/mach-o/rpath.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp index bbf62de6102a..d1577556e1ea 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp @@ -429,7 +429,7 @@ uint32_t MachOFileLayout::loadCommandsSize(uint32_t &count) { // Add LC_RPATH for (const StringRef &path : _file.rpaths) { - size += sizeof(rpath_command) + pointerAlign(path.size()+1); + size += pointerAlign(sizeof(rpath_command) + path.size() + 1); ++count; } @@ -855,7 +855,7 @@ std::error_code MachOFileLayout::writeLoadCommands() { // Add LC_RPATH for (const StringRef &path : _file.rpaths) { rpath_command *rpc = reinterpret_cast(lc); - uint32_t size = sizeof(rpath_command) + pointerAlign(path.size()+1); + uint32_t size = pointerAlign(sizeof(rpath_command) + path.size() + 1); rpc->cmd = LC_RPATH; rpc->cmdsize = size; rpc->path = sizeof(rpath_command); // offset diff --git a/lld/test/mach-o/rpath.yaml b/lld/test/mach-o/rpath.yaml index f0b5f718c15a..ce1234d4c78f 100644 --- a/lld/test/mach-o/rpath.yaml +++ b/lld/test/mach-o/rpath.yaml @@ -34,5 +34,5 @@ global-symbols: # CHECK-BINARY-WRITE: cmd LC_RPATH -# CHECK-BINARY-WRITE-NEXT: cmdsize 44 +# CHECK-BINARY-WRITE-NEXT: cmdsize 40 # CHECK-BINARY-WRITE-NEXT: path @loader_path/../Frameworks (offset 12)