broken code generation

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

broken code generation

avr-libc-devel
Hello friends.
A long time ago, more than 10 years ago, I used avr-gcc + avr-binutils +
avr-libc on Linux.
Today I had to compile a test project with a modern installation of
avr-gcc, avr-binutils, avr-libc.
And I noticed a strange assembler code in the listing: there is no
initialization of the stack, interrupt handlers are in an abnormal
place, the transition to the main function is missing ..
Can anyone comment on what is going on?

Command line to compile the project:
$ avr-gcc -iquote . -Os -pipe -mmcu=attiny2313 -mint8 -g -c -o blink.o
blink.c
$ avr-gcc blink.o -o blink.elf

Listing avr-objdump -h -S blink.elf:

---skip---
Disassembly of section .text:

00000000 <__do_clear_bss>:
    0:   20 e0           ldi     r18, 0x00       ; 0
    2:   a0 e6           ldi     r26, 0x60       ; 96
    4:   b0 e0           ldi     r27, 0x00       ; 0
    6:   01 c0           rjmp    .+2             ; 0xa <.do_clear_bss_start>

00000008 <.do_clear_bss_loop>:
    8:   1d 92           st      X+, r1

0000000a <.do_clear_bss_start>:
    a:   a1 36           cpi     r26, 0x61       ; 97
    c:   b2 07           cpc     r27, r18
    e:   e1 f7           brne    .-8             ; 0x8 <.do_clear_bss_loop>

00000010 <__vector_2>:
}

#endif


ISR(INT1_vect, ISR_BLOCK){
   10:   1f 92           push    r1
   12:   0f 92           push    r0
   14:   0f b6           in      r0, 0x3f        ; 63
   16:   0f 92           push    r0
   18:   11 24           eor     r1, r1
   1a:   8f 93           push    r24
   1c:   9f 93           push    r25
         PORTD ^= _BV(PORT5);
   1e:   92 b3           in      r25, 0x12       ; 18
   20:   80 e2           ldi     r24, 0x20       ; 32
   22:   89 27           eor     r24, r25
   24:   82 bb           out     0x12, r24       ; 18
}
   26:   9f 91           pop     r25
   28:   8f 91           pop     r24
   2a:   0f 90           pop     r0
   2c:   0f be           out     0x3f, r0        ; 63
   2e:   0f 90           pop     r0
   30:   1f 90           pop     r1
   32:   18 95           reti

00000034 <main>:
//        TIMSK = OCIE0A; //enable interrupt on compare match

         /*enable and tune INT1 */
--- skip ---

At the same time, I still have a listing from the project compilation
more than 10 years ago (the processor is not attiny2313):

---- skip ----
00000000 <__vectors>:
    0:   0c 94 2a 00     jmp     0x54
    4:   0c 94 45 00     jmp     0x8a
    8:   0c 94 45 00     jmp     0x8a
    c:   0c 94 45 00     jmp     0x8a
   10:   0c 94 45 00     jmp     0x8a
   14:   0c 94 45 00     jmp     0x8a
   18:   0c 94 45 00     jmp     0x8a
   1c:   0c 94 45 00     jmp     0x8a
   20:   0c 94 45 00     jmp     0x8a
   24:   0c 94 45 00     jmp     0x8a
   28:   0c 94 45 00     jmp     0x8a
   2c:   0c 94 45 00     jmp     0x8a
   30:   0c 94 45 00     jmp     0x8a
   34:   0c 94 45 00     jmp     0x8a
   38:   0c 94 45 00     jmp     0x8a
   3c:   0c 94 45 00     jmp     0x8a
   40:   0c 94 45 00     jmp     0x8a
   44:   0c 94 45 00     jmp     0x8a
   48:   0c 94 45 00     jmp     0x8a
   4c:   0c 94 45 00     jmp     0x8a
   50:   0c 94 45 00     jmp     0x8a

00000054 <__ctors_end>:
   54:   11 24           eor     r1, r1
   56:   1f be           out     0x3f, r1        ; 63
   58:   cf e5           ldi     r28, 0x5F       ; 95
   5a:   d8 e0           ldi     r29, 0x08       ; 8
   5c:   de bf           out     0x3e, r29       ; 62
   5e:   cd bf           out     0x3d, r28       ; 61

00000060 <__do_copy_data>:
   60:   10 e0           ldi     r17, 0x00       ; 0
   62:   a0 e6           ldi     r26, 0x60       ; 96
   64:   b0 e0           ldi     r27, 0x00       ; 0
   66:   e2 ea           ldi     r30, 0xA2       ; 162
   68:   f0 e0           ldi     r31, 0x00       ; 0
   6a:   02 c0           rjmp    .+4             ; 0x70

