linux-mips
[Top] [All Lists]

Re: Relocation problem with MIPS kernel modules

To: Ralf Baechle <ralf@linux-mips.org>
Subject: Re: Relocation problem with MIPS kernel modules
From: David Daney <ddaney@caviumnetworks.com>
Date: Mon, 03 Aug 2009 12:33:25 -0700
Cc: David VomLehn <dvomlehn@cisco.com>, GCC Help Mailing List <gcc-help@gcc.gnu.org>, Linux MIPS Mailing List <linux-mips@linux-mips.org>
In-reply-to: <20090803092030.GB30431@linux-mips.org>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <20090730184923.GA27030@cuplxvomd02.corp.sa.net> <20090803092030.GB30431@linux-mips.org>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Thunderbird 2.0.0.21 (X11/20090320)
Ralf Baechle wrote:
On Thu, Jul 30, 2009 at 11:49:23AM -0700, David VomLehn wrote:

To: GCC Help Mailing List <gcc-help@gcc.gnu.org>,
        Linux MIPS Mailing List <linux-mips@linux-mips.org>
Subject: Relocation problem with MIPS kernel modules
Content-Type: text/plain; charset=us-ascii

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

I'll change the messages to indicate the relocation type.

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.

The GNU tools as an extension over the MIPS ABI allows an arbitrary number of
R_MIPS_HI16 relocations to be followed by a R_MIPS_LO16 symbol.  All
relocations of this sequence must use the same symbol, of course.  This is
a very old extension; I think it predates the Linux/MIPS port.


Actually I think it is the opposite:

RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE
00000000 R_MIPS_HI16       .bss+0x00000004
00000008 R_MIPS_LO16       .bss+0x00000004
00000014 R_MIPS_LO16       .bss+0x00000004

We load the hi16 value into a register and then use multiple lo16 offsets for the follow loads and stores to the same location. On a read-modify-write we only want to load the base address one time.

David Daney

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