From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7713 invoked by alias); 13 Jun 2013 09:25:15 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 7701 invoked by uid 89); 13 Jun 2013 09:25:15 -0000 X-Spam-SWARE-Status: No, score=0.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_NO,TW_BL,TW_OV autolearn=no version=3.3.1 Received: from smtprelay-b22.telenor.se (HELO smtprelay-b22.telenor.se) (195.54.99.213) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 13 Jun 2013 09:25:14 +0000 Received: from ipb2.telenor.se (ipb2.telenor.se [195.54.127.165]) by smtprelay-b22.telenor.se (Postfix) with ESMTP id 3066DDD5A for ; Thu, 13 Jun 2013 11:25:11 +0200 (CEST) X-SENDER-IP: [85.224.174.91] X-LISTENER: [smtp.bredband.net] X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjWRAE+PuVFV4K5bPGdsb2JhbABbgwgxgz2EOrAlhxICgRYDAQEBATg1gk1rIAIYDgJFGiSIAZpNhneIA5FYgSaNT4MhgRQDl0CBKZFLgV86 Received: from c-5baee055.5523237--62697410.cust.bredbandsbolaget.se (HELO mail.henttunen.se) ([85.224.174.91]) by ipb2.telenor.se with ESMTP; 13 Jun 2013 11:25:11 +0200 Subject: gcc Cortex M4 bug ? From: =?utf-8?Q?matti_h?= To: =?utf-8?Q?gcc-help=40gcc=2Egnu=2Eorg?= Date: Thu, 13 Jun 2013 09:25:00 -0000 Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Reply-To: matti@henttunen.se Message-Id: X-SW-Source: 2013-06/txt/msg00091.txt.bz2 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
: 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
: 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