Re: [PATCH] fix modpost segfault for 64bit mipsel kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Atsushi Nemoto wrote:
> On Mon, 17 Apr 2006 15:07:35 +0100, Thiemo Seufer <ths@xxxxxxxxxxxx> 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


[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux