On Wed, Apr 17, 2013 at 08:52:57PM -0400, Kirill Shklovsky wrote: > Dear avr-gcc-ers: > > It appears that a global SRAM uint8_t variable is placed at address > 0x060 by avr-gcc versions 4.6.2 and 7.3.2. The avr-gcc compiler was > compiled on cygwin. For example, given the followign AVR cpp code: > > volatile uint8_t latchingFlag; > > int main() { > > LED_PORT &= ~(1<<LED_BIT); > DDRD = 0xFF; > for (;;) { > latchingFlag=1; > if (latchingFlag==0) { > LED_PORT ^= 1<<LED_BIT; // Toggle the LED > _delay_ms(100); > latchingFlag = 1; > } > } > } > > The disassembly for the conditional looks as follows: > > if (latchingFlag==0) { > a0: 80 91 60 00 lds r24, 0x0060 > a4: 81 11 cpse r24, r1 > a6: fa cf rjmp .-12 ; 0x9c <main+0xc> > > At the same time, compiling this on avr-gcc 4.7.0 on Ubuntu I get: > > lds r24, 0x0100 > > Presumably 0x0100 is correct, since on ATmega 0x0060 is actually > mapped to the WDTCSR register, if I understand it correctly. Is this > a problem with the way I built avr-gcc or is this not an avr-gcc > issue? >
I don't see the problem when I tried compiling the below code with 4.6.2. Can you paste the command line you used, with -v and -Wl,--verbose turned on? It would be helpful to know what version of binutils was used, as well as the build steps. #include <stdint.h> volatile uint8_t x; int main() { x = 1; return x; } When I compile with /proj/builds/3.4.0/avr/install/bin/avr-gcc -mmcu=atmega328p -v test.c I get COLLECT_GCC=/proj/builds/3.4.0/avr/install/bin/avr-gcc COLLECT_LTO_WRAPPER=/data2/builds/3.4.0/avr/install/bin/../libexec/gcc/avr/4.6.2/lto-wrapper Target: avr Configured with: /proj/builds/3.4.0/avr/gcc-4.6.2/configure --prefix=/proj/builds/3.4.0/avr/install --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2 Thread model: single gcc version 4.6.2 (GCC) COLLECT_GCC_OPTIONS='-mmcu=atmega328p' '-v' /data2/builds/3.4.0/avr/install/bin/../libexec/gcc/avr/4.6.2/cc1 -quiet -v -imultilib avr5 -iprefix /data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/ test.c -quiet -dumpbase test.c -mmcu=atmega328p -auxbase test -version -o /tmp/cctr0ZVY.s GNU C (GCC) version 4.6.2 (avr) compiled by GNU C version 4.1.2 20080704 (Red Hat 4.1.2-52), GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C (GCC) version 4.6.2 (avr) compiled by GNU C version 4.1.2 20080704 (Red Hat 4.1.2-52), GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2 COLLECT_GCC_OPTIONS='-mmcu=atmega328p' '-v' /data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/../../../../avr/bin/as -mmcu=atmega328p -o /tmp/ccCbCXlO.o /tmp/cctr0ZVY.s COMPILER_PATH=/data2/builds/3.4.0/avr/install/bin/../libexec/gcc/avr/4.6.2/:/data2/builds/3.4.0/avr/install/bin/../libexec/gcc/:/data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/../../../../avr/bin/ LIBRARY_PATH=/data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/avr5/:/data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/../../../../avr/lib/avr5/:/data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/:/data2/builds/3.4.0/avr/install/bin/../lib/gcc/:/data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/../../../../avr/lib/ COLLECT_GCC_OPTIONS='-mmcu=atmega328p' '-v' /data2/builds/3.4.0/avr/install/bin/../libexec/gcc/avr/4.6.2/collect2 -m avr5 -Tdata 0x800100 /data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/../../../../avr/lib/avr5/crtm328p.o -L/data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/avr5 -L/data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/../../../../avr/lib/avr5 -L/data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2 -L/data2/builds/3.4.0/avr/install/bin/../lib/gcc -L/data2/builds/3.4.0/avr/install/bin/../lib/gcc/avr/4.6.2/../../../../avr/lib /tmp/ccCbCXlO.o -lgcc -lc -lgcc The -Tdata 0x800100 tells the linker that the data segment starts from 0x800100. The disassembly looks like this 000000a6 <main>: a6: cf 93 push r28 a8: df 93 push r29 aa: cd b7 in r28, 0x3d ; 61 ac: de b7 in r29, 0x3e ; 62 ae: 81 e0 ldi r24, 0x01 ; 1 b0: 80 93 00 01 sts 0x0100, r24 b4: 80 91 00 01 lds r24, 0x0100 b8: 88 2f mov r24, r24 ba: 90 e0 ldi r25, 0x00 ; 0 bc: df 91 pop r29 be: cf 91 pop r28 c0: 08 95 ret > Any help would be appreciated. > > Kirill > > _______________________________________________ > AVR-GCC-list mailing list > AVR-GCC-list@nongnu.org > https://lists.nongnu.org/mailman/listinfo/avr-gcc-list _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-gcc-list