From e8c62c5e19b119788272d63007ce76caf88f28b6 Mon Sep 17 00:00:00 2001
From: Avi Kivity <avi@cloudius-systems.com>
Date: Sun, 26 May 2013 20:48:05 +0300
Subject: [PATCH] elf: add support for IRELATIVE relocations

This are used to support ifunc functions, which are resolved at load-time
based on cpu features, rather than at link time.
---
 core/elf.cc    | 3 +++
 include/elf.hh | 1 +
 2 files changed, 4 insertions(+)

diff --git a/core/elf.cc b/core/elf.cc
index ecb479c9d..502484390 100644
--- a/core/elf.cc
+++ b/core/elf.cc
@@ -924,6 +924,9 @@ init_table get_init(Elf64_Ehdr* header)
                         // FIXME: assumes TLS segment comes before DYNAMIC segment
                         *static_cast<u64*>(addr) = lookup()->st_value - ret.tls.size;
                         break;
+                    case R_X86_64_IRELATIVE:
+                        *static_cast<void**>(addr) = reinterpret_cast<void *(*)()>(base + addend)();
+                        break;
                     default:
                         abort();
                     }
diff --git a/include/elf.hh b/include/elf.hh
index 43eb6e6ad..b14199879 100644
--- a/include/elf.hh
+++ b/include/elf.hh
@@ -192,6 +192,7 @@ enum {
     R_X86_64_GOTPC32 = 26, //  word32 GOT + A - P
     R_X86_64_SIZE32 = 32, //  word32 Z + A
     R_X86_64_SIZE64 = 33, //  word64 Z + A
+    R_X86_64_IRELATIVE = 37, //  word64 indirect(B + A)
     };
 
 enum {
-- 
GitLab