diff options
author | Vladislav Khmelevsky <och95@yandex.ru> | 2023-02-10 17:09:03 +0400 |
---|---|---|
committer | Vladislav Khmelevsky <och95@yandex.ru> | 2023-03-13 13:37:28 +0400 |
commit | 7117af529ebd389a0eee1ed2683ba2ec8fc21449 (patch) | |
tree | f7a4811cc7d2bd88e9fe7a9e62a689b32f9b755f /bolt/include | |
parent | 23b0df72d272015f72800980dc029cca5bd991f0 (diff) | |
download | llvm-7117af529ebd389a0eee1ed2683ba2ec8fc21449.tar.gz |
[BOLT] Improve dynamic relocations support for CI
This patch fixes few problems with supporting dynamic relocations in CI.
1. After dynamic relocations and functions were read search for dynamic
relocations located in functions. Currently we expected them only to be
relative and only to be in constant island. Mark islands of such
functions to have dynamic relocations and create CI access symbol on the
relocation offset, so the BD would be created for such place.
2. During function disassemble and handling address reference for
constant island check if the referred external CI has dynamic
relocation. And if it has one we would continue to refer original CI
rather then creating a local copy.
3. After function disassembly stage mark function that has dynamic reloc
in CI as non-simple. We don't want such functions to be optimized, since
such passes as split function would create 2 copies of CI which we
unable to support currently.
4. During updating output values for BF search for BD located in CI and
update their output locations.
5. On dynamic relocation patching stage search for binary data located
on relocation offset. If it was moved use new relocation offset value
rather then an old one.
Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei
Differential Revision: https://reviews.llvm.org/D143748
Diffstat (limited to 'bolt/include')
-rw-r--r-- | bolt/include/bolt/Core/BinaryFunction.h | 26 | ||||
-rw-r--r-- | bolt/include/bolt/Rewrite/RewriteInstance.h | 12 |
2 files changed, 26 insertions, 12 deletions
diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h index 051a58547007..a4a5e213ac7a 100644 --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -167,6 +167,10 @@ public: /// List of relocations associated with data in the constant island std::map<uint64_t, Relocation> Relocations; + /// Set true if constant island contains dynamic relocations, which may + /// happen if binary is linked with -z notext option. + bool HasDynamicRelocations{false}; + /// Offsets in function that are data values in a constant island identified /// after disassembling std::map<uint64_t, MCSymbol *> Offsets; @@ -1945,6 +1949,28 @@ public: return Symbol; } + /// Support dynamic relocations in constant islands, which may happen if + /// binary is linked with -z notext option. + void markIslandDynamicRelocationAtAddress(uint64_t Address) { + if (!isInConstantIsland(Address)) { + errs() << "BOLT-ERROR: dynamic relocation found for text section at 0x" + << Twine::utohexstr(Address) << "\n"; + exit(1); + } + + // Mark island to have dynamic relocation + Islands->HasDynamicRelocations = true; + + // Create island access, so we would emit the label and + // move binary data during updateOutputValues, making us emit + // dynamic relocation with the right offset value. + getOrCreateIslandAccess(Address); + } + + bool hasDynamicRelocationAtIsland() const { + return !!(Islands && Islands->HasDynamicRelocations); + } + /// Called by an external function which wishes to emit references to constant /// island symbols of this function. We create a proxy for it, so we emit /// separate symbols when emitting our constant island on behalf of this other diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h index c8d5f03d085c..3f9fe5793078 100644 --- a/bolt/include/bolt/Rewrite/RewriteInstance.h +++ b/bolt/include/bolt/Rewrite/RewriteInstance.h @@ -547,18 +547,6 @@ private: ErrorOr<BinarySection &> LSDASection{std::errc::bad_address}; ErrorOr<BinarySection &> EHFrameSection{std::errc::bad_address}; - /// .got.plt sections. - /// - /// Contains jump slots (addresses) indirectly referenced by - /// instructions in .plt section. - ErrorOr<BinarySection &> GOTPLTSection{std::errc::bad_address}; - - /// .rela.plt section. - /// - /// Contains relocations against .got.plt. - ErrorOr<BinarySection &> RelaPLTSection{std::errc::bad_address}; - ErrorOr<BinarySection &> RelaDynSection{std::errc::bad_address}; - /// .note.gnu.build-id section. ErrorOr<BinarySection &> BuildIDSection{std::errc::bad_address}; |