0000006c <.do_copy_data_loop>:
   6c:   05 90           lpm     r0, Z+
   6e:   0d 92           st      X+, r0

00000070 <.do_copy_data_start>:
   70:   a0 36           cpi     r26, 0x60       ; 96
   72:   b1 07           cpc     r27, r17
   74:   d9 f7           brne    .-10            ; 0x6c

00000076 <__do_clear_bss>:
   76:   10 e0           ldi     r17, 0x00       ; 0
   78:   a0 e6           ldi     r26, 0x60       ; 96
   7a:   b0 e0           ldi     r27, 0x00       ; 0
   7c:   01 c0           rjmp    .+2             ; 0x80

0000007e <.do_clear_bss_loop>:
   7e:   1d 92           st      X+, r1

00000080 <.do_clear_bss_start>:
   80:   a0 36           cpi     r26, 0x60       ; 96
   82:   b1 07           cpc     r27, r17
   84:   e1 f7           brne    .-8             ; 0x7e
   86:   0c 94 47 00     jmp     0x8e

0000008a <__bad_interrupt>:
   8a:   0c 94 00 00     jmp     0x0

0000008e <main>:
#include <avr/io.h>
int main (void){
   8e:   cf e5           ldi     r28, 0x5F       ; 95
---- skip ----

It looks right: interrupt vectors, stack initialization and everything else.

Friends, what am I doing wrong?

Thank you.

_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

Re: broken code generation

Joerg Wunsch
As avr-libc-devel wrote:

> Can anyone comment on what is going on?

Seems like a strange compiler build.

> Command line to compile the project:
> $ avr-gcc -iquote . -Os -pipe -mmcu=attiny2313 -mint8 -g -c -o blink.o
> blink.c

While I would not recommend using -mint8 (it has been deprecated for a
long time), the commandline looks basically OK.

You could add a -v to see more details.

Did you build the compiler yourself?
--
cheers, Joerg               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)

_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

Re: broken code generation

avr-libc-devel
> Seems like a strange compiler build.
In my opinion, the problem at the link stage: the object file after
compilation looks OK

>> Command line to compile the project:
>> $ avr-gcc -iquote . -Os -pipe -mmcu=attiny2313 -mint8 -g -c -o blink.o
>> blink.c
>
> While I would not recommend using -mint8 (it has been deprecated for a
> long time), the commandline looks basically OK.
Fine, I remove it.

> You could add a -v to see more details.
Yes, two ctages: compiling and then linking:
1.$ avr-gcc -iquote . -Os -pipe -mmcu=attiny2313 -g -v -c -o blink.o blink.c

Using built-in specs.
Reading specs from /usr/lib/gcc/avr/4.9.2/device-specs/specs-attiny2313
COLLECT_GCC=avr-gcc
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++
--prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man
--bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib
--enable-shared --with-system-zlib --enable-long-long --enable-nls
--without-included-gettext --disable-libssp --build=i686-linux-gnu
--host=i686-linux-gnu --target=avr CFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong -Wformat ' CPPFLAGS='-Wdate-time
-D_FORTIFY_SOURCE=2' CXXFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong -Wformat ' FCFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong' FFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong' GCJFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong' LDFLAGS=-Wl,-z,relro OBJCFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong -Wformat ' OBJCXXFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong -Wformat '
Thread model: single
gcc version 4.9.2 (GCC)
COLLECT_GCC_OPTIONS='-iquote' '.' '-Os' '-pipe'  '-g' '-v' '-c' '-o'
'blink.o' '-specs=device-specs/specs-attiny2313' '-mmcu=avr25' '-msp8'
  /usr/lib/gcc/avr/4.9.2/cc1 -quiet -v -imultilib avr25/tiny-stack
-D__AVR_ATtiny2313__ -D__AVR_DEVICE_NAME__=attiny2313 -iquote . blink.c
-mn-flash=1 -mno-skip-bug -quiet -dumpbase blink.c -mmcu=avr25 -msp8
-auxbase-strip blink.o -g -Os -version -o - |
  /usr/lib/gcc/avr/4.9.2/../../../avr/bin/as -mmcu=avr25 -mno-skip-bug
-o blink.o
GNU C (GCC) version 4.9.2 (avr)
         compiled by GNU C version 6.2.0 20160914, GMP version 6.1.1,
MPFR version 3.1.4-p2, MPC version 1.0.3
warning: GMP header version 6.1.1 differs from library version 6.1.2.
warning: MPFR header version 3.1.4-p2 differs from library version 3.1.5.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/usr/lib/gcc/avr/4.9.2/../../../avr/sys-include"
#include "..." search starts here:
  .
#include <...> search starts here:
  /usr/lib/gcc/avr/4.9.2/include
  /usr/lib/gcc/avr/4.9.2/include-fixed
  /usr/lib/gcc/avr/4.9.2/../../../avr/include
End of search list.
GNU C (GCC) version 4.9.2 (avr)
         compiled by GNU C version 6.2.0 20160914, GMP version 6.1.1,
MPFR version 3.1.4-p2, MPC version 1.0.3
warning: GMP header version 6.1.1 differs from library version 6.1.2.
warning: MPFR header version 3.1.4-p2 differs from library version 3.1.5.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: adb1813162fa70896e87bd1cd3f13704
COMPILER_PATH=/usr/lib/gcc/avr/4.9.2/:/usr/lib/gcc/avr/4.9.2/:/usr/lib/gcc/avr/:/usr/lib/gcc/avr/4.9.2/:/usr/lib/gcc/avr/:/usr/lib/gcc/avr/4.9.2/../../../avr/bin/
LIBRARY_PATH=/usr/lib/gcc/avr/4.9.2/avr25/tiny-stack/:/usr/lib/gcc/avr/4.9.2/../../../avr/lib/avr25/tiny-stack/:/usr/lib/gcc/avr/4.9.2/:/usr/lib/gcc/avr/4.9.2/../../../avr/lib/
COLLECT_GCC_OPTIONS='-iquote' '.' '-Os' '-pipe'  '-g' '-v' '-c' '-o'
'blink.o' '-specs=device-specs/specs-attiny2313' '-mmcu=avr25' '-msp8'

2.$ avr-gcc blink.o -v -o blink.elf

Using built-in specs.
Reading specs from /usr/lib/gcc/avr/4.9.2/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.9.2/lto-wrapper
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++
--prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man
--bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib
--enable-shared --with-system-zlib --enable-long-long --enable-nls
--without-included-gettext --disable-libssp --build=i686-linux-gnu
--host=i686-linux-gnu --target=avr CFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong -Wformat ' CPPFLAGS='-Wdate-time
-D_FORTIFY_SOURCE=2' CXXFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong -Wformat ' FCFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong' FFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong' GCJFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong' LDFLAGS=-Wl,-z,relro OBJCFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong -Wformat ' OBJCXXFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-IRBaON/gcc-avr-4.9.2+Atmel3.5.3=.
-fstack-protector-strong -Wformat '
Thread model: single
gcc version 4.9.2 (GCC)
COMPILER_PATH=/usr/lib/gcc/avr/4.9.2/:/usr/lib/gcc/avr/4.9.2/:/usr/lib/gcc/avr/:/usr/lib/gcc/avr/4.9.2/:/usr/lib/gcc/avr/:/usr/lib/gcc/avr/4.9.2/../../../avr/bin/
LIBRARY_PATH=/usr/lib/gcc/avr/4.9.2/:/usr/lib/gcc/avr/4.9.2/../../../avr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'blink.elf' '-specs=device-specs/specs-avr2'
  /usr/lib/gcc/avr/4.9.2/collect2 -plugin
/usr/lib/gcc/avr/4.9.2/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/avr/4.9.2/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccKYdDXH.res
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lm
-plugin-opt=-pass-through=-lc -o blink.elf -L/usr/lib/gcc/avr/4.9.2
-L/usr/lib/gcc/avr/4.9.2/../../../avr/lib blink.o --start-group -lgcc
-lm -lc --end-group

> Did you build the compiler yourself?
No, this is a standard installation in Debian 9.7 (and the situation is
the same in modern ArchLinux)

Thank you for your reply. I hope to get something to understand.

_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

Re: broken code generation

avr-libc-devel
In reply to this post by Joerg Wunsch
> Seems like a strange compiler build.
If this can be useful, I will provide an user account in Debian 9.7,
where I try to compile the project — you can try your thoughts on this
installation, if you wish.

_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

Re: broken code generation

Joerg Wunsch
In reply to this post by avr-libc-devel
As avr-libc-devel wrote:

> >Seems like a strange compiler build.
> In my opinion, the problem at the link stage: the object file after
> compilation looks OK

Yes, but the linker is driven by the compiler.

> 2.$ avr-gcc blink.o -v -o blink.elf

Your linker call is missing the -mmcu option.

That's why no startup code has been scheduled to link against.
--
cheers, Joerg               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)

_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

Re: broken code generation

avr-libc-devel
> Your linker call is missing the -mmcu option.
> That's why no startup code has been scheduled to link against.
OMG, thank you, it works :)

_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev