This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/37247] New: Function address passed as argument is incremented by 1


when calling a function with an function call address as argument, the address
is passed incremented by 1. it may work some times, but often crashes.
It can be verified in the dumpfile (.dm), the error is also present in hex
file.

the function call is "netif_add" (see below) argument "ethernetif_init" real
address is 0x0001261c, but in the table after the code (at 0x2050) we can find
0x0001261d. Of course, when calling the function, which then has an odd
address, the target generates a data error. Same problem with the last argument
"tcpip_input"
I have found same problems in other projects, I don't understand how they can
work. 
Can it be a linker problem ? Why is the address incremented by 1? is there a
bad option in the makefile ? I think it can be a bug. not all function
addresses are affected.

project is based on lwip stack with freeRTOS. target : AT91SAM7X512 (or 256).

part extracted from .DM file:
===============================
00001f40 <vBasicWEBServer>:
    1f40:       b530            push    {r4, r5, lr}
    1f42:       b091            sub     sp, #68
    1f44:       ab03            add     r3, sp, #12
.....
netif_add(&EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init,
tcpip_input);
....
    1f7c:       46ec            mov     ip, sp
    1f7e:       4b34            ldr     r3, [pc, #208]  (2050
<vBasicWEBServer+0x110>) <ethernetif_init>
    1f80:       4660            mov     r0, ip
    1f82:       6043            str     r3, [r0, #4]
    1f84:       46ec            mov     ip, sp
    1f86:       4b33            ldr     r3, [pc, #204]  (2054
<vBasicWEBServer+0x114>)<tcpip_input>
    1f88:       4660            mov     r0, ip
....
    2038:       2296            movs    r2, #150
    203a:       1c23            adds    r3, r4, #0
    203c:       f017 f9b4       bl      193a8 <xTaskCreate>
    2040:       e7c6            b.n     1fd0 <vBasicWEBServer+0x90>
    2042:       46c0            nop                     (mov r8, r8)
    2044:       c0a8002d        .word   0xc0a8002d
    2048:       c0a800fe        .word   0xc0a800fe
    204c:       0020ab68        .word   0x0020ab68
    2050:       0001261d        .word   0x0001261d      <ethernetif_init>       
    2054:       0000f70d        .word   0x0000f70d
    2058:       00023ff8        .word   0x00023ff8
    205c:       00001ebd        .word   0x00001ebd


=======================
0001261c <ethernetif_init>:
   1261c:       b500            push    {lr}
   1261e:       b083            sub     sp, #12
   12620:       ab01            add     r3, sp, #4
...
   126a2:       bc02            pop     {r1}
   126a4:       4708            bx      r1
   126a6:       46c0            nop                     (mov r8, r8)
   126a8:       000124bd        .word   0x000124bd
   126ac:       000122a9        .word   0x000122a9
   126b0:       00001388        .word   0x00001388
   126b4:       000125f5        .word   0x000125f5
   126b8:       4720            bx      r4
   126ba:       46c0            nop                     (mov r8, r8)

=======================
0000f70c <tcpip_input>:
 *          to an IP header (if netif doesn't got NETIF_FLAG_ETHARP flag)
 * @param inp the network interface on which the packet was received
 */
err_t
tcpip_input(struct pbuf *p, struct netif *inp)
{
    f70c:       b500            push    {lr}
    f70e:       b084            sub     sp, #16
...
    f7a2:       b004            add     sp, #16
    f7a4:       bc02            pop     {r1}
    f7a6:       4708            bx      r1
    f7a8:       0021570c        .word   0x0021570c

makefile used:
========================
#      
***************************************************************************
#       See http://www.FreeRTOS.org for documentation, latest information,
license 
#       and contact details.  Please ensure to read the configuration and
relevant 
#       port sections of the online documentation.
#      
***************************************************************************

CC=arm-elf-gcc
AS=arm-elf-gcc -x assembler-with-cpp
OBJCOPY=arm-elf-objcopy
ARCH=arm-elf-ar
DEBUG=-g
OPTIM=-O0
LDSCRIPT=atmel-rom.ld

#jlb -S: intermix C with Assembler
ODFLAGS = -f -p -x -h -t -s -D -S -r -G -W
OBJDUMP = arm-elf-objdump

#Project and main binary file name
PROJECT = InterfaceIP_V1

#
# CFLAGS common to both the THUMB and ARM mode builds
#
#jlb : remove one level '../' before Source

CFLAGS= \
-I.  \
-I./Include \
-I./EMAC  \
-I../Common/include  \
-I./USB  \
-I./lwip-1.3.0/src/include  \
-I./lwip-1.3.0/contrib/port/FreeRTOS/AT91SAM7X \
-I./lwip-1.3.0/contrib/port/FreeRTOS/AT91SAM7X\arch \
-I../Source/include  \
-I../Source/portable/GCC/ARM7_AT91SAM7S  \
-I./lwip-1.3.0/src/include/ipv4 \
-I./Txs_generic \
-I./Txs_custom \
-I./Txs_http \
-Wall  \
-Wextra  \
-Wstrict-prototypes  \
-Wmissing-prototypes  \
-Wmissing-declarations  \
-Wno-strict-aliasing  \
-D SAM7_GCC \
-D THUMB_INTERWORK \
-mthumb-interwork \
-mcpu=arm7tdmi  \
-T$(LDSCRIPT) \
$(DEBUG)  \
$(OPTIM) \
-fomit-frame-pointer


THUMB_FLAGS=-mthumb
LINKER_FLAGS=-Xlinker -o$(PROJECT).elf -Xlinker -M -Xlinker -Map=$(PROJECT).map
--cref

#jlb
# Define ASM defines here
# List all default ASM defines here, like -D_DEBUG=1
DADEFS =
#CHIP  = at91sam7x256
CHIP  = at91sam7x512
UADEFS = -D$(CHIP)
ADEFS   = $(DADEFS) $(UADEFS) -D__ASSEMBLY__
ASFLAGS = -mcpu=arm7tdmi -g -gdwarf-2 -Wa,-amhls=$(<:.s=.lst) $(ADEFS)
-mthumb-interwork

#
# Source files that can be built to THUMB mode.
#
FREERTOS_THUMB_SRC= \
  ../Source/tasks.c \
  ../Source/queue.c \
  ../Source/list.c \
  ../Source/portable/GCC/ARM7_AT91SAM7S/port.c

DEMO_APP_THMUB_SRC= \
  ../Source/portable/MemMang/heap_2.c \
  ParTest/ParTest.c \
  Txs_custom/main.c \
  Txs_generic/io.c \
  ../Common/Minimal/flash.c \
  ../Common/Minimal/BlockQ.c \
  ../Common/Minimal/PollQ.c \
  ../Common/Minimal/semtest.c \
  TxsWEB.c \
  USB/USB-CDC.c \
  Txs_http/txs_httpd-fs.c \
  Txs_http/http-strings.c


LWIP_THUMB_SRC= \
  lwip-1.3.0/src/core/tcp_out.c \
  lwip-1.3.0/src/core/ipv4/inet.c \
  lwip-1.3.0/src/core/ipv4/inet_chksum.c \
  lwip-1.3.0/src/core/mem.c \
  lwip-1.3.0/src/core/memp.c \
  lwip-1.3.0/src/core/netif.c \
  lwip-1.3.0/src/core/init.c \
  lwip-1.3.0/src/core/pbuf.c \
  lwip-1.3.0/src/core/raw.c \
  lwip-1.3.0/src/core/stats.c \
  lwip-1.3.0/src/core/sys.c \
  lwip-1.3.0/src/core/tcp.c \
  lwip-1.3.0/src/core/tcp_in.c \
  lwip-1.3.0/src/core/ipv4/ip.c \
  lwip-1.3.0/src/core/ipv4/ip_addr.c \
  lwip-1.3.0/src/core/ipv4/icmp.c \
  lwip-1.3.0/src/netif/etharp.c \
  lwip-1.3.0/src/api/tcpip.c \
  lwip-1.3.0/src/api/netbuf.c \
  lwip-1.3.0/src/api/api_msg.c \
  lwip-1.3.0/src/api/err.c \
  lwip-1.3.0/src/api/api_lib.c \
  lwip-1.3.0/contrib/port/FreeRTOS/AT91SAM7X/sys_arch.c \
  lwip-1.3.0/src/netif/ethernetif.c \
  EMAC/SAM7_EMAC.c \
  lwip-1.3.0/src/core/udp.c \
  lwip-1.3.0/src/core/ipv4/ip_frag.c \
  lwip-1.3.0/src/core/dhcp.c \
  lwip-1.3.0/src/api/sockets.c

# List ASM source files here (jlb)
ASRC = boot.s

#
# Source files that must be built to ARM mode.
#
ARM_SRC= \
  ../Source/portable/GCC/ARM7_AT91SAM7S/portISR.c \
  EMAC/SAM7_EMAC_ISR.c \
  USB/USBIsr.c \
  Cstartup_SAM7.c  


#
# Define all object files.
#
ARM_OBJ = $(ARM_SRC:.c=.o)
FREERTOS_THUMB_OBJ = $(FREERTOS_THUMB_SRC:.c=.o)
DEMO_APP_THMUB_OBJ = $(DEMO_APP_THMUB_SRC:.c=.o)
LWIP_THUMB_OBJ = $(LWIP_THUMB_SRC:.c=.o)
BOOT_OBJ = $(ASRC:.s=.o)

#jlb
all: $(PROJECT).hex $(PROJECT).bin $(PROJECT).elf

$(PROJECT).bin : $(PROJECT).elf
        $(OBJCOPY) $(PROJECT).elf -O binary $(PROJECT).bin

$(PROJECT).hex : $(PROJECT).elf
        $(OBJCOPY) $(PROJECT).elf -O ihex $(PROJECT).hex
#jlb    
        $(OBJDUMP) $(ODFLAGS) $(PROJECT).elf > $(PROJECT).dm

$(PROJECT).elf : $(BOOT_OBJ) $(ARM_OBJ) $(DEMO_APP_THMUB_OBJ) $(LWIP_THUMB_OBJ)
$(FREERTOS_THUMB_OBJ) Makefile FreeRTOSConfig.h
        $(CC) $(CFLAGS) $(BOOT_OBJ) $(ARM_OBJ) $(DEMO_APP_THMUB_OBJ)
$(LWIP_THUMB_OBJ) $(FREERTOS_THUMB_OBJ) -nostartfiles $(LINKER_FLAGS)

$(DEMO_APP_THMUB_OBJ)  : %.o : %.c $(LDSCRIPT) Makefile FreeRTOSConfig.h
        $(CC) -c $(THUMB_FLAGS) $(CFLAGS) $< -o $@

$(LWIP_THUMB_OBJ)  : %.o : %.c $(LDSCRIPT) Makefile FreeRTOSConfig.h
        $(CC) -c $(THUMB_FLAGS) $(CFLAGS) $< -o $@

$(FREERTOS_THUMB_OBJ)  : %.o : %.c $(LDSCRIPT) Makefile FreeRTOSConfig.h
        $(CC) -c $(THUMB_FLAGS) $(CFLAGS) $< -o $@

$(ARM_OBJ) : %.o : %.c $(LDSCRIPT) Makefile FreeRTOSConfig.h
        $(CC) -c $(CFLAGS) $< -o $@

$(BOOT_OBJ) : %.o : %.s $(LDSCRIPT) Makefile FreeRTOSConfig.h
        $(AS) -c $(ASFLAGS) $< -o $@

clean:
        touch Makefile
#jlb    
        rm -f $(PROJECT).elf
        rm -f $(PROJECT).hex
        rm -f $(PROJECT).bin
        rm -f $(PROJECT).dm

#----------------------------
# added by JLB
#----------------------------
# specify output filename here (must be *.bin file)
TARGET = $(PROJECT).bin

# specify the directory where openocd executable resides (openocd-ftd2xx.exe or
openocd-pp.exe)
#OPENOCD_DIR = C:\Program Files\amontec\sdk4arm\ocd\openocd\bin
OPENOCD_DIR = C:\Program Files\openocd-r717\bin

# specify OpenOCD executable (pp is for the wiggler, ftd2xx is for the USB
debugger)
#OPENOCD = '$(OPENOCD_DIR)\openocd.exe'
OPENOCD = '$(OPENOCD_DIR)\openocd-ftd2xx.exe'

# specify OpenOCD configuration file (pick the one for your device)
OPENOCD_CFG = 'jtagkey-at91r40008-progflash.cfg'

# specify the name and folder of the flash programming script file
#OPENOCD_SCRIPT = Flashprog.ocd

# program the AT91SAM7S256 internal flash memory
#*****************
# Flashprog
#*****************
Flashprog: $(TARGET)
        @echo "Flash Programming with OpenOCD..."
        $(OPENOCD) -f $(OPENOCD_CFG)
        @echo "Flash Programming Finished."


-- 
           Summary: Function address passed as argument is incremented by 1
           Product: gcc
           Version: 4.2.2
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jlb dot for at free dot fr
 GCC build triplet: 4.2.2
  GCC host triplet: PC x86 windows XP
GCC target triplet: arm7


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37247


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]