diff options
| author | Nick Kledzik <kledzik@apple.com> | 2014-11-12 23:34:23 +0000 |
|---|---|---|
| committer | Nick Kledzik <kledzik@apple.com> | 2014-11-12 23:34:23 +0000 |
| commit | 8870ad24399680811045a34d9b5438ebc4d812f8 (patch) | |
| tree | 000fd735b4824b7c48d4f33d5ef8cba392167aa5 /lld/lib/ReaderWriter/MachO/GOTPass.cpp | |
| parent | e8356339cda10ea094eb9d57af80e1f53532af3f (diff) | |
| download | bcm5719-llvm-8870ad24399680811045a34d9b5438ebc4d812f8.tar.gz bcm5719-llvm-8870ad24399680811045a34d9b5438ebc4d812f8.zip | |
[mach-o] Sort GOT entries by name to make links reproducible
The GOT slots were being laid out in a random order by the GOTPass which
caused randomness in the output file.
Note: With this change lld now bootstraps on darwin. That is:
1) link lld using system linker to make lld.1
2) link lld using lld.1 to make lld.2
3) link lld using lld.2 to make lld.3
Now lld.2 and lld.3 are identical.
llvm-svn: 221831
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/GOTPass.cpp')
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/GOTPass.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lld/lib/ReaderWriter/MachO/GOTPass.cpp b/lld/lib/ReaderWriter/MachO/GOTPass.cpp index b86160efc24..b5381115c01 100644 --- a/lld/lib/ReaderWriter/MachO/GOTPass.cpp +++ b/lld/lib/ReaderWriter/MachO/GOTPass.cpp @@ -52,8 +52,8 @@ namespace mach_o { // class GOTEntryAtom : public SimpleDefinedAtom { public: - GOTEntryAtom(const File &file, bool is64) - : SimpleDefinedAtom(file), _is64(is64) { } + GOTEntryAtom(const File &file, bool is64, StringRef name) + : SimpleDefinedAtom(file), _is64(is64), _name(name) { } ContentType contentType() const override { return DefinedAtom::typeGOT; @@ -77,8 +77,13 @@ public: return llvm::makeArrayRef(zeros, size()); } + StringRef slotName() const { + return _name; + } + private: const bool _is64; + StringRef _name; }; @@ -116,9 +121,17 @@ private: } } - // add all created GOT Atoms to master file + // Sort and add all created GOT Atoms to master file + std::vector<const GOTEntryAtom *> entries; + entries.reserve(_targetToGOT.size()); for (auto &it : _targetToGOT) - mergedFile->addAtom(*it.second); + entries.push_back(it.second); + std::sort(entries.begin(), entries.end(), + [](const GOTEntryAtom *left, const GOTEntryAtom *right) { + return (left->slotName().compare(right->slotName()) < 0); + }); + for (const GOTEntryAtom *slot : entries) + mergedFile->addAtom(*slot); } bool shouldReplaceTargetWithGOTAtom(const Atom *target, bool canBypassGOT) { @@ -142,7 +155,7 @@ private: auto pos = _targetToGOT.find(target); if (pos == _targetToGOT.end()) { GOTEntryAtom *gotEntry = new (_file.allocator()) - GOTEntryAtom(_file, _context.is64Bit()); + GOTEntryAtom(_file, _context.is64Bit(), target->name()); _targetToGOT[target] = gotEntry; const ArchHandler::ReferenceInfo &nlInfo = _archHandler.stubInfo(). nonLazyPointerReferenceToBinder; |

