fix: kallsyms wrapper on ppc64el
[lttng-modules.git] / src / wrapper / kallsyms.c
index e7c6639432ee9ebf84b51644cc22f01f0dcbb960..061224dee26876ca88f2651298b6ce5ee0552f37 100644 (file)
@@ -14,7 +14,7 @@
 #include <linux/module.h>
 #include <wrapper/kallsyms.h>
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,7,0))
 
 #ifndef CONFIG_KPROBES
 # error "LTTng-modules requires CONFIG_KPROBES on kernels >= 5.7.0"
@@ -39,10 +39,26 @@ unsigned long do_get_kallsyms(void)
        memset(&probe, 0, sizeof(probe));
        probe.pre_handler = dummy_kprobe_handler;
        probe.symbol_name = "kallsyms_lookup_name";
+#ifdef LTTNG_CONFIG_PPC64_ELF_ABI_V2
+       /*
+        * With powerpc64 ABIv2, we need the global entry point of
+        * kallsyms_lookup_name to call it later, while kprobe_register would
+        * automatically adjust the global entry point to the local entry point,
+        * when a kprobe was registered at a function entry. So we add 4 bytes
+        * which is the length of one instruction to kallsyms_lookup_name to
+        * avoid the adjustment.
+        */
+       probe.offset = 4;
+#endif
        ret = register_kprobe(&probe);
        if (ret)
                return 0;
+#ifdef LTTNG_CONFIG_PPC64_ELF_ABI_V2
+       /* Substract 4 bytes to get what we originally want */
+       addr = (unsigned long)(((char *)probe.addr) - 4);
+#else
        addr = (unsigned long)probe.addr;
+#endif
 #ifdef CONFIG_ARM
 #ifdef CONFIG_THUMB2_KERNEL
        if (addr)
This page took 0.023238 seconds and 4 git commands to generate.