public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "matti h" <matti@henttunen.se>
To: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: gcc Cortex M4 bug ?
Date: Thu, 13 Jun 2013 09:25:00 -0000	[thread overview]
Message-ID: <zarafa.51b98ff7.317d.5b99653d51906e75@mail.henttunen.se> (raw)

Hi,
Im trying to implement a dynamic linker for M4 mcu's.
But the generated code from gcc seems incorrect to me: im compiling using
arm-none-eabi-gcc: -mcpu=cortex-m4 -mthumb -O2 -ggdb  -Wstrict-prototypes 
-Wunused-parameter -lmylib main.c -o test

Ive created the following program dynamically linked:
----main.c---------
int main()
{
        test();
        return 1;
}

On target I have the function
-------mylib.c-----------
int test()
{
        return 1;
}
arm-none-eabi-gcc -fPIC -mcpu=cortex-m4 -mthumb -O2 -ggdb 
-Wstrict-prototypes -Wunused-parameter -lmylib mylib.c -o mylib.so

------linker script-----
OUTPUT_FORMAT("elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)

PHDRS
{
        headers PT_PHDR PHDRS ;
        interp PT_INTERP ;
        text PT_LOAD FILEHDR PHDRS ;
        data PT_LOAD ;
        got PT_LOAD;
        dynamic PT_DYNAMIC ;
}

SECTIONS
{
        . = SIZEOF_HEADERS;
        .interp : { *(.interp) } :text :interp
        .hash           : { *(.hash) }
        .text : { *(.text) } :text
        .rodata : { *(.rodata) } /* defaults to :text */
        .dynsym         : { *(.dynsym) }
        .dynstr         : { *(.dynstr) }
        .rel.dyn        :
    {
      *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
      *(.rel.got)
    }
        .rela.dyn       :
    {
      *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
      *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
      *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
      *(.rela.got)
    }
        .rel.plt        :
    {
      *(.rel.plt)
    }
        .rela.plt       :
    {
      *(.rela.plt)
    }
  .init_array     :
  {
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array))
    PROVIDE_HIDDEN (__init_array_end = .);
  }
  .fini_array     :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array))
    PROVIDE_HIDDEN (__fini_array_end = .);
  }
  .jcr            : { KEEP (*(.jcr)) }

        .init           :
        {
                KEEP (*(.init))
        } =0
 .plt            :  { *(.plt) }
        .dynamic : { *(.dynamic) } :data :dynamic
        .got            : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } 
:got
        .data : { *(.data) } :data
}

the machine generated code for main looks as follows (objdump -D):

0000015c <main>:
 15c:   b508            push    {r3, lr}
 15e:   f000 e888       blx     270 <__libc_fini_array+0xfc>
 162:   2001            movs    r0, #1
 164:   bd08            pop     {r3, pc}
 166:   bf00            nop


instruction at  15e:   seems incorrect to me, since M4 only branches using 
a register   blx{cond} Rm, (M3 seems to be ok with label aswell.)

Anyone who can tell me what is wrong and if there is a workaround for this 
?

Ive tried to use -mlong-calls, and it produces:

00000164 <main>:
 164:   b508            push    {r3, lr}
 166:   f240 237c       movw    r3, #636        ; 0x27c
 16a:   f2c0 0300       movt    r3, #0
 16e:   4798            blx     r3
 170:   2001            movs    r0, #1
 172:   bd08            pop     {r3, pc}


This looks OK except for the address in R3 not being rellative, since it's 
absolute it's not correct either (or am I missing something)



BR
Matias

             reply	other threads:[~2013-06-13  9:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-13  9:25 matti h [this message]
2013-06-13 16:50 ` Kai Ruottu
2013-06-14 13:37   ` Ilija Kocho

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=zarafa.51b98ff7.317d.5b99653d51906e75@mail.henttunen.se \
    --to=matti@henttunen.se \
    --cc=gcc-help@gcc.gnu.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).