We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

AR# 21265

7.1 EDK-GNU - mb-gcc - abs() function does not word align


Keywords: mb-gcc, abs, shift_temp, bss, word alignment

Urgency: Standard

General Description:
This is a bug exposed by the move to GCC 3.4.1.

GCC now moves the declaration "int <var> = 0;" into BSS as an optimization. However, the code for emitting alignment directives for these BSS symbols contains a bug. Instead of using the assembler directive ".comm," it is now using the assembler directive ".space." This directive is not required to be aligned, hence it is not being aligned by the linker. There is a misalignment occurring at _shift_temp_loc.

EDK63 vs EDK71

abs() function is compiled differently in EDK 71 than it was in EDK 63.

I have a customer that moved to EDK 71 and is using the same code with no modifications. Since his algorithm is not working in 71 when it did in 63, he brought this to my attention. Can anyone explain why the SWI command is not word aligned in 71?
-ReXpMag and ReXp are both Xilinx types Xint16; they are declared locally in a function.
-My optimization setting is "No optimization".
-ZeroDlyCnt is a global variable, type Xuint8, declared outside all functions and main.
Notice I have an unsigned character (byte) variable at address 0x1a84;
the line at address 0x1384 does a SWI to address 0x1a85; but, the SWI
must be word-aligned, which means it is overwriting my variable.
In the old disassemble code the target address of the SWI was 0x1b4c and
my variable was at 0x1b94.
Both disassemblies were compiled from the same C code.
EDK 71 mb-gcc non working algorithm
C-code snippet
ReXpMag = abs(ReXp);
ImXpMag = abs(ImXp);
Objectdump snippet
if (ZeroDlyCnt == 0)
12ac: e0601a84 lbui r3, r0, 6788 // 1a84
12b0: bc23001c bnei r3, 28 // 12cc
ReXpMag = abs(ReXp);
137c: e4730004 lhui r3, r19, 4
1380: 90630061 sext16 r3, r3
1384: f8601a85 swi r3, r0, 6789 // 1a85
1388: e2401a85 lbui r18, r0, 6789 // 1a85
138c: 90920060 sext8 r4, r18
1390: 90840001 sra r4, r4
1394: 90840001 sra r4, r4
1398: 90840001 sra r4, r4
139c: 90840001 sra r4, r4
13a0: 90840001 sra r4, r4
13a4: 90840001 sra r4, r4
13a8: 90840001 sra r4, r4
13ac: 88641800 xor r3, r4, r3
13b0: 14641800 rsubk r3, r4, r3
13b4: f4730008 shi r3, r19, 8
EDK 63 mb-gcc working algorithm
C-code snippet
ReXpMag = abs(ReXp);
ImXpMag = abs(ImXp);
Objectdump snippet
13b8: e0601b94 lbui r3, r0, 7060 // 1b94 <ZeroDlyCnt>
13bc: bc23001c bnei r3, 28 // 13d8
1488: c4809800 lhu r4, r0, r19
148c: 90640061 sext16 r3, r4
1490: f8601b4c swi r3, r0, 6988 // 1b4c <_shift_temp_loc>
1494: e2401b4c lbui r18, r0, 6988 // 1b4c <_shift_temp_loc>
1498: 90920060 sext8 r4, r18
149c: 90840001 sra r4, r4
14a0: 90840001 sra r4, r4
14a4: 90840001 sra r4, r4
14a8: 90840001 sra r4, r4
14ac: 90840001 sra r4, r4
14b0: 90840001 sra r4, r4
14b4: 90840001 sra r4, r4
14b8: 88641800 xor r3, r4, r3
14bc: 14841800 rsubk r4, r4, r3
14c0: f4930004 shi r4, r19, 4



Currently, to work around the issue above, create a new file from the text below and compile with user C source.

//Start of file
// Copyright (c) 2001 Xilinx, Inc. All rights reserved.
// mb_variables.c
// MicroBlaze specific variables required by certain operations
// a) shift
// $Header: /devl/xcs/repo/env/Jobs/MDT/sw/ThirdParty/gnu/src/gcc/src-3.4/gcc/config/microblaze/mb_variables.c,v 1.1 2005/03/18 20:00:25 vasanth Exp $

/* This variable is need by shift operations */
int _shift_temp_loc;

// End of file


This problem has been fixed in the latest EDK 7.1i Service Pack available at:
The first service pack containing the fix is EDK 7.1i Service Pack 1.
AR# 21265
Date 04/13/2007
Status Archive
Type General Article