[BOLT][AARCH64] Skip R_AARCH64_LD_PREL_LO19 relocation
authorVladislav Khmelevsky <och95@yandex.ru>
Thu, 9 Jun 2022 16:00:24 +0000 (19:00 +0300)
committerVladislav Khmelevsky <och95@yandex.ru>
Mon, 13 Jun 2022 12:40:06 +0000 (15:40 +0300)
Supress failed to analyze relocations warning for R_AARCH64_LD_PREL_LO19
relocation. This relocation is mostly used to get value stored in CI and
we don't process it since we are caluclating target address using the
instruction value in evaluateMemOperandTarget().

Differential Revision: https://reviews.llvm.org/D127413

bolt/include/bolt/Core/Relocation.h
bolt/lib/Core/Relocation.cpp
bolt/lib/Rewrite/RewriteInstance.cpp

index 9a280bc..08bb02c 100644 (file)
@@ -55,7 +55,10 @@ struct Relocation {
   /// Return size of this relocation.
   size_t getSize() const { return getSizeForType(Type); }
 
-  /// Handle special cases when relocation should not be processed by bolt
+  /// Skip relocations that we don't want to handle in BOLT
+  static bool skipRelocationType(uint64_t Type);
+
+  /// Handle special cases when relocation should not be processed by BOLT
   static bool skipRelocationProcess(uint64_t Type, uint64_t Contents);
 
   // Adjust value depending on relocation type (make it PC relative or not)
index c0fe63e..f989ab1 100644 (file)
@@ -165,6 +165,12 @@ size_t getSizeForTypeAArch64(uint64_t Type) {
   }
 }
 
+bool skipRelocationTypeX86(uint64_t Type) { return Type == ELF::R_X86_64_NONE; }
+
+bool skipRelocationTypeAArch64(uint64_t Type) {
+  return Type == ELF::R_AARCH64_NONE || Type == ELF::R_AARCH64_LD_PREL_LO19;
+}
+
 bool skipRelocationProcessX86(uint64_t Type, uint64_t Contents) {
   return false;
 }
@@ -536,6 +542,12 @@ size_t Relocation::getSizeForType(uint64_t Type) {
   return getSizeForTypeX86(Type);
 }
 
+bool Relocation::skipRelocationType(uint64_t Type) {
+  if (Arch == Triple::aarch64)
+    return skipRelocationTypeAArch64(Type);
+  return skipRelocationTypeX86(Type);
+}
+
 bool Relocation::skipRelocationProcess(uint64_t Type, uint64_t Contents) {
   if (Arch == Triple::aarch64)
     return skipRelocationProcessAArch64(Type, Contents);
index 41055d2..684b098 100644 (file)
@@ -2332,7 +2332,7 @@ void RewriteInstance::readRelocations(const SectionRef &Section) {
     SmallString<16> TypeName;
     Rel.getTypeName(TypeName);
     uint64_t RType = Rel.getType();
-    if (Relocation::isNone(RType))
+    if (Relocation::skipRelocationType(RType))
       continue;
 
     // Adjust the relocation type as the linker might have skewed it.