This fixes PR51345: lib1funcs.S accesses SPH register even on devices that don't have it.
There are 2 issues with SPH here: * Reading non-existent SFR * Assuming SPH = 0 lead to smaller code for devices without SPH Devices with 8-bit SP are the ones that need size optimizations most This patch does the following: * It auto-generates MULTILIB_OPTIONS, MULTILIB_MATCHES, MULTILIB_DIRNAMES, MULTILIB_EXCEPTIONS from info provided by avr-mcus.def * It maps devices with 8-bit SP to their multilib default. GCC's genmultilib does not allow to map combination of switches to specific multilib. Therefore, an avr-specific multilib.h is generated whose purpose is to override multilib_raw[] from multilib.h. Even if genmultilib provided a feature to facilitate mapping set of options to specific multilib, is would be desirable to auto-generate respective MULTILIB_* variables from avr-mcus.def in order to keep information in /one/ place: avr-mcus.def. Moreover, MULTILIB has over 150 entries and will grow even larger in the future. The script that performs the work is genmultilib.awk. It is not as general as genmultilib (but way easier to read) and needs to treat special cases that arise from SPH/non-SPH requirement. If new devices/cores are added to avr-mcus.def all will work out of the box. Adding new multlilib option like -f[no]short-double, however, will need extension of genmultilib.awk. Beside approving from AVR maintainer this has to be coordinated with avr-libc because that support library has its own understanding of how multilib structure looks like. With the patch it looks like so: . ./tiny-stack ./avr25 ./avr25/tiny-stack ./avr3 ./avr31 ./avr35 ./avr4 ./avr5 ./avr51 ./avr6 -mtiny-stack is a partial multilib option now: This switch affects multilib choice for devices in avr2 and avr25. Devices in other cores are not affected; they all have SPH and IMHO it's too much of splitting as to make mtiny-stack a full-featured multilib option doubling the number of multilibs. Some examples: -print-multi-directory -mmcu=attiny44 -> avr25 -print-multi-directory -mmcu=attiny44 -mtiny-stack -> avr25/tiny-stack -print-multi-directory -mmcu=attiny44 -mno-tiny-stack -> avr25 -print-multi-directory -mmcu=at90s2313 -> tiny-stack -print-multi-directory -mmcu=at90s2313 -mtiny-stack -> tiny-stack -print-multi-directory -mmcu=at90s2313 -mno-tiny-stack -> tiny-stack Linking with current version still works. However there are multilibs missing in avr-libc build because of current avr-libc build system: Default "." will be used for, e.g. "-mmcu=attiny44 -mtiny-stack" will trigger ./libc.a instead of ./avr25/tiny-stack/libc.a The reason is that there is no ./avr25/tiny-stack/libc.a built and the multlilib-picker falls back to ./libc.a. Ok for trunk? If okay from maintainers, I will wait for the commit until Joerg has agreed. Johann contrib/ PR target/51345 * gcc_update (files_and_dependencies): Add gcc/config/avr/t-multilib, gcc/config/avr/multilib.h. libgcc/ PR target/51345 * config/avr/lib1funcs.S: Remove FIXME comments. gcc/ PR target/51345 * config.gcc (tm_file [target=avr]): Add avr/avr-multilib.h (tmake_file [target=avr]): Add avr/t-multilib. * config/avr/genmultilib.awk: New file. * config/avr/t-multilib: New auto-generated file. * config/avr/multilib.h: New auto-generated file. * config/avr/t-avr (AVR_MCUS): New variable. (genopt.sh): Use it. (s-mlib): Depend on t-multilib. (t-multilib, multilib.h): New dependencies. (s-avr-mlib): New rule to build t-multilib, multilib.h from AVR_MCUS. (MULTILIB_OPTIONS): Remove. (MULTILIB_MATCHES): Remove. (MULTILIB_DIRNAMES): Remove. (MULTILIB_EXCEPTIONS): Remove: * config/avr/genopt.sh: Don't use hard coded file name; pass AVR_MCUS from t-avr instead.
Index: contrib/gcc_update =================================================================== --- contrib/gcc_update (revision 182277) +++ contrib/gcc_update (working copy) @@ -82,6 +82,8 @@ gcc/fixinc/fixincl.x: gcc/fixinc/fixincl gcc/config/arm/arm-tune.md: gcc/config/arm/arm-cores.def gcc/config/arm/gentune.sh gcc/config/arm/arm-tables.opt: gcc/config/arm/arm-arches.def gcc/config/arm/arm-cores.def gcc/config/arm/arm-fpus.def gcc/config/arm/genopt.sh gcc/config/avr/avr-tables.opt: gcc/config/avr/avr-mcus.def gcc/config/avr/genopt.sh +gcc/config/avr/t-multilib: gcc/config/avr/avr-mcus.def gcc/config/avr/genmultilib.awk +gcc/config/avr/multilib.h: gcc/config/avr/avr-mcus.def gcc/config/avr/genmultilib.awk gcc/config/c6x/c6x-tables.opt: gcc/config/c6x/c6x-isas.def gcc/config/c6x/genopt.sh gcc/config/c6x/c6x-sched.md: gcc/config/c6x/c6x-sched.md.in gcc/config/c6x/gensched.sh gcc/config/c6x/c6x-mult.md: gcc/config/c6x/c6x-mult.md.in gcc/config/c6x/genmult.sh Index: libgcc/config/avr/lib1funcs.S =================================================================== --- libgcc/config/avr/lib1funcs.S (revision 182328) +++ libgcc/config/avr/lib1funcs.S (working copy) @@ -1540,9 +1540,6 @@ DEFUN __divdi3_moddi3 4: ;; Epilogue: Restore the Z = 12 Registers and return in r28, __SP_L__ #if defined (__AVR_HAVE_8BIT_SP__) -;; FIXME: __AVR_HAVE_8BIT_SP__ is set on device level, not on core level -;; so this lines are dead code. To make it work, devices without -;; SP_H must get their own multilib(s). clr r29 #else in r29, __SP_H__ @@ -1627,9 +1624,6 @@ DEFUN __prologue_saves__ push r28 push r29 #if defined (__AVR_HAVE_8BIT_SP__) -;; FIXME: __AVR_HAVE_8BIT_SP__ is set on device level, not on core level -;; so this lines are dead code. To make it work, devices without -;; SP_H must get their own multilib(s). in r28,__SP_L__ sub r28,r26 out __SP_L__,r28 @@ -1679,9 +1673,6 @@ DEFUN __epilogue_restores__ ldd r17,Y+3 ldd r26,Y+2 #if defined (__AVR_HAVE_8BIT_SP__) -;; FIXME: __AVR_HAVE_8BIT_SP__ is set on device level, not on core level -;; so this lines are dead code. To make it work, devices without -;; SP_H must get their own multilib(s). ldd r29,Y+1 add r28,r30 out __SP_L__,r28 Index: gcc/config.gcc =================================================================== --- gcc/config.gcc (revision 182277) +++ gcc/config.gcc (working copy) @@ -909,13 +909,14 @@ arm*-wince-pe*) extra_objs="pe.o" ;; avr-*-rtems*) - tm_file="elfos.h avr/elf.h avr/avr.h dbxelf.h avr/rtems.h rtems.h newlib-stdint.h" - tmake_file="avr/t-avr t-rtems avr/t-rtems" + tm_file="elfos.h avr/elf.h avr/avr.h avr/multilib.h dbxelf.h avr/rtems.h rtems.h newlib-stdint.h" + tmake_file="avr/t-avr avr/t-multilib t-rtems avr/t-rtems" extra_gcc_objs="driver-avr.o avr-devices.o" extra_objs="avr-devices.o avr-log.o" ;; avr-*-*) - tm_file="elfos.h avr/elf.h avr/avr.h dbxelf.h newlib-stdint.h" + tm_file="elfos.h avr/elf.h avr/avr.h avr/multilib.h dbxelf.h newlib-stdint.h" + tmake_file="avr/t-avr avr/t-multilib" use_gcc_stdint=wrap extra_gcc_objs="driver-avr.o avr-devices.o" extra_objs="avr-devices.o avr-log.o" Index: gcc/config/avr/t-multilib =================================================================== --- gcc/config/avr/t-multilib (revision 0) +++ gcc/config/avr/t-multilib (revision 0) @@ -0,0 +1,174 @@ +# Auto-generated Makefile Snip +# Generated by : ./gcc/config/avr/genmultilib.awk +# Generated from : ./gcc/config/avr/avr-mcus.def +# Used by : tmake_file from Makefile and genmultilib + +MULTILIB_OPTIONS = mmcu=avr2/mmcu=avr25/mmcu=avr3/mmcu=avr31/mmcu=avr35/mmcu=avr4/mmcu=avr5/mmcu=avr51/mmcu=avr6 mtiny-stack + +MULTILIB_DIRNAMES = avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 tiny-stack avr25/tiny-stack + +MULTILIB_EXCEPTIONS = \ + mmcu=avr3/mtiny-stack \ + mmcu=avr31/mtiny-stack \ + mmcu=avr35/mtiny-stack \ + mmcu=avr4/mtiny-stack \ + mmcu=avr5/mtiny-stack \ + mmcu=avr51/mtiny-stack \ + mmcu=avr6/mtiny-stack + +MULTILIB_MATCHES = \ + mmcu?at90s2313=mmcu?at90s2313 \ + mmcu?at90s2323=mmcu?at90s2323 \ + mmcu?at90s2333=mmcu?at90s2333 \ + mmcu?at90s2343=mmcu?at90s2343 \ + mmcu?attiny22=mmcu?attiny22 \ + mmcu?attiny26=mmcu?attiny26 \ + mmcu?at90s4433=mmcu?at90s4433 \ + mmcu?avr25=mmcu?ata6289 \ + mmcu?attiny13=mmcu?attiny13 \ + mmcu?avr25=mmcu?attiny13 \ + mmcu?attiny13a=mmcu?attiny13a \ + mmcu?avr25=mmcu?attiny13a \ + mmcu?attiny2313=mmcu?attiny2313 \ + mmcu?avr25=mmcu?attiny2313 \ + mmcu?attiny2313a=mmcu?attiny2313a \ + mmcu?avr25=mmcu?attiny2313a \ + mmcu?attiny24=mmcu?attiny24 \ + mmcu?avr25=mmcu?attiny24 \ + mmcu?attiny24a=mmcu?attiny24a \ + mmcu?avr25=mmcu?attiny24a \ + mmcu?avr25=mmcu?attiny4313 \ + mmcu?avr25=mmcu?attiny44 \ + mmcu?avr25=mmcu?attiny44a \ + mmcu?avr25=mmcu?attiny84 \ + mmcu?avr25=mmcu?attiny84a \ + mmcu?attiny25=mmcu?attiny25 \ + mmcu?avr25=mmcu?attiny25 \ + mmcu?avr25=mmcu?attiny45 \ + mmcu?avr25=mmcu?attiny85 \ + mmcu?attiny261=mmcu?attiny261 \ + mmcu?avr25=mmcu?attiny261 \ + mmcu?attiny261a=mmcu?attiny261a \ + mmcu?avr25=mmcu?attiny261a \ + mmcu?avr25=mmcu?attiny461 \ + mmcu?avr25=mmcu?attiny461a \ + mmcu?avr25=mmcu?attiny861 \ + mmcu?avr25=mmcu?attiny861a \ + mmcu?avr25=mmcu?attiny43u \ + mmcu?avr25=mmcu?attiny87 \ + mmcu?avr25=mmcu?attiny48 \ + mmcu?avr25=mmcu?attiny88 \ + mmcu?avr25=mmcu?at86rf401 \ + mmcu?avr3=mmcu?at43usb355 \ + mmcu?avr3=mmcu?at76c711 \ + mmcu?avr31=mmcu?atmega103 \ + mmcu?avr31=mmcu?at43usb320 \ + mmcu?avr35=mmcu?at90usb82 \ + mmcu?avr35=mmcu?at90usb162 \ + mmcu?avr35=mmcu?atmega8u2 \ + mmcu?avr35=mmcu?atmega16u2 \ + mmcu?avr35=mmcu?atmega32u2 \ + mmcu?avr35=mmcu?attiny167 \ + mmcu?avr4=mmcu?atmega8 \ + mmcu?avr4=mmcu?atmega48 \ + mmcu?avr4=mmcu?atmega48a \ + mmcu?avr4=mmcu?atmega48p \ + mmcu?avr4=mmcu?atmega88 \ + mmcu?avr4=mmcu?atmega88a \ + mmcu?avr4=mmcu?atmega88p \ + mmcu?avr4=mmcu?atmega88pa \ + mmcu?avr4=mmcu?atmega8515 \ + mmcu?avr4=mmcu?atmega8535 \ + mmcu?avr4=mmcu?atmega8hva \ + mmcu?avr4=mmcu?at90pwm1 \ + mmcu?avr4=mmcu?at90pwm2 \ + mmcu?avr4=mmcu?at90pwm2b \ + mmcu?avr4=mmcu?at90pwm3 \ + mmcu?avr4=mmcu?at90pwm3b \ + mmcu?avr4=mmcu?at90pwm81 \ + mmcu?avr5=mmcu?atmega16 \ + mmcu?avr5=mmcu?atmega16a \ + mmcu?avr5=mmcu?atmega161 \ + mmcu?avr5=mmcu?atmega162 \ + mmcu?avr5=mmcu?atmega163 \ + mmcu?avr5=mmcu?atmega164a \ + mmcu?avr5=mmcu?atmega164p \ + mmcu?avr5=mmcu?atmega165 \ + mmcu?avr5=mmcu?atmega165a \ + mmcu?avr5=mmcu?atmega165p \ + mmcu?avr5=mmcu?atmega168 \ + mmcu?avr5=mmcu?atmega168a \ + mmcu?avr5=mmcu?atmega168p \ + mmcu?avr5=mmcu?atmega169 \ + mmcu?avr5=mmcu?atmega169a \ + mmcu?avr5=mmcu?atmega169p \ + mmcu?avr5=mmcu?atmega169pa \ + mmcu?avr5=mmcu?atmega32 \ + mmcu?avr5=mmcu?atmega323 \ + mmcu?avr5=mmcu?atmega324a \ + mmcu?avr5=mmcu?atmega324p \ + mmcu?avr5=mmcu?atmega324pa \ + mmcu?avr5=mmcu?atmega325 \ + mmcu?avr5=mmcu?atmega325a \ + mmcu?avr5=mmcu?atmega325p \ + mmcu?avr5=mmcu?atmega3250 \ + mmcu?avr5=mmcu?atmega3250a \ + mmcu?avr5=mmcu?atmega3250p \ + mmcu?avr5=mmcu?atmega328 \ + mmcu?avr5=mmcu?atmega328p \ + mmcu?avr5=mmcu?atmega329 \ + mmcu?avr5=mmcu?atmega329a \ + mmcu?avr5=mmcu?atmega329p \ + mmcu?avr5=mmcu?atmega329pa \ + mmcu?avr5=mmcu?atmega3290 \ + mmcu?avr5=mmcu?atmega3290a \ + mmcu?avr5=mmcu?atmega3290p \ + mmcu?avr5=mmcu?atmega406 \ + mmcu?avr5=mmcu?atmega64 \ + mmcu?avr5=mmcu?atmega640 \ + mmcu?avr5=mmcu?atmega644 \ + mmcu?avr5=mmcu?atmega644a \ + mmcu?avr5=mmcu?atmega644p \ + mmcu?avr5=mmcu?atmega644pa \ + mmcu?avr5=mmcu?atmega645 \ + mmcu?avr5=mmcu?atmega645a \ + mmcu?avr5=mmcu?atmega645p \ + mmcu?avr5=mmcu?atmega6450 \ + mmcu?avr5=mmcu?atmega6450a \ + mmcu?avr5=mmcu?atmega6450p \ + mmcu?avr5=mmcu?atmega649 \ + mmcu?avr5=mmcu?atmega649a \ + mmcu?avr5=mmcu?atmega649p \ + mmcu?avr5=mmcu?atmega6490 \ + mmcu?avr5=mmcu?atmega16hva \ + mmcu?avr5=mmcu?atmega16hva2 \ + mmcu?avr5=mmcu?atmega16hvb \ + mmcu?avr5=mmcu?atmega32hvb \ + mmcu?avr5=mmcu?atmega64hve \ + mmcu?avr5=mmcu?at90can32 \ + mmcu?avr5=mmcu?at90can64 \ + mmcu?avr5=mmcu?at90pwm216 \ + mmcu?avr5=mmcu?at90pwm316 \ + mmcu?avr5=mmcu?atmega32c1 \ + mmcu?avr5=mmcu?atmega64c1 \ + mmcu?avr5=mmcu?atmega16m1 \ + mmcu?avr5=mmcu?atmega32m1 \ + mmcu?avr5=mmcu?atmega64m1 \ + mmcu?avr5=mmcu?atmega16u4 \ + mmcu?avr5=mmcu?atmega32u4 \ + mmcu?avr5=mmcu?atmega32u6 \ + mmcu?avr5=mmcu?at90scr100 \ + mmcu?avr5=mmcu?at90usb646 \ + mmcu?avr5=mmcu?at90usb647 \ + mmcu?avr5=mmcu?at94k \ + mmcu?avr5=mmcu?m3000 \ + mmcu?avr51=mmcu?atmega128 \ + mmcu?avr51=mmcu?atmega1280 \ + mmcu?avr51=mmcu?atmega1281 \ + mmcu?avr51=mmcu?atmega1284p \ + mmcu?avr51=mmcu?atmega128rfa1 \ + mmcu?avr51=mmcu?at90can128 \ + mmcu?avr51=mmcu?at90usb1286 \ + mmcu?avr51=mmcu?at90usb1287 \ + mmcu?avr6=mmcu?atmega2560 \ + mmcu?avr6=mmcu?atmega2561 Index: gcc/config/avr/t-avr =================================================================== --- gcc/config/avr/t-avr (revision 182327) +++ gcc/config/avr/t-avr (working copy) @@ -34,156 +34,29 @@ avr-log.o: $(srcdir)/config/avr/avr-log. $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(INPUT_H) $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< -$(srcdir)/config/avr/avr-tables.opt: $(srcdir)/config/avr/genopt.sh \ - $(srcdir)/config/avr/avr-mcus.def - $(SHELL) $(srcdir)/config/avr/genopt.sh $(srcdir)/config/avr > \ - $(srcdir)/config/avr/avr-tables.opt - -MULTILIB_OPTIONS = mmcu=avr2/mmcu=avr25/mmcu=avr3/mmcu=avr31/mmcu=avr35/mmcu=avr4/mmcu=avr5/mmcu=avr51/mmcu=avr6 -MULTILIB_DIRNAMES = avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 - -# The many avr2 matches are not listed here - this is the default. -MULTILIB_MATCHES = \ - mmcu?avr25=mmcu?ata6289 \ - mmcu?avr25=mmcu?attiny13 \ - mmcu?avr25=mmcu?attiny13a \ - mmcu?avr25=mmcu?attiny2313 \ - mmcu?avr25=mmcu?attiny2313a \ - mmcu?avr25=mmcu?attiny4313 \ - mmcu?avr25=mmcu?attiny24 \ - mmcu?avr25=mmcu?attiny24a \ - mmcu?avr25=mmcu?attiny44 \ - mmcu?avr25=mmcu?attiny44a \ - mmcu?avr25=mmcu?attiny84 \ - mmcu?avr25=mmcu?attiny84a \ - mmcu?avr25=mmcu?attiny25 \ - mmcu?avr25=mmcu?attiny45 \ - mmcu?avr25=mmcu?attiny85 \ - mmcu?avr25=mmcu?attiny261 \ - mmcu?avr25=mmcu?attiny261a \ - mmcu?avr25=mmcu?attiny461 \ - mmcu?avr25=mmcu?attiny461a \ - mmcu?avr25=mmcu?attiny861 \ - mmcu?avr25=mmcu?attiny861a \ - mmcu?avr25=mmcu?attiny43u \ - mmcu?avr25=mmcu?attiny87 \ - mmcu?avr25=mmcu?attiny48 \ - mmcu?avr25=mmcu?attiny88 \ - mmcu?avr25=mmcu?at86rf401 \ - mmcu?avr3=mmcu?at43usb355 \ - mmcu?avr3=mmcu?at76c711 \ - mmcu?avr31=mmcu?atmega103 \ - mmcu?avr31=mmcu?at43usb320 \ - mmcu?avr35=mmcu?at90usb82 \ - mmcu?avr35=mmcu?at90usb162 \ - mmcu?avr35=mmcu?atmega8u2 \ - mmcu?avr35=mmcu?atmega16u2 \ - mmcu?avr35=mmcu?atmega32u2 \ - mmcu?avr35=mmcu?attiny167 \ - mmcu?avr4=mmcu?atmega48 \ - mmcu?avr4=mmcu?atmega48a \ - mmcu?avr4=mmcu?atmega48p \ - mmcu?avr4=mmcu?atmega8 \ - mmcu?avr4=mmcu?atmega8515 \ - mmcu?avr4=mmcu?atmega8535 \ - mmcu?avr4=mmcu?atmega88 \ - mmcu?avr4=mmcu?atmega88a \ - mmcu?avr4=mmcu?atmega88p \ - mmcu?avr4=mmcu?atmega88pa \ - mmcu?avr4=mmcu?atmega8hva \ - mmcu?avr4=mmcu?at90pwm1 \ - mmcu?avr4=mmcu?at90pwm2 \ - mmcu?avr4=mmcu?at90pwm2b \ - mmcu?avr4=mmcu?at90pwm3 \ - mmcu?avr4=mmcu?at90pwm3b \ - mmcu?avr4=mmcu?at90pwm81 \ - mmcu?avr5=mmcu?atmega16 \ - mmcu?avr5=mmcu?atmega16a \ - mmcu?avr5=mmcu?atmega161 \ - mmcu?avr5=mmcu?atmega162 \ - mmcu?avr5=mmcu?atmega163 \ - mmcu?avr5=mmcu?atmega164a \ - mmcu?avr5=mmcu?atmega164p \ - mmcu?avr5=mmcu?atmega165 \ - mmcu?avr5=mmcu?atmega165a \ - mmcu?avr5=mmcu?atmega165p \ - mmcu?avr5=mmcu?atmega168 \ - mmcu?avr5=mmcu?atmega168a \ - mmcu?avr5=mmcu?atmega168p \ - mmcu?avr5=mmcu?atmega169 \ - mmcu?avr5=mmcu?atmega169a \ - mmcu?avr5=mmcu?atmega169p \ - mmcu?avr5=mmcu?atmega169pa \ - mmcu?avr5=mmcu?atmega32 \ - mmcu?avr5=mmcu?atmega323 \ - mmcu?avr5=mmcu?atmega324a \ - mmcu?avr5=mmcu?atmega324p \ - mmcu?avr5=mmcu?atmega324pa \ - mmcu?avr5=mmcu?atmega325 \ - mmcu?avr5=mmcu?atmega325a \ - mmcu?avr5=mmcu?atmega325p \ - mmcu?avr5=mmcu?atmega3250 \ - mmcu?avr5=mmcu?atmega3250a \ - mmcu?avr5=mmcu?atmega3250p \ - mmcu?avr5=mmcu?atmega328 \ - mmcu?avr5=mmcu?atmega328p \ - mmcu?avr5=mmcu?atmega329 \ - mmcu?avr5=mmcu?atmega329a \ - mmcu?avr5=mmcu?atmega329p \ - mmcu?avr5=mmcu?atmega329pa \ - mmcu?avr5=mmcu?atmega3290 \ - mmcu?avr5=mmcu?atmega3290a \ - mmcu?avr5=mmcu?atmega3290p \ - mmcu?avr5=mmcu?atmega406 \ - mmcu?avr5=mmcu?atmega64 \ - mmcu?avr5=mmcu?atmega640 \ - mmcu?avr5=mmcu?atmega644 \ - mmcu?avr5=mmcu?atmega644a \ - mmcu?avr5=mmcu?atmega644p \ - mmcu?avr5=mmcu?atmega644pa \ - mmcu?avr5=mmcu?atmega645 \ - mmcu?avr5=mmcu?atmega645a \ - mmcu?avr5=mmcu?atmega645p \ - mmcu?avr5=mmcu?atmega6450 \ - mmcu?avr5=mmcu?atmega6450a \ - mmcu?avr5=mmcu?atmega6450p \ - mmcu?avr5=mmcu?atmega649 \ - mmcu?avr5=mmcu?atmega649a \ - mmcu?avr5=mmcu?atmega649p \ - mmcu?avr5=mmcu?atmega6490 \ - mmcu?avr5=mmcu?atmega6490a \ - mmcu?avr5=mmcu?atmega6490p \ - mmcu?avr5=mmcu?atmega16hva \ - mmcu?avr5=mmcu?atmega16hva2 \ - mmcu?avr5=mmcu?atmega16hvb \ - mmcu?avr5=mmcu?atmega32hvb \ - mmcu?avr5=mmcu?atmega64hve \ - mmcu?avr5=mmcu?at90can32 \ - mmcu?avr5=mmcu?at90can64 \ - mmcu?avr5=mmcu?at90pwm216 \ - mmcu?avr5=mmcu?at90pwm316 \ - mmcu?avr5=mmcu?atmega32c1 \ - mmcu?avr5=mmcu?atmega64c1 \ - mmcu?avr5=mmcu?atmega16m1 \ - mmcu?avr5=mmcu?atmega32m1 \ - mmcu?avr5=mmcu?atmega64m1 \ - mmcu?avr5=mmcu?atmega16u4 \ - mmcu?avr5=mmcu?atmega32u4 \ - mmcu?avr5=mmcu?atmega32u6 \ - mmcu?avr5=mmcu?at90scr100 \ - mmcu?avr5=mmcu?at90usb646 \ - mmcu?avr5=mmcu?at90usb647 \ - mmcu?avr5=mmcu?at94k \ - mmcu?avr5=mmcu?m3000 \ - mmcu?avr51=mmcu?atmega128 \ - mmcu?avr51=mmcu?atmega1280 \ - mmcu?avr51=mmcu?atmega1281 \ - mmcu?avr51=mmcu?atmega1284p \ - mmcu?avr51=mmcu?atmega128rfa1 \ - mmcu?avr51=mmcu?at90can128 \ - mmcu?avr51=mmcu?at90usb1286 \ - mmcu?avr51=mmcu?at90usb1287 \ - mmcu?avr6=mmcu?atmega2560 \ - mmcu?avr6=mmcu?atmega2561 +# Files and Variables auto-generated from avr-mvus.def -MULTILIB_EXCEPTIONS = +AVR_MCUS = $(srcdir)/config/avr/avr-mcus.def + +$(srcdir)/config/avr/avr-tables.opt: $(srcdir)/config/avr/genopt.sh $(AVR_MCUS) + $(SHELL) $< $(AVR_MCUS) > $@ + +# MULTILIB_OPTIONS +# MULTILIB_DIRNAMES +# MULTILIB_EXCEPTIONS +# MULTILIB_MATCHES +$(srcdir)/config/avr/t-multilib: s-avr-mlib; @true + +# Override multilib_raw[] from multilib.h +$(srcdir)/config/avr/multilib.h: s-avr-mlib; @true + +s-mlib: $(srcdir)/config/avr/t-multilib + +s-avr-mlib: $(srcdir)/config/avr/genmultilib.awk $(AVR_MCUS) + $(AWK) -f $< -v FORMAT=Makefile $(AVR_MCUS) > tmp-avr-mlib + $(AWK) -f $< -v FORMAT=multilib.h $(AVR_MCUS) > tmp-avr-mlib.h + $(SHELL) $(srcdir)/../move-if-change \ + tmp-avr-mlib.h $(srcdir)/config/avr/multilib.h + $(SHELL) $(srcdir)/../move-if-change \ + tmp-avr-mlib $(srcdir)/config/avr/t-multilib + $(STAMP) $@ Index: gcc/config/avr/avr-mcus.def =================================================================== --- gcc/config/avr/avr-mcus.def (revision 182327) +++ gcc/config/avr/avr-mcus.def (working copy) @@ -21,7 +21,6 @@ /* List of all known AVR MCU types - if updated, it has to be kept in sync in several places (FIXME: is there a better way?): - here; - - t-avr (MULTILIB_MATCHES); - gas/config/tc-avr.c; - avr-libc. Index: gcc/config/avr/genmultilib.awk =================================================================== --- gcc/config/avr/genmultilib.awk (revision 0) +++ gcc/config/avr/genmultilib.awk (revision 0) @@ -0,0 +1,255 @@ +################################################################## +# +# Transform Core/Device Information from avr-mcus.def to a +# Representation that is understood by GCC's multilib Machinery. +# +# The script works as a filter from STDIN to STDOUT. +# +# FORMAT = "Makefile": Generate Makefile Snipet that sets some +# MULTILIB_* Variables as needed. +# +# FORMAT = "multilib.h": Generate C Header intended to override +# (parts of) multilib.h used in gcc.c. +# +################################################################## + +BEGIN { + FS ="[(, \t]+" + option[""] = "" + tiny_stack[""] = 1 + + mtiny[0] = "" + mtiny[1] = "tiny-stack" + option["tiny-stack"] = "mtiny-stack" +} + +################################################################## +# Run over all AVR_MCU lines and gather information: +# cores[] : Enumerates the Cores (avr2, avr25, ...) +# mcu[] : Enumerates the Devices +# tiny_stack[]: Maps Core/Device to 0 (2-byte SP) or 1 (1-byte SP) +# option[] : Maps Core/Device to the mmcu= option to get it +# toCore[] : Maps Device to its Core +################################################################## + +/^AVR_MCU/ { + name = $2 + gsub ("\"", "", name) + + if ($4 == "NULL") + { + core = name + + # avr1 is supported for Assembler only: It gets no multilib + if (core == "avr1") + next + + cores[length (cores)] = core + tiny_stack[core] = 0 + option[core] = "mmcu=" core + + next + } + + # avr1 is supported for Assembler only: Its Devices are ignored + if (core == "avr1") + next + + tiny_stack[name] = $5 + mcu[length (mcu)] = name + option[name] = "mmcu=" name + toCore[name] = core + + if (tiny_stack[name] == 1) + tiny_stack[core] = 1 +} + +################################################################## +# +# We gathered all the Information, now build/output the following: +# +# awk Variable target Variable FORMAT +# ----------------------------------------------------------- +# m_options <-> MULTILIB_OPTIONS Makefile +# m_dirnames <-> MULTILIB_DIRNAMES " +# m_exceptions <-> MULTILIB_EXCEPTIONS " +# m_matches <-> MULTILIB_MATCHES " +# m_raw <-> avr_multilib_raw multilib.h +# +################################################################## + +END { + m_options = "\nMULTILIB_OPTIONS = " + m_dirnames = "\nMULTILIB_DIRNAMES =" + m_exceptions = "\nMULTILIB_EXCEPTIONS =" + m_matches = "\nMULTILIB_MATCHES =" + + m_raw = "" + + ############################################################## + # Compose MULTILIB_OPTIONS. This represents the Cross-Product + # (avr2, avr25, ...) x mtiny-stack + + sep = "" + for (c = 0; c < length (cores); c++) + { + m_options = m_options sep option[cores[c]] + sep = "/" + } + + # The ... x mtiny-stack + m_options = m_options " " option[mtiny[1]] + + ############################################################## + # Map Device to its multilib + + # All Mappings that cannot be represented by GCC's genmultilib + # Machinery must be handcrafted. + + dot_excludes = "" + m_raw_sp8 = "" + + for (t = 0; t < length (mcu); t++) + { + core = toCore[mcu[t]] + + if (tiny_stack[mcu[t]] == 1) + { + if (core == "avr2") + dir = mtiny[1] + else + dir = core "/" mtiny[1] + + m_raw_sp8 = m_raw_sp8 " \"" dir " " option[mcu[t]] ";\",\n" + dot_excludes = dot_excludes " !" option[mcu[t]] + + line = option[mcu[t]] ":" option[mcu[t]] + gsub ("=", "?", line) + gsub (":", "=", line) + + m_matches = m_matches " \\\n\t" line + } + + # The SP = 16 Devices are vanilla: Do the same as + # MULTILIB_MATCHES would yield. Don't list avr2 (default) + + if (core != "avr2") + { + line = option[core] ":" option[mcu[t]] + gsub ("=", "?", line) + gsub (":", "=", line) + + m_matches = m_matches " \\\n\t" line + } + } + + #################################################################### + # Compose MULTILIB_DIRNAMES, MULTILIB_EXEPTIONS and avr_multilib_raw + + for (t = 0; t < length (mtiny); t++) + for (c = -1; c < length (cores); c++) + { + if (c == -1) + core = "" + else + core = cores[c] + + # The Directory Name for this multilib + + if (core != "" && mtiny[t] != "") + { + mdir = core "/" mtiny[t] + mopt = option[core] "/" option[mtiny[t]] + } + else + { + mdir = core mtiny[t] + mopt = option[core] option[mtiny[t]] + } + + if (core != "" && tiny_stack[core] == 0 && mtiny[t] != "") + { + # There's not a single SP = 8 Devices for this Core: + # Don't build respective multilib + m_exceptions = m_exceptions " \\\n\t" mopt + continue + } + + if (core != "avr2" || mtiny[t] == "") + m_dirnames = m_dirnames " " mdir + + # Remainder deals with avr_multilib_raw Entries. + # Each Entry looks like + # "multilib-dir option-to-match !option-to-avoid-match;" + # for Example: + # "avr25/tiny-stack !mmcu=avr2 mmcu=avr25 !mmcu=avr3 ... mtiny-stack;" + + if (mdir == "") + mdir = "." + + line = mdir + + for (s = 0; s < length (cores); s++) + { + if (cores[s] == core) + line = line " " option[cores[s]] + else + line = line " !" option[cores[s]] + } + + if (tiny_stack[core] != 0) + { + if (mtiny[t] == "") + line = line " !" option[mtiny[1]] + else + line = line " " option[mtiny[1]] + } + + if (mdir == ".") + line = line dot_excludes + + m_raw = m_raw " \"" line ";\",\n" + } + + ############################################################ + # Output that Stuff + ############################################################ + + if (FORMAT == "Makefile") + { + # Intended Target: ./gcc/config/avr/t-multilib + + print "# Auto-generated Makefile Snip" + print "# Generated by : ./gcc/config/avr/genmultilib.awk" + print "# Generated from : ./gcc/config/avr/avr-mcus.def" + print "# Used by : tmake_file from Makefile and genmultilib" + print m_options + print m_dirnames + print m_exceptions + print m_matches + } + + if (FORMAT == "multilib.h") + { + # Intended Target: ./gcc/config/avr/multilib.h + + print "/*" + print " Auto-generated C header" + print " Generated by : ./gcc/config/avr/genmultilib.awk" + print " Generated from : ./gcc/config/avr/avr-mcus.def" + print " Used by : ./gcc/gcc.c via tm.h" + print " Purpose : Override multilib_raw[] from multilib.h" + print "*/" + print "#ifndef AVR_MULTILIB_H" + print "#define AVR_MULTILIB_H" + + print "static const char* const avr_multilib_raw[] = {" + print m_raw_sp8 + print m_raw + print " (const char*) 0\n};" + + print "#undef multilib_raw" + print "#define multilib_raw avr_multilib_raw" + print "#endif /* AVR_MULTILIB_H */" + } +} Index: gcc/config/avr/genopt.sh =================================================================== --- gcc/config/avr/genopt.sh (revision 182327) +++ gcc/config/avr/genopt.sh (working copy) @@ -56,4 +56,4 @@ awk -F'[(, ]+' 'BEGIN { print "Enum(avr_mcu) String(" name ") Value(" value ")" print "" value++ -}' $1/avr-mcus.def +}' $1 Index: gcc/config/avr/multilib.h =================================================================== --- gcc/config/avr/multilib.h (revision 0) +++ gcc/config/avr/multilib.h (revision 0) @@ -0,0 +1,46 @@ +/* + Auto-generated C header + Generated by : ./gcc/config/avr/genmultilib.awk + Generated from : ./gcc/config/avr/avr-mcus.def + Used by : ./gcc/gcc.c via tm.h + Purpose : Override multilib_raw[] from multilib.h +*/ +#ifndef AVR_MULTILIB_H +#define AVR_MULTILIB_H +static const char* const avr_multilib_raw[] = { + "tiny-stack mmcu=at90s2313;", + "tiny-stack mmcu=at90s2323;", + "tiny-stack mmcu=at90s2333;", + "tiny-stack mmcu=at90s2343;", + "tiny-stack mmcu=attiny22;", + "tiny-stack mmcu=attiny26;", + "tiny-stack mmcu=at90s4433;", + "avr25/tiny-stack mmcu=attiny13;", + "avr25/tiny-stack mmcu=attiny13a;", + "avr25/tiny-stack mmcu=attiny2313;", + "avr25/tiny-stack mmcu=attiny2313a;", + "avr25/tiny-stack mmcu=attiny24;", + "avr25/tiny-stack mmcu=attiny24a;", + "avr25/tiny-stack mmcu=attiny25;", + "avr25/tiny-stack mmcu=attiny261;", + "avr25/tiny-stack mmcu=attiny261a;", + + ". !mmcu=avr2 !mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6 !mtiny-stack !mmcu=at90s2313 !mmcu=at90s2323 !mmcu=at90s2333 !mmcu=at90s2343 !mmcu=attiny22 !mmcu=attiny26 !mmcu=at90s4433 !mmcu=attiny13 !mmcu=attiny13a !mmcu=attiny2313 !mmcu=attiny2313a !mmcu=attiny24 !mmcu=attiny24a !mmcu=attiny25 !mmcu=attiny261 !mmcu=attiny261a;", + "avr2 mmcu=avr2 !mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6 !mtiny-stack;", + "avr25 !mmcu=avr2 mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6 !mtiny-stack;", + "avr3 !mmcu=avr2 !mmcu=avr25 mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6;", + "avr31 !mmcu=avr2 !mmcu=avr25 !mmcu=avr3 mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6;", + "avr35 !mmcu=avr2 !mmcu=avr25 !mmcu=avr3 !mmcu=avr31 mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6;", + "avr4 !mmcu=avr2 !mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6;", + "avr5 !mmcu=avr2 !mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 mmcu=avr5 !mmcu=avr51 !mmcu=avr6;", + "avr51 !mmcu=avr2 !mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 mmcu=avr51 !mmcu=avr6;", + "avr6 !mmcu=avr2 !mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 mmcu=avr6;", + "tiny-stack !mmcu=avr2 !mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6 mtiny-stack;", + "avr2/tiny-stack mmcu=avr2 !mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6 mtiny-stack;", + "avr25/tiny-stack !mmcu=avr2 mmcu=avr25 !mmcu=avr3 !mmcu=avr31 !mmcu=avr35 !mmcu=avr4 !mmcu=avr5 !mmcu=avr51 !mmcu=avr6 mtiny-stack;", + + (const char*) 0 +}; +#undef multilib_raw +#define multilib_raw avr_multilib_raw +#endif /* AVR_MULTILIB_H */