From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27626 invoked by alias); 10 Jun 2013 23:19:20 -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 27617 invoked by uid 89); 10 Jun 2013 23:19:20 -0000 X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,SPF_PASS,TW_OV autolearn=ham version=3.3.1 Received: from mail-lb0-f179.google.com (HELO mail-lb0-f179.google.com) (209.85.217.179) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 10 Jun 2013 23:19:18 +0000 Received: by mail-lb0-f179.google.com with SMTP id w20so6888652lbh.10 for ; Mon, 10 Jun 2013 16:19:16 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.152.20.40 with SMTP id k8mr5681921lae.25.1370906355602; Mon, 10 Jun 2013 16:19:15 -0700 (PDT) Received: by 10.114.79.233 with HTTP; Mon, 10 Jun 2013 16:19:15 -0700 (PDT) In-Reply-To: References: Date: Mon, 10 Jun 2013 23:19:00 -0000 Message-ID: Subject: Re: Thumb inline assembly From: Kalai Rajah N To: Ian Lance Taylor Cc: "gcc-help@gcc.gnu.org" Content-Type: text/plain; charset=ISO-8859-1 X-SW-Source: 2013-06/txt/msg00060.txt.bz2 Even I'm confused about the errors. when remove the clobber list "r0", "r1", "r2", "r3", I get undefined reference to r1, r3 and r2. Here is the generated assembly code 1: when the asm is called directly ... this seems to work ldr r2, =8 /* number of register */ ldr r1, =#-536813312 /* load the nvic_iser* register */ read_nvic_iser: sub r2, r2, #1 ldr r0, [r1] add r1, r1, #4 /* go to the next register */ cmp r0, #0 beq read_nvic_iser_ok ldr r3, =#-1163018018 str r3, [r4] /* update status flag */ read_nvic_iser_ok: cmp r2, #0 bne read_nvic_iser ldr r3, =#1611514078 str r3, [r4] /* update status flag */ 2: when the asm gets called through another function ... this is having the compilation error ... .thumb_func .type check_reset_value, %function check_reset_value: @ args = 0, pretend = 0, frame = 16 @ frame_needed = 1, uses_anonymous_args = 0 @ link register save eliminated. push {r4, r5, r6, r7, r8} sub sp, sp, #20 add r7, sp, #0 str r0, [r7, #12] str r1, [r7, #8] str r2, [r7, #4] ldr r6, [r7, #12] ldr ip, [r7, #8] movw r4, #49374 movt r4, 47789 movw r5, #49374 movt r5, 24589 ldr r8, [r7, #4] @ 24 "nvic_reg_read.c" 1 ldr r2, =8 /* number of register */ ldr r1, =r6 /* load the nvic_iser* register */ <------ read_reg: sub r2, r2, #1 ldr r0, [r1] add r1, r1, #4 /* go to the next register */ cmp r0, ip beq read_reg_ok ldr r3, =r4 <---------- str r3, [r8] /* update status flag */ read_reg_ok: cmp r2, #0 bne read_reg ldr r3, =r5 <-------------- str r3, [r8] /* update status flag */ the lines marked with the arrows are where the errors occur. On Mon, Jun 10, 2013 at 3:51 PM, Ian Lance Taylor wrote: > On Mon, Jun 10, 2013 at 2:41 PM, Kalai Rajah N wrote: > >> I'm trying to do a simple register read through ARM inline assembly. >> If I embed the asm in the function directly, it works ... > > ... > >> I see the following errors: >> /tmp/ccYu7aUS.ltrans0.ltrans.o: In function `read_reg_ok': >> ccYu7aUS.ltrans0.o:(.text.check_reset_value.4010+0x60): undefined >> reference to `r6' >> ccYu7aUS.ltrans0.o:(.text.check_reset_value.4010+0x64): undefined >> reference to `r4' >> ccYu7aUS.ltrans0.o:(.text.check_reset_value.4010+0x68): undefined >> reference to `r5' >> collect2: error: ld returned 1 exit status >> >> What am I doing wrong? > > > Your test case has no mention of r4, r5, or r6. It always helps to > show a complete standalone test case. > > The error messages indicate some confusion: there are references to > symbols using the names of registers. But I don't know where those > are coming from. > > Ian