Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Thiemo Seufer <ths@networkno.de>
To: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: linux-mips@linux-mips.org, ralf@linux-mips.org, sam@ravnborg.org
Subject: Re: [PATCH] fix modpost segfault for 64bit mipsel kernel
Date: Mon, 17 Apr 2006 17:27:42 +0100	[thread overview]
Message-ID: <20060417162742.GD28935@networkno.de> (raw)
In-Reply-To: <20060418.004718.108120830.anemo@mba.ocn.ne.jp>

Atsushi Nemoto wrote:
> On Mon, 17 Apr 2006 15:07:35 +0100, Thiemo Seufer <ths@networkno.de> wrote:
> > I should have read more carefully. The ELF_R_SYM seems to be correct, if
> > this patch makes it work fo you then the toolchain you use creates broken
> > (word-swapped ?) relocation entries for mips64el.
> 
> Looking at following codes in glibc source
> (sysdeps/mips/elf/ldsodefs.h), I thought r_info on 64bit mips needs
> special handling.  Is not this structure used for 64bit kernel
> modules?
> 
> typedef struct
> {
>   Elf32_Word    r_sym;		/* Symbol index */
>   unsigned char r_ssym;		/* Special symbol for 2nd relocation */
>   unsigned char r_type3;	/* 3rd relocation type */
>   unsigned char r_type2;	/* 2nd relocation type */
>   unsigned char r_type1;	/* 1st relocation type */
> } _Elf64_Mips_R_Info;


Hm, binutils uses generically 64bit quantities:

#define ELF32_R_SYM(i)		((i) >> 8)
#define ELF32_R_TYPE(i)		((i) & 0xff)
#define ELF32_R_INFO(s,t)	(((s) << 8) + ((t) & 0xff))

#define ELF64_R_SYM(i)		((i) >> 32)
#define ELF64_R_TYPE(i)		((i) & 0xffffffff)
#define ELF64_R_INFO(s,t)	(((bfd_vma) (s) << 31 << 1) + (bfd_vma) (t))


But for MIPS64 the same as glibc:

typedef struct
{
  /* Address of relocation.  */
  unsigned char r_offset[8];
  /* Symbol index.  */
  unsigned char r_sym[4];
  /* Special symbol.  */
  unsigned char r_ssym[1];
  /* Third relocation.  */
  unsigned char r_type3[1];
  /* Second relocation.  */
  unsigned char r_type2[1];
  /* First relocation.  */
  unsigned char r_type[1];
  /* Addend.  */
  unsigned char r_addend[8];
} Elf64_Mips_External_Rela;

/* MIPS ELF 64 relocation info access macros.  */
#define ELF64_MIPS_R_SSYM(i) (((i) >> 24) & 0xff)
#define ELF64_MIPS_R_TYPE3(i) (((i) >> 16) & 0xff)
#define ELF64_MIPS_R_TYPE2(i) (((i) >> 8) & 0xff)
#define ELF64_MIPS_R_TYPE(i) ((i) & 0xff)


So it is the

      r.r_info   = TO_NATIVE(rela->r_info);

in modpost.c which breaks both SYM and TYPE because it assumes a
64bit integer. The proper solution would be to add a Elf64_Mips_Rela
structure (with lots of nearly identical duplicated code), the hack
would be to cast r_info to a 32bit integer for mips, before feeding
it to TO_NATIVE (which works until somebody asks for the TYPE, then
a separate mips64 version becomes inevitable.)


Thiemo

  reply	other threads:[~2006-04-17 16:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-17 12:00 [PATCH] fix modpost segfault for 64bit mipsel kernel Atsushi Nemoto
2006-04-17 12:53 ` Thiemo Seufer
2006-04-17 14:07   ` Thiemo Seufer
2006-04-17 15:47     ` Atsushi Nemoto
2006-04-17 16:27       ` Thiemo Seufer [this message]
2006-04-19  2:22         ` Atsushi Nemoto
2006-04-20  0:19           ` Thiemo Seufer
2006-04-20 16:02             ` Atsushi Nemoto
2006-04-20 16:23               ` Thiemo Seufer
2006-04-20 17:05                 ` Atsushi Nemoto
2006-04-21 13:57                   ` Thiemo Seufer
2006-04-17 13:40 ` Sam Ravnborg
2006-04-17 16:03   ` Atsushi Nemoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060417162742.GD28935@networkno.de \
    --to=ths@networkno.de \
    --cc=anemo@mba.ocn.ne.jp \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.org \
    --cc=sam@ravnborg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox