linux-mips
[Top] [All Lists]

Re: Relocation problem with MIPS kernel modules

To: David VomLehn <dvomlehn@cisco.com>
Subject: Re: Relocation problem with MIPS kernel modules
From: David Daney <ddaney@caviumnetworks.com>
Date: Thu, 30 Jul 2009 12:15:42 -0700
Cc: GCC Help Mailing List <gcc-help@gcc.gnu.org>, Linux MIPS Mailing List <linux-mips@linux-mips.org>
In-reply-to: <20090730184923.GA27030@cuplxvomd02.corp.sa.net>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <20090730184923.GA27030@cuplxvomd02.corp.sa.net>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Thunderbird 2.0.0.21 (X11/20090320)
David VomLehn wrote:
I have a MIPS loadable kernel module that, when I try to insmod it, causes the
kernel to emit the message:

        module xyz: dangerous relocation

This message appears in three different places in arch/mips/kernel/module.c,
but this one is coming from apply_r_mips_lo16_rel(). The module code at
the location at which the error message is generated appears to be pretty
bland:
        lw v0,28564(s1)
with the expected relocation type of R_MIPS_LO16. The relocation before it
is R_MIPS_HI16, as expected, but for a different symbol. Before *that*
is another R_MIPS_HI16 relocation entry for yet a third symbol.

According to the MIPS ABI, for what it's worth, "Each relocation type of
R_MIPS_HI16 must have an associated R_MIPS_LO16 entry immediately following
it in the list of relocations." So, what's actually getting generated by
gcc and linker differs from the closest thing we have to an ABI of record for
MIPS processors.

What the kernel actually does differs from my interpretation of the MIPS ABI
in several particulars, which it has to do to relocate what it is actually
getting, but since I get the "dangerous relocation" error for a module that
appears to me to be valid, it may need to be fixed/enhanced.

So, who the heck knows what gcc and the linker are really generating and can
anyone suggest an algorithm for handling R_MIPS_HI16/R_MIPS_LO16 relocation
entries correctly?

Without seeing your object module I am guessing.

Q: What version of binutils and GCC are you using?

It is the assembler's responsibility to properly sort the relocations. Some versions of binutils have bugs in this area. If you are not using 2.19.1, I suggest that you upgrade.

Unless you are compiling with -fsection-anchors there should be pairs of R_MIPS_HI16/R_MIPS_LO16 relocations.

David Daney

<Prev in Thread] Current Thread [Next in Thread>