[llvm] c966ed8 - [llvm-objcopy][MachO] Fix cmdsize of LC_RPATH

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 11 20:34:38 PDT 2020


Author: Alexander Shaposhnikov
Date: 2020-06-11T19:55:04-07:00
New Revision: c966ed8dc7ce7629c4371314e5ec2119b84e852c

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

LOG: [llvm-objcopy][MachO] Fix cmdsize of LC_RPATH

Fix the calculation of the field cmdsize (in the function buildRPathLoadCommand)
to account for the null byte terminator.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81575

Added: 
    

Modified: 
    llvm/test/tools/llvm-objcopy/MachO/install-name-tool-add-rpath.test
    llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-add-rpath.test b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-add-rpath.test
index 61aca209315a..1435c6b744c8 100644
--- a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-add-rpath.test
+++ b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-add-rpath.test
@@ -21,3 +21,12 @@
 # RUN: | FileCheck --check-prefix=NO-INPUT %s
 
 # NO-INPUT: no input file specified
+
+## Check that cmdsize accounts for NULL terminator.
+# RUN: yaml2obj %p/Inputs/x86_64.yaml -o %t.x86_64
+# RUN: llvm-install-name-tool -add_rpath abcd %t.x86_64
+# RUN: llvm-objdump -p %t.x86_64 | FileCheck %s --check-prefix=RPATH-SIZE
+
+# RPATH-SIZE: cmd LC_RPATH
+# RPATH-SIZE-NEXT: cmdsize 24
+# RPATH-SIZE-NEXT: path abcd

diff  --git a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
index d6889c1ac6e0..17d84549544b 100644
--- a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
@@ -87,7 +87,7 @@ static LoadCommand buildRPathLoadCommand(StringRef Path) {
   MachO::rpath_command RPathLC;
   RPathLC.cmd = MachO::LC_RPATH;
   RPathLC.path = sizeof(MachO::rpath_command);
-  RPathLC.cmdsize = alignTo(sizeof(MachO::rpath_command) + Path.size(), 8);
+  RPathLC.cmdsize = alignTo(sizeof(MachO::rpath_command) + Path.size() + 1, 8);
   LC.MachOLoadCommand.rpath_command_data = RPathLC;
   LC.Payload.assign(RPathLC.cmdsize - sizeof(MachO::rpath_command), 0);
   std::copy(Path.begin(), Path.end(), LC.Payload.begin());


        


More information about the llvm-commits mailing list