R_PPC_ADDR16_HI relocs in PPC modules ?

Simon Vallet linux-ppc at castalie.org
Wed Jan 3 03:25:54 EST 2007


I'm currently trying to port a binary-only driver to Linux/PPC using a
MacOS X driver as a starting point. "Translating" this driver to ELF32
gives an object that links into a .ko without too much problems.

However, trying to insmod the resulting object gives the following
error message:

unknown ADD relocation: 5

which refers to R_PPC_ADDR16_HI relocations. The error message comes
from apply_relocate_add() in arch/powerpc/kernel/module_32.c, which
deals with R_PPC_ADDR16_LO and R_PPC_ADDR16_HA relocs, but not
R_PPC_ADDR16_HI ones.

Is there a reason for this ? Those relocs directly come from the
mapping of PPC_RELOC_HI16 in the original driver, and i'd rather not
transpose them into R_PPC_ADDR16_HA.

If there are no reasons, then how about the following patch ?
(this is against, but the problem is still present in 2.6.19 kernels)

--- arch/powerpc/kernel/module_32.c.orig	2007-01-02 17:07:21.000000000 +0100
+++ arch/powerpc/kernel/module_32.c	2007-01-02 17:11:55.000000000 +0100
@@ -222,6 +222,11 @@ int apply_relocate_add(Elf32_Shdr *sechd
 			*(uint16_t *)location = value;
+		case R_PPC_ADDR16_HI:
+			/* Higher half of the symbol */
+			*(uint16_t *)location = (value >> 16);
+			break;
 		case R_PPC_ADDR16_HA:
 			/* Sign-adjusted lower 16 bits: PPC ELF ABI says:
 			   (((x >> 16) + ((x & 0x8000) ? 1 : 0))) & 0xFFFF.

Note that I'm quite new to the kernel in general, so feel free to point me to 
another list if you think my questions are inappropriate here.


More information about the Linuxppc-dev mailing list