[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] gcc 3.0.4/binutuils 2.11.2 patches for c++ support
From: |
Jan Beutel |
Subject: |
Re: [avr-gcc-list] gcc 3.0.4/binutuils 2.11.2 patches for c++ support |
Date: |
23 Apr 2002 15:41:24 +0200 |
maybe it is worthwhile to note that the c++ patch needs to be applied
before the at128 patch...
On Thu, 2002-03-07 at 00:51, Peter Jansen wrote:
> Hi All,
>
> Attached are patches for binutils, gcc, c++ support.
>
> These are for gcc-3.0.4, binutils-2.11.2.
>
> to use these get the binutils 2.11.2, gcc 3.0.4 source package,
>
> untar the sources,apply the patches, configure the packages, make the
> package and install them.
>
> eg. (this puts the build files in a different directory)
>
> tar xvzf binutils-2.11.2
> cd binutils-2.11.2
> patch -p1 < binutils-2.11.2-patchc++
> cd ..
> mkdir build-binutils
> cd build-binutils
> ../binutils-2.11.2/configure --target=avr
> (lots of output)
> make
> (lots of output)
> make install (as root)
> (lots more output)
>
> tar xvzf gcc-3.0.4
> cd gcc-3.0.4
> patch -p1 < gcc-3.0.4-patchc++
> cd ..
> mkdir build-gcc
> cd build-gcc
> ../gcc/configure --target=avr --enable-languages=c
> (lots of output)
> make
> (lots of output)
> make install (as root)
> (lots more output)
>
> You will also need avr-libc also, configure and make this as per its
> instructions. I have sent a patch for avr-libc to support c++ you will
> need to get that and configure/make/install avr-libc also.
>
> Once avr-libc is installed re-build gcc with --enable-languages=c,c++
>
> Thanks to Theodore A. Roth <address@hidden> for helping check some of
> these patches.
>
>
> --
> Peter Jansen
> Smart Container
> Level 1, NIC Building
> Eveleigh
> NSW 1430
> AUSTRALIA
> ----
>
> diff -urN binutils-2.11.2/ld/scripttempl/elf32avr.sc
> binutils-2.11.2-patchc++/ld/scripttempl/elf32avr.sc
> --- binutils-2.11.2/ld/scripttempl/elf32avr.sc Tue Nov 14 09:26:38 2000
> +++ binutils-2.11.2-patchc++/ld/scripttempl/elf32avr.sc Thu Feb 28
> 12:19:16 2002
> @@ -21,7 +21,7 @@
> .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
>
> .rel.init ${RELOCATING-0} : { *(.rel.init) }
> - .rela.init ${RELOCATING-0} : { *(.rela.init) }
> + .rela.init ${RELOCATING-0} : { *(.rela.init) }
> .rel.text ${RELOCATING-0} :
> {
> *(.rel.text)
> @@ -35,7 +35,7 @@
> ${RELOCATING+*(.rela.gnu.linkonce.t*)}
> }
> .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
> - .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
> + .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
> .rel.rodata ${RELOCATING-0} :
> {
> *(.rel.rodata)
> @@ -74,6 +74,14 @@
> /* Internal text space or external memory */
> .text :
> {
> + *(.init0)
> + *(.init1)
> + *(.init2)
> + *(.init3)
> + *(.init4)
> + *(.init5)
> + *(.init6)
> + *(.init7)
> *(.init)
> *(.progmem.gcc*)
> *(.progmem*)
> @@ -82,28 +90,55 @@
> ${RELOCATING+. = ALIGN(2);}
> *(.text.*)
> ${RELOCATING+. = ALIGN(2);}
> - *(.fini)
> + ${RELOCATING+__CTOR_LIST__ = .;}
> + *(.ctors)
> + ${RELOCATING+__CTOR_END__ = .;}
> ${RELOCATING+ _etext = . ; }
> } ${RELOCATING+ > text}
>
> + /* We don't want these in an embedded system, if you want
> + * them put them in the .text section above */
> + /DISCARD/ :
> + {
> + *(.fini)
> + *(.fini7)
> + *(.fini6)
> + *(.fini5)
> + *(.fini4)
> + *(.fini3)
> + *(.fini2)
> + *(.fini1)
> + *(.fini0)
> +/* ${RELOCATING+__DTOR_LIST__ = .;} */
> + *(.dtors)
> +/* ${RELOCATING+__DTOR_END__ = .;} */
> + }
> +
> .data ${RELOCATING-0} : ${RELOCATING+AT (ADDR (.text) + SIZEOF
> (.text))}
> {
> - ${RELOCATING+ PROVIDE (__data_start = .) ; }
> *(.data)
> *(.gnu.linkonce.d*)
> ${RELOCATING+. = ALIGN(2);}
> ${RELOCATING+ _edata = . ; }
> } ${RELOCATING+ > data}
>
> + ${RELOCATING+__data_length = SIZEOF(.data);}
> + ${RELOCATING+__data_start = ADDR(.data);}
> + ${RELOCATING+__data_end = __data_start + SIZEOF(.data);}
> + ${RELOCATING+__data_load_start = LOADADDR(.data);}
> + ${RELOCATING+__data_load_end = __data_load_start + SIZEOF(.data);}
> +
> .bss ${RELOCATING+ SIZEOF(.data) + ADDR(.data)} :
> {
> - ${RELOCATING+ PROVIDE (__bss_start = .) ; }
> *(.bss)
> *(COMMON)
> - ${RELOCATING+ PROVIDE (__bss_end = .) ; }
> ${RELOCATING+ _end = . ; }
> } ${RELOCATING+ > data}
>
> + ${RELOCATING+__bss_length = SIZEOF(.bss);}
> + ${RELOCATING+__bss_start = LOADADDR(.bss);}
> + ${RELOCATING+__bss_end = __bss_start + SIZEOF(.bss);}
> +
> .eeprom ${RELOCATING-0}:
> ${RELOCATING+AT (ADDR (.text) + SIZEOF (.text) + SIZEOF (.data))}
> {
> ----
>
> diff -urN gcc-3.0.4/configure.in gcc-3.0.4-patchc++/configure.in
> --- gcc-3.0.4/configure.in Tue Aug 14 02:14:49 2001
> +++ gcc-3.0.4-patchc++/configure.in Wed Feb 27 12:44:28 2002
> @@ -713,6 +713,9 @@
> arm-*-riscix*)
> noconfigdirs="$noconfigdirs ld target-libgloss ${libgcj}"
> ;;
> + avr-*-*)
> + noconfigdirs="$noconfigdirs target-libiberty ${libstdcxx_version}
> ${libgcj}"
> + ;;
> d10v-*-*)
> noconfigdirs="$noconfigdirs target-librx ${libstdcxx_version}
> target-libgloss ${libgcj}"
> ;;
> diff -urN gcc-3.0.4/gcc/config/avr/avr.h
> gcc-3.0.4-patchc++/gcc/config/avr/avr.h
> --- gcc-3.0.4/gcc/config/avr/avr.h Tue Apr 17 04:25:42 2001
> +++ gcc-3.0.4-patchc++/gcc/config/avr/avr.h Tue Mar 5 15:35:38 2002
> @@ -1982,22 +1982,84 @@
>
>
> #define TEXT_SECTION_ASM_OP "\t.text"
> +
> /* A C expression whose value is a string containing the assembler
> operation that should precede instructions and read-only data.
> Normally `"\t.text"' is right. */
>
> #define DATA_SECTION_ASM_OP "\t.data"
> +
> /* A C expression whose value is a string containing the assembler
> operation to identify the following data as writable initialized
> data. Normally `"\t.data"' is right. */
>
> -#define EXTRA_SECTIONS in_progmem
> +#define CONST_SECTION_ASM_OP "\t.section\t.rodata"
> +
> +#define BSS_SECTION_ASM_OP "\t.section\t.bss"
> +
> +/* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
> +
> + Note that we want to give these sections the SHF_WRITE attribute
> + because these sections will actually contain data (i.e. tables of
> + addresses of functions in the current root executable or shared library
> + file) and, in the case of a shared library, the relocatable addresses
> + will have to be properly resolved/relocated (and then written into) by
> + the dynamic linker when it actually attaches the given shared library
> + to the executing process. (Note that on SVR4, you may wish to use the
> + `-z text' option to the ELF linker, when building a shared library, as
> + an additional check that you are doing everything right. But if you do
> + use the `-z text' option when building a shared library, you will get
> + errors unless the .ctors and .dtors sections are marked as writable
> + via the SHF_WRITE attribute.) */
> +
> +#define CTORS_SECTION_ASM_OP "\t.section\t.ctors,\"aw\""
> +#define DTORS_SECTION_ASM_OP "\t.section\t.dtors,\"aw\""
> +
> +/* On svr4, we *do* have support for the .init and .fini sections, and we
> + can put stuff in there to be executed before and after `main'. We let
> + crtstuff.c and other files know this by defining the following symbols.
> + The definitions say how to change sections to the .init and .fini
> + sections. This is the same for all known svr4 assemblers. */
> +
> +#define INIT_SECTION_ASM_OP "\t.section\t.init"
> +#define FINI_SECTION_ASM_OP "\t.section\t.fini"
> +
> +#define CTORS_SECTION_FUNCTION \
> +void \
> +ctors_section () \
> +{ \
> + if (in_section != in_ctors) \
> + { \
> + fprintf (asm_out_file, "\t.globl\t__do_global_ctors\n"); \
> + fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP); \
> + in_section = in_ctors; \
> + } \
> +}
> +
> +#define DTORS_SECTION_FUNCTION \
> +void \
> +dtors_section () \
> +{ \
> + if (in_section != in_dtors) \
> + { \
> + fprintf (asm_out_file, "\t.globl\t__do_global_dtors\n"); \
> + fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP); \
> + in_section = in_dtors; \
> + } \
> +}
> +
> +#define EXTRA_SECTIONS in_progmem, in_ctors, in_dtors
> /* A list of names for sections other than the standard two, which are
> `in_text' and `in_data'. You need not define this macro on a
> system with no other sections (that GCC needs to use). */
>
> -#define EXTRA_SECTION_FUNCTIONS
> \
> - \
> +#undef EXTRA_SECTION_FUNCTIONS
> +#define EXTRA_SECTION_FUNCTIONS \
> + PROGMEM_SECTION_FUNCTION \
> + CTORS_SECTION_FUNCTION \
> + DTORS_SECTION_FUNCTION
> +
> +#define PROGMEM_SECTION_FUNCTION \
> void \
> progmem_section (void)
> \
> { \
> @@ -2011,6 +2073,45 @@
> in_section = in_progmem;
> \
> }
> \
> }
> +
> +/* This is the pseudo-op used to generate a reference to a specific
> + symbol in some section. It is only used in machine-specific
> + configuration files, typically only in ASM_OUTPUT_CONSTRUCTOR and
> + ASM_OUTPUT_DESTRUCTOR. This is the same for all known svr4
> + assemblers, except those in targets that don't use 32-bit pointers.
> + Those should override INT_ASM_OP. Yes, the name of the macro is
> + misleading. */
> +
> +#ifndef INT_ASM_OP
> +#define INT_ASM_OP "\t.short\t"
> +#endif
> +
> +
> +/* A C statement (sans semicolon) to output an
> + element in the table of global constructors. */
> +#define ASM_OUTPUT_CONSTRUCTOR(FILE, NAME) \
> + do \
> + { \
> + ctors_section (); \
> + fprintf (FILE, "%spm(", INT_ASM_OP); \
> + assemble_name (FILE, NAME); \
> + fprintf (FILE, ")\t;; constructor is a word address\n"); \
> + } \
> + while (0)
> +
> +/* A C statement (sans semicolon) to output an
> + element in the table of global destructors. */
> +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \
> + do \
> + { \
> + dtors_section (); \
> + fprintf (FILE, "%spm(", INT_ASM_OP); \
> + assemble_name (FILE, NAME); \
> + fprintf (FILE, ")\t;; destructor is a word address\n"); \
> + } \
> + while (0)
> +
> +
> /* `EXTRA_SECTION_FUNCTIONS'
> One or more functions to be defined in `varasm.c'. These
> functions should do jobs analogous to those of `text_section' and
> @@ -2244,6 +2345,21 @@
> These macros are provided by `real.h' for writing the definitions of
> `ASM_OUTPUT_DOUBLE' and the like: */
>
> +#define ASM_OUTPUT_BSS(STREAM, DECL, NAME, SIZE, ROUNDED) \
> + asm_output_bss(STREAM, DECL, NAME, SIZE, ROUNDED)
> +
> +/* A C statement (sans semicolon) to output to the stdio stream
> + STREAM the assembler definition of a bss named NAME whose
> + size is SIZE bytes. The variable ROUNDED is the size rounded up
> + to whatever alignment the caller wants.
> +
> + Use the expression `assemble_name (STREAM, NAME)' to output the
> + name itself; before and after that, output the additional
> + assembler syntax for defining the name, and a newline.
> +
> + This macro controls how the assembler definitions of uninitialized
> + global variables are output. */
> +
> #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED)
> \
> do { \
> fputs ("\t.comm ", (STREAM)); \
> @@ -3031,6 +3147,10 @@
>
> Do not define this macro if it does not need to do anything. */
>
> +#define CC1PLUS_SPEC "%{!frtti:-fno-rtti} \
> + %{!fenforce-eh-specs:-fno-enforce-eh-specs} \
> + %{!fexceptions:-fno-exceptions}"
> +
> #define ASM_SPEC "%{mmcu=*:-mmcu=%*}"
> /* A C string constant that tells the GNU CC driver program options to
> pass to the assembler. It can also specify how to translate
> @@ -3086,6 +3206,9 @@
> If this macro is not defined, a default is provided that loads the
> standard C library from the usual place. See `gcc.c'. */
>
> +#define LIBSTDCXX "-lcpp"
> +/* library to add by default for c++ linkage, this defaults to -lstdc++ */
> +
> #define LIBGCC_SPEC \
> "%{!mmcu=at90s1*:%{!mmcu=attiny1*:%{!mmcu=attiny28: -lgcc }}}"
> /* Another C string constant that tells the GNU CC driver program how
> diff -urN gcc-3.0.4/gcc/config/avr/libgcc.S
> gcc-3.0.4-patchc++/gcc/config/avr/libgcc.S
> --- gcc-3.0.4/gcc/config/avr/libgcc.S Sun Apr 1 02:36:08 2001
> +++ gcc-3.0.4-patchc++/gcc/config/avr/libgcc.S Wed Feb 27 16:47:10 2002
> @@ -31,6 +31,7 @@
> #define __SREG__ 0x3f
> #define __SP_H__ 0x3e
> #define __SP_L__ 0x3d
> +#define __RAMPZ__ 0x3b
>
> /* Most of the functions here are called directly from avr.md
> patterns, instead of using the standard libcall mechanisms.
> @@ -674,3 +675,78 @@
> .endfunc
> #endif /* defined (L_tablejump) */
>
> +#ifdef L_ctor
> + .sect .init5,"ax",@progbits
> + .globl __do_global_ctors
> +;;
> +;; Run through constructor table.
> +;; This needs to be run before main is called.
> +;;
> +#define ZH r31
> +#define ZL r30
> +#define XH r27
> +#define XL r26
> +
> +__do_global_ctors:
> +#if defined (__AVR_ENHANCED__) && defined (__AVR_MEGA__)
> + ldi ZL, lo8(__CTOR_LIST__)
> + ldi ZH, hi8(__CTOR_LIST__)
> + ldi r16, hh8(__CTOR_LIST__) ; init the RAMPZ value
> + out __RAMPZ__, r16
> +_ctorsLoop:
> + cpi ZL, lo8(__CTOR_END__)
> + brne _do_ctor ; Branch if low Z not equal to CTOR_END
> + cpi ZH, hi8(__CTOR_END__)
> + brne _do_ctor ; Branch if high Z not equal to CTOR_END
> + jmp _ctors_done
> +_do_ctor:
> + elpm XL, Z+
> + elpm XH, Z+ ; post-increment will automatically handle RAMPZ
> + push ZL
> + push ZH
> + movw ZL, XL
> + icall
> + pop ZH
> + pop ZL
> + jmp _ctorsLoop
> +#endif /* AVR_ENHANCED, AVR_MEGA */
> +_ctors_done:
> +#endif /* L_ctor */
> +
> +#ifdef L_dtor
> + .sect .fini5,"ax",@progbits
> + .globl __do_global_dtors
> +;;
> +;; Run through the destructor table.
> +;; This needs to be run in the exit function.
> +;;
> +#define ZH r31
> +#define ZL r30
> +#define XH r27
> +#define XL r26
> +
> +__do_global_dtors:
> +#if defined (__AVR_ENHANCED__) && defined (__AVR_MEGA__)
> + ldi ZL, lo8(__DTOR_LIST__)
> + ldi ZH, hi8(__DTOR_LIST__)
> + ldi r16, hh8(__DTOR_LIST__) ; init the RAMPZ value
> + out __RAMPZ__, r16
> +_dtorsLoop:
> + cpi r30, lo8(__DTOR_END__)
> + brne _do_dtor ; Branch if low Z not equal to DTOR_END
> + cpi r31, hi8(__DTOR_END__)
> + brne _do_dtor ; Branch if high Z not equal to DTOR_END
> + jmp _dtors_done
> +_do_dtor:
> + elpm XL, Z+
> + elpm XH, Z+ ; post-increment will automatically handle RAMPZ
> + push ZL
> + push ZH
> + movw ZL, XL
> + icall
> + pop ZH
> + pop ZL
> + jmp _dtorsLoop
> +#endif /* AVR_ENHANCED, AVR_MEGA */
> +_dtors_done:
> +#endif /* L_dtor */
> diff -urN gcc-3.0.4/gcc/config/avr/t-avr
> gcc-3.0.4-patchc++/gcc/config/avr/t-avr
> --- gcc-3.0.4/gcc/config/avr/t-avr Sun Jan 21 03:49:01 2001
> +++ gcc-3.0.4-patchc++/gcc/config/avr/t-avr Wed Feb 27 12:44:28 2002
> @@ -18,7 +18,9 @@
> _epilogue \
> _exit \
> _cleanup \
> - _tablejump
> + _tablejump \
> + _ctor \
> + _dtor
>
> # libgcc...
> LIBGCC1_TEST =
--
Jan Beutel address@hidden
Computer Engineering and Networks Laboratory, ETZ G63
ETH Zurich +41 1 632 70 32 Phone
Gloriastrasse 35 +41 1 632 10 35 Fax
CH 8092 Zurich/Switzerland http://www.tik.ee.ethz.ch/~beutel
avr-gcc-list at http://avr1.org
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [avr-gcc-list] gcc 3.0.4/binutuils 2.11.2 patches for c++ support,
Jan Beutel <=