Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: John Reiser <jreiser@bitwagon.com>
To: wu zhangjin <wuzhangjin@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	David Daney <ddaney@caviumnetworks.com>,
	linux-mips@linux-mips.org, ralf@linux-mips.org
Subject: Re: [RFC 2/2] ftrace/MIPS: Add support for C version of recordmcount
Date: Sun, 24 Oct 2010 07:25:13 -0700	[thread overview]
Message-ID: <4CC441C9.8070206@bitwagon.com> (raw)
In-Reply-To: <AANLkTinwXjLAYACUfhLYaocHD_vBbiErLN3NjwN8JqSy@mail.gmail.com>

Hi, here is the diagnosis for SIGSEGV in recordmcount.c on MIPS64:

On 10/23/2010, wu zhangjin wrote:
>   CC      init/main.o
> /bin/sh: line 1: 21835 Segmentation fault     scripts/recordmcount "init/main.o"
> make[1]: *** [init/main.o] Error 139
> make: *** [init] Error 2
> 
> I traced the problem and found it was triggered by the 201 line of
> scripts/recordmcount.h:
> 
> 198                 if (!mcountsym) {
> 199                         Elf_Sym const *const symp =
> 200                                 &sym0[ELF_R_SYM(_w(relp->r_info))];
> *201                         char const *symname = &str0[w(symp->st_name)];*
> 202
> 203                         if ('.' == symname[0])
> 204                                 ++symname;  /* ppc64 hack */
> 
> Exactly, it was triggered by: symp->st_name, symp is normal address,
> i.e. 0xa01831f0, but perhaps the content pointed by this address may
> not exist or is not allocated before?
> 
> Did I miss something for MIPS specific support?

The layout of a MIPS structure Elf64_Rela is not described correctly
by the macros ELF64_R_SYM and ELF64_R_TYPE of <elf.h>:
-----
#define ELF64_R_SYM(i)                  ((i) >> 32)
#define ELF64_R_TYPE(i)                 ((i) & 0xffffffff)
-----

"readelf main.o" says:
-----
Relocation section '.rela.text' at offset 0x5b68 contains 59 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000020  004200000004 R_MIPS_26         0000000000000000 _mcount + 0
                    Type2: R_MIPS_NONE
                    Type3: R_MIPS_NONE
-----

The actual bytes are [performed on a little-endian machine,
which is the same as main.o, namely ELFDATA2LSB]:
-----
$ od -Ax -tx8 -j0x5b68 main.o  |  sed 2q
005b68 0000000000000020 0400000000000042
005b78 0000000000000000
-----

So it looks like the data actually corresponds to:
-----
#define MIPS_ELF64_R_TYPE(i)  (0xff & ((i)>>56))
#define MIPS_ELF64_R_TYPE2(i) (0xff & ((i)>>48))
#define MIPS_ELF64_R_TYPE3(i) (0xff & ((i)>>40))
#define MIPS_ELF64_R_SYM(i)   (0xffffffff & (i))  /* perhaps 40 bits? */
-----

What this means for recordmcount.c is that ELF_R_SYM and ELF_R_TYPE
should become pointers to functions with default bodies given by
the macros in <elf.h>, and which EM_MIPS overrides.


> for kernel:
>     #     14:   0c000000        jal     0
>     #                    14: R_MIPS_26   _mcount

> for module:
>     #       c:  3c030000        lui     v1,0x0
>     #                   c: R_MIPS_HI16  _mcount

I suggest that the argv command line for recordcmount.c have an
optional flag -m or --module, such that the correct reltype can
be chosen when .e_machine is decoded.

> (Note: The above patch is not enough, for the modules with
> -mlong-calls, the reltype should be R_MIPS_HI16, and we may also need
> to add our specific code for sift_rel_mcount() to get the right
> location of the _mcount calling site)

"-mlong-calls" must set .e_flags, or otherwise provide enough
description to that the correct reltype can be chosen at the time
when .e_machine is decoded.  Adjusting the address for the location
of the call to _mcount should be another function pointer that is
overridden for EM_MIPS.

Regards,

-- 
John Reiser, jreiser@BitWagon.com

  parent reply	other threads:[~2010-10-24 14:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-23 18:53 [RFC 2/2] ftrace/MIPS: Add support for C version of recordmcount wu zhangjin
2010-10-24  8:58 ` Steven Rostedt
2010-10-24 14:25 ` John Reiser [this message]
2010-10-24 20:44 ` patch: " John Reiser
2010-10-25  3:59   ` Maciej W. Rozycki
2010-10-25 12:28     ` John Reiser
2010-10-25 16:46     ` patch v2: " John Reiser
2010-10-25 18:17       ` wu zhangjin
2010-10-25 20:24         ` Steven Rostedt
2010-10-26 18:28           ` wu zhangjin
2010-10-26 13:36       ` Maciej W. Rozycki
2010-10-26 19:57         ` wu zhangjin
2010-10-27  9:31           ` Maciej W. Rozycki
2010-10-27  9:54             ` wu zhangjin
2010-10-26 21:21       ` wu zhangjin

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=4CC441C9.8070206@bitwagon.com \
    --to=jreiser@bitwagon.com \
    --cc=ddaney@caviumnetworks.com \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.org \
    --cc=rostedt@goodmis.org \
    --cc=wuzhangjin@gmail.com \
    /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