All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Fontana <claudio.fontana@huawei.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Michael Tokarev <mjt@tls.msk.ru>, Ed Maste <emaste@freebsd.org>,
	qemu-devel@nongnu.org, Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] Could configure generate QEMU's linker scripts?
Date: Tue, 4 Jun 2013 17:55:37 +0200	[thread overview]
Message-ID: <51AE0DF9.6060709@huawei.com> (raw)
In-Reply-To: <CAFEAcA_evDvvTAOJZ8_=3zoPFzyxyY2J1dk_guNH7sQYZxJ8Jw@mail.gmail.com>

On 03.06.2013 16:57, Peter Maydell wrote:
> On 3 June 2013 15:23, Richard Henderson <rth@twiddle.net> wrote:
>> On 06/02/2013 10:15 AM, Peter Maydell wrote:
>>> So for a new architecture how do we determine whether we need
>>> to fiddle with the start address or not? (More specifically,
>>> is aarch64 going to need a linker script or just to go in the
>>> configure list of "hosts which don't need one" ?)
>>
>> Basically, for a non-PIE build, is there room to run the
>> -linux-user guest binary?  That means getting out of the
>> way of the guest's default link location.  If the host
>> default link location is above 2G you may be good; above
>> 4G is even better.
> 
> Well, the output of ld --verbose says:
> 
>   PROVIDE (__executable_start = SEGMENT_START("text-segment",
> 0x400000)); . = SEGMENT_START("text-segment", 0x400000) +
> SIZEOF_HEADERS;
> 
> and objdump of a random aarch64 binary suggests the
> text segment defaults to a vaddr of 0x400000, so I guess
> that means we need to change the start address.
> 
> thanks
> -- PMM
> 

I'm trying to get this to run, in order to be able to test the aarch64 TCG User mode support I have under development.

I wrote an aarch64.ld script based on the sections of other binaries, using a high address (0x0600000000). Before I tried what seemed to be the standard number for non-x86(0x0060000000), with the same results.

The program actually runs (I can qemu-x86-64 --help, for example),
but I get in trouble with the bss, in the sense that I get a sigfault at runtime as soon as the QEMU code tries to initialize the TCG Context (tcg_ctx, residing in bss) with memset, during tcg_context_init():

qemu-x86_64[418]: unhandled level 3 translation fault (11) at 0x602187000, esr 0x92000047
pgd = ffffffc01aef8000
[602187000] *pgd=000000009ae52003, *pmd=000000009aef9003, *pte=0000000000000000

Pid: 418, comm:          qemu-x86_64
CPU: 0    Not tainted  (3.8.0-rc6+ #3)
PC is at 0x7fb7d0b2f0
LR is at 0x6000c0494
pc : [<0000007fb7d0b2f0>] lr : [<00000006000c0494>] pstate: 20000000
sp : 0000007ffffff480
x29: 0000007ffffff480 x28: 0000000000000000 
x27: 0000000000000000 x26: 0000000000000000 
x25: 0000000000000000 x24: 0000000000000000 
x23: 0000000000000000 x22: 0000000000000000 
x21: 00000006000073e8 x20: 0000000000000000 
x19: 0000000000000000 x18: 0000007fffffe250 
x17: 0000007fb7d0b2a8 x16: 000000060011fd70 
x15: 0016fcc9b4000000 x14: 0000000000000008 
x13: 00000003e8000000 x12: 0000000000000000 
x11: 0000000000000000 x10: 0000007fb7c92ba8 
x9 : 0000000600006424 x8 : 0000000000000038 
x7 : 0000000000001569 x6 : 000000000000002b 
x5 : 0000000000000000 x4 : 0000000602132080 
x3 : 0000000602187000 x2 : 0000000000055a60 
x1 : 0000000000000000 x0 : 0000000602132080 

Program received signal SIGSEGV, Segmentation fault.
__GI_memset (dstpp=0x602132080 <tcg_ctx>, c=0, len=350816) at memset.c:56
56                ((op_t *) dstp)[0] = cccc;
(gdb) bt
#0  __GI_memset (dstpp=0x602132080 <tcg_ctx>, c=0, len=350816) at memset.c:56
#1  0x00000006000c0494 in tcg_context_init (s=0x602132080 <tcg_ctx>)
    at /home/claudio/git/qemu-really-new/tcg/tcg.c:236
#2  0x00000006000c6988 in cpu_gen_init ()
    at /home/claudio/git/qemu-really-new/translate-all.c:130
#3  0x00000006000c7194 in tcg_exec_init (tb_size=0)
    at /home/claudio/git/qemu-really-new/translate-all.c:592
#4  0x000000060004b9cc in main (argc=2, argv=0x7ffffffdb8, envp=0x7ffffffdd0)
    at /home/claudio/git/qemu-really-new/linux-user/main.c:3624

----

This is the aarch64.ld script I am using. The problem is probably here,
since I wrote it without fully understanding it.
Can someone save the day?

----

OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64");
OUTPUT_ARCH(aarch64)
ENTRY(_start)
SECTIONS
{
  /* Read-only sections, merged into text segment: */
  . = 0x600000000 + SIZEOF_HEADERS;
  .interp         : { *(.interp) }
  .hash           : { *(.hash) }
  .dynsym         : { *(.dynsym) }
  .dynstr         : { *(.dynstr)	}
  .gnu.version    : { *(.gnu.version) }
  .gnu.version_r  : { *(.gnu.version_r) }
  .gnu.version_d  : { *(.gnu.version_d) }

  .rel.dyn        : {
    *(.rel.dyn)
    *(.rel.init)
    *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
    *(.rel.fini)
    *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
    *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
    *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
    *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
    *(.rel.ctors)
    *(.rel.dtors)
    *(.rel.got)
    *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
  }

  .rel.plt        : {
    *(.rel.plt)
    PROVIDE (__rel_iplt_start = .);
    *(.rel.iplt)
    PROVIDE (__rel_iplt_end = .);
  }

  .rela.dyn       : {
    *(.rela.dyn)
    *(.rela.init)
    *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
    *(.rela.fini)
    *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
    *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
    *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
    *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
    *(.rela.ctors)
    *(.rela.dtors)
    *(.rela.got)
    *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
  }

  .rela.plt       : {
    *(.rela.plt)
    PROVIDE (__rela_iplt_start = .);
    *(.rela.iplt)
    PROVIDE (__rela_iplt_end = .);
  }

  .init           : { *(.init) } = 0x600000000
  .plt            : { *(.plt) }
  .text           : {
    *(.text)
    *(.gnu.warning)
    *(.gnu.linkonce.t*)
  } = 0x600000000
  _etext = .;
  PROVIDE (etext = .);

  .fini           : { *(.fini)    } = 0x600000000
  .rodata         : { *(.rodata) *(.gnu.linkonce.r*) }

   __exidx_start = .;
  .ARM.exidx      : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }
   __exidx_end = .;
  .ARM.extab      : { *(.ARM.extab* .gnu.linkonce.armextab.*) }
  .ARM.attributes : { *(.ARM.attributes* .gnu.linkonce.armattributes.*) }

  .eh_frame       : { KEEP (*(.eh_frame)) }

  . = ALIGN(64 / 8);

  .preinit_array :
  {
    PROVIDE (__preinit_array_start = .);
    KEEP (*(.preinit_array))
    PROVIDE (__preinit_array_end = .);
  }
  .init_array    :
  {
     PROVIDE (__init_array_start = .);
     KEEP (*(SORT(.init_array.*)))
     KEEP (*(.init_array))
     PROVIDE (__init_array_end = .);
  }
  .fini_array    :
  {
    PROVIDE (__fini_array_start = .);
    KEEP (*(.fini_array))
    KEEP (*(SORT(.fini_array.*)))
    PROVIDE (__fini_array_end = .);
  }

  .jcr           : { KEEP (*(.jcr)) }
  .dynamic       : { *(.dynamic) }
  .got           : { *(.got) }
  .got.plt       : { *(.got.plt) }
  .data          : {
    *(.gen_code .data .data.* .gnu.linkonce.d*)
    SORT(CONSTRUCTORS)
  }

  . = ALIGN(64 / 8);
  __bss_start = .;
  .bss           : {
    *(.dynbss)
    *(.bss .bss.* .gnu.linkonce.b.*)
    *(COMMON)
    /* Align here to ensure that the .bss section occupies space up to
       _end.  Align after .bss to ensure correct alignment even if the
      .bss section disappears because there are no input sections. */
    . = ALIGN(64 / 8);
  }
  _end = .;
  PROVIDE (end = .);

  /* Stabs debugging sections.  */
  .stab 0          : { *(.stab) }
  .stabstr 0       : { *(.stabstr) }
  .stab.excl 0     : { *(.stab.excl) }
  .stab.exclstr 0  : { *(.stab.exclstr) }
  .stab.index 0    : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }
  .comment 0       : { *(.comment) }
  /* DWARF debug sections.
     Symbols in the DWARF debugging sections are relative to the beginning
     of the section so we begin them at 0.  */
  /* DWARF 1 */
  .debug 0           : { *(.debug) }
  .line 0            : { *(.line) }
  /* GNU DWARF 1 extensions */
  .debug_srcinfo 0   : { *(.debug_srcinfo) }
  .debug_sfnames 0   : { *(.debug_sfnames) }
  /* DWARF 1.1 and DWARF 2 */
  .debug_aranges 0   : { *(.debug_aranges) }
  .debug_pubnames 0  : { *(.debug_pubnames) }
  /* DWARF 2 */
  .debug_info 0      : { *(.debug_info) }
  .debug_abbrev 0    : { *(.debug_abbrev) }
  .debug_line 0      : { *(.debug_line) }
  .debug_frame 0     : { *(.debug_frame) }
  .debug_str 0       : { *(.debug_str) }
  .debug_loc 0       : { *(.debug_loc) }
  .debug_macinfo 0   : { *(.debug_macinfo) }
  /* SGI/MIPS DWARF 2 extensions */
  .debug_weaknames 0 : { *(.debug_weaknames) }
  .debug_funcnames 0 : { *(.debug_funcnames) }
  .debug_typenames 0 : { *(.debug_typenames) }
  .debug_varnames  0 : { *(.debug_varnames) }
  .debug_ranges 0    : { *(.debug_ranges) }

  .note.gnu.build-id : { *(.note.gnu.build-id) }

  /* These must appear regardless of  .  */
  /DISCARD/ : { *(.note.GNU-stack) *(.note.ABI-tag) }
}

  parent reply	other threads:[~2013-06-04 16:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-19 16:30 [Qemu-devel] Could configure generate QEMU's linker scripts? Ed Maste
2013-05-19 19:24 ` Paolo Bonzini
2013-05-20  0:22   ` Aurelien Jarno
2013-05-20 17:21 ` Richard Henderson
2013-05-21 17:51   ` Ed Maste
2013-05-21 18:14     ` Richard Henderson
2013-06-02 17:15   ` Peter Maydell
2013-06-03 14:23     ` Richard Henderson
2013-06-03 14:57       ` Peter Maydell
2013-06-03 15:01         ` Richard Henderson
2013-06-04 15:55         ` Claudio Fontana [this message]
2013-06-04 16:13           ` Peter Maydell
2013-06-04 16:18             ` Richard Henderson
2013-06-05  9:03             ` Claudio Fontana

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=51AE0DF9.6060709@huawei.com \
    --to=claudio.fontana@huawei.com \
    --cc=emaste@freebsd.org \
    --cc=mjt@tls.msk.ru \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.