diff options
author | Jean-Daniel Dupas <devlists@shadowlab.org> | 2014-12-18 21:33:38 +0000 |
---|---|---|
committer | Jean-Daniel Dupas <devlists@shadowlab.org> | 2014-12-18 21:33:38 +0000 |
commit | 23dd15e26d81c3230e7dc7b184a5dc8e37e8f3bb (patch) | |
tree | b01942ecb8283f26d86804fb8a8282c310166503 /lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp | |
parent | f27ae736175a3cc339af15ffc8ad3cb518224c0c (diff) | |
download | bcm5719-llvm-23dd15e26d81c3230e7dc7b184a5dc8e37e8f3bb.tar.gz bcm5719-llvm-23dd15e26d81c3230e7dc7b184a5dc8e37e8f3bb.zip |
[macho] -rpath support
Summary:
Work on adding -rpath support to the mach-o linker.
This patch is based on the ld64 behavior for the command line option validation.
It includes a basic test to check that the LC_RPATH load commands are properly generated when that option is used.
It also add LC_RPATH support to the binary reader, but I don't know how to test it though.
Reviewers: kledzik
Subscribers: llvm-commits
Projects: #lld
Differential Revision: http://reviews.llvm.org/D6724
llvm-svn: 224544
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp')
-rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp index d931865408f..a3542c4fc50 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp @@ -428,6 +428,12 @@ uint32_t MachOFileLayout::loadCommandsSize(uint32_t &count) { ++count; } + // Add LC_RPATH + for (const StringRef &path : _file.rpaths) { + size += sizeof(rpath_command) + pointerAlign(path.size()+1); + ++count; + } + // Add LC_DATA_IN_CODE if needed if (!_file.dataInCode.empty()) { size += sizeof(linkedit_data_command); @@ -844,6 +850,21 @@ std::error_code MachOFileLayout::writeLoadCommands() { lc[sizeof(dylib_command)+dep.path.size()] = '\0'; lc += size; } + + // Add LC_RPATH + for (const StringRef &path : _file.rpaths) { + rpath_command *rpc = reinterpret_cast<rpath_command *>(lc); + uint32_t size = sizeof(rpath_command) + pointerAlign(path.size()+1); + rpc->cmd = LC_RPATH; + rpc->cmdsize = size; + rpc->path = sizeof(rpath_command); // offset + if (_swap) + swapStruct(*rpc); + memcpy(lc+sizeof(rpath_command), path.begin(), path.size()); + lc[sizeof(rpath_command)+path.size()] = '\0'; + lc += size; + } + // Add LC_DATA_IN_CODE if needed. if (_dataInCodeSize != 0) { linkedit_data_command* dl = reinterpret_cast<linkedit_data_command*>(lc); |