From: Jozef Lawrynowicz Date: Mon, 4 Nov 2019 11:23:46 +0000 (+0000) Subject: MSP430: Add -mtiny-printf option X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=02afb6a9321fbfb435452636cedc2cd43f0c4fd2;p=gcc.git MSP430: Add -mtiny-printf option 2019-11-04 Jozef Lawrynowicz gcc/ * config.in: Regenerate. * config/msp430/msp430.c (msp430_option_override): Emit an error if -mtiny-printf is used without GCC being configured with --enable-newlib-nano-formatted-io. * config/msp430/msp430.h (LINK_SPEC): Pass "--wrap puts --wrap printf" when -mtiny-printf is used. * config/msp430/msp430.opt: Document -mtiny-printf. * configure: Regenerate. * configure.ac: Enable --enable-newlib-nano-formatted-io flag. Define HAVE_NEWLIB_NANO_FORMATTED_IO if --enable-newlib-nano-formatted-io is passed. * doc/invoke.texi: Document -mtiny-printf. gcc/testsuite/ * gcc.target/msp430/tiny-printf.c: New test. From-SVN: r277774 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6f0bd8381a0..193e8e40d19 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2019-11-04 Jozef Lawrynowicz + + * config.in: Regenerate. + * config/msp430/msp430.c (msp430_option_override): Emit an error if + -mtiny-printf is used without GCC being configured with + --enable-newlib-nano-formatted-io. + * config/msp430/msp430.h (LINK_SPEC): Pass + "--wrap puts --wrap printf" when -mtiny-printf is used. + * config/msp430/msp430.opt: Document -mtiny-printf. + * configure: Regenerate. + * configure.ac: Enable --enable-newlib-nano-formatted-io flag. + Define HAVE_NEWLIB_NANO_FORMATTED_IO if + --enable-newlib-nano-formatted-io is passed. + * doc/invoke.texi: Document -mtiny-printf. + 2019-11-04 Jozef Lawrynowicz * configure: Regenerate. diff --git a/gcc/config.in b/gcc/config.in index c0baa761fcd..e2afcbc8940 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -1688,6 +1688,13 @@ #endif +/* Define if GCC has been configured with --enable-newlib-nano-formatted-io. + */ +#ifndef USED_FOR_TARGET +#undef HAVE_NEWLIB_NANO_FORMATTED_IO +#endif + + /* Define to 1 if you have the `nl_langinfo' function. */ #ifndef USED_FOR_TARGET #undef HAVE_NL_LANGINFO diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c index b5d3edb42d0..4ebdcf51e8b 100644 --- a/gcc/config/msp430/msp430.c +++ b/gcc/config/msp430/msp430.c @@ -287,6 +287,12 @@ msp430_option_override (void) possible to build newlib with -Os enabled. Until now... */ if (TARGET_OPT_SPACE && optimize < 3) optimize_size = 1; + +#ifndef HAVE_NEWLIB_NANO_FORMATTED_IO + if (TARGET_TINY_PRINTF) + error ("GCC must be configured with %<--enable-newlib-nano-formatted-io%> " + "to use %<-mtiny-printf%>"); +#endif } #undef TARGET_SCALAR_MODE_SUPPORTED_P diff --git a/gcc/config/msp430/msp430.h b/gcc/config/msp430/msp430.h index 2e70e0d6ab6..0ea6b0a093e 100644 --- a/gcc/config/msp430/msp430.h +++ b/gcc/config/msp430/msp430.h @@ -75,7 +75,8 @@ extern bool msp430x; "msp430_propagate_region_opt(%* %{muse-lower-region-prefix})} " \ "%{mdata-region=*:--data-region=%:" \ "msp430_propagate_region_opt(%* %{muse-lower-region-prefix})} " \ - "%:msp430_get_linker_devices_include_path()" + "%:msp430_get_linker_devices_include_path() " \ + "%{mtiny-printf:--wrap puts --wrap printf} " #define DRIVER_SELF_SPECS \ " %{!mlarge:%{mcode-region=*:%{mdata-region=*:%e-mcode-region and " \ diff --git a/gcc/config/msp430/msp430.opt b/gcc/config/msp430/msp430.opt index 2db2906ca11..b451174c3d1 100644 --- a/gcc/config/msp430/msp430.opt +++ b/gcc/config/msp430/msp430.opt @@ -2,6 +2,10 @@ msim Target Use simulator runtime. +mtiny-printf +Target Report Mask(TINY_PRINTF) +Use a lightweight configuration of printf and puts to reduce code size. For single-threaded applications, not requiring reentrant I/O only. Requires Newlib Nano IO. + masm-hex Target Mask(ASM_HEX) Force assembly output to always use hex constants. diff --git a/gcc/configure b/gcc/configure index fd33bc661a8..9fe04293f72 100755 --- a/gcc/configure +++ b/gcc/configure @@ -990,6 +990,7 @@ with_plugin_ld enable_gnu_indirect_function enable_initfini_array enable_comdat +enable_newlib_nano_formatted_io enable_standard_branch_protection enable_fix_cortex_a53_835769 enable_fix_cortex_a53_843419 @@ -1718,6 +1719,8 @@ Optional Features: glibc systems --enable-initfini-array use .init_array/.fini_array sections --enable-comdat enable COMDAT group support + --enable-newlib-nano-formatted-io + Use nano version formatted IO --enable-standard-branch-protection enable Branch Target Identification Mechanism and @@ -18923,7 +18926,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18926 "configure" +#line 18929 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -19029,7 +19032,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 19032 "configure" +#line 19035 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -24549,6 +24552,19 @@ $as_echo "#define HAVE_GAS_DISCRIMINATOR 1" >>confdefs.h fi +# Catch the newlib flag of the same name so we can gate GCC features on it. +# Check whether --enable-newlib-nano-formatted-io was given. +if test "${enable_newlib_nano_formatted_io+set}" = set; then : + enableval=$enable_newlib_nano_formatted_io; case "${enableval}" in + yes|no) + ;; + *) + as_fn_error $? "unknown newlib-nano-formatted-io setting $enableval" "$LINENO" 5 + ;; +esac +fi + + # Thread-local storage - the check is heavily parameterized. conftest_s= tls_first_major= @@ -27939,6 +27955,11 @@ $as_echo "#define HAVE_AS_MSPABI_ATTRIBUTE 1" >>confdefs.h fi + if test x$enable_newlib_nano_formatted_io = xyes; then + +$as_echo "#define HAVE_NEWLIB_NANO_FORMATTED_IO 1" >>confdefs.h + + fi ;; riscv*-*-*) { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .attribute support" >&5 diff --git a/gcc/configure.ac b/gcc/configure.ac index bc15683fd02..0fe4e547272 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -3359,6 +3359,18 @@ gcc_GAS_CHECK_FEATURE([line table discriminator support], [AC_DEFINE(HAVE_GAS_DISCRIMINATOR, 1, [Define if your assembler supports the .loc discriminator sub-directive.])]) +# Catch the newlib flag of the same name so we can gate GCC features on it. +AC_ARG_ENABLE(newlib-nano-formatted-io, +[AS_HELP_STRING([--enable-newlib-nano-formatted-io], [Use nano version + formatted IO])], +[case "${enableval}" in + yes|no) + ;; + *) + AC_MSG_ERROR([unknown newlib-nano-formatted-io setting $enableval]) + ;; +esac], []) + # Thread-local storage - the check is heavily parameterized. conftest_s= tls_first_major= @@ -4999,6 +5011,10 @@ pointers into PC-relative form.]) [.mspabi_attribute 4,1],, [AC_DEFINE(HAVE_AS_MSPABI_ATTRIBUTE, 1, [Define if your assembler supports .mspabi_attribute.])]) + if test x$enable_newlib_nano_formatted_io = xyes; then + AC_DEFINE(HAVE_NEWLIB_NANO_FORMATTED_IO, 1, [Define if GCC has been +configured with --enable-newlib-nano-formatted-io.]) + fi ;; riscv*-*-*) gcc_GAS_CHECK_FEATURE([.attribute support], diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 122a23eef11..bf3ea3f6c04 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1010,7 +1010,7 @@ Objective-C and Objective-C++ Dialects}. -mwarn-mcu @gol -mcode-region= -mdata-region= @gol -msilicon-errata= -msilicon-errata-warn= @gol --mhwmult= -minrt} +-mhwmult= -minrt -mtiny-printf} @emph{NDS32 Options} @gccoptlist{-mbig-endian -mlittle-endian @gol @@ -23323,6 +23323,19 @@ initializers or constructors. This is intended for memory-constrained devices. The compiler includes special symbols in some objects that tell the linker and runtime which code fragments are required. +@item -mtiny-printf +@opindex mtiny-printf +Enable reduced code size @code{printf} and @code{puts} library functions. +The @samp{tiny} implementations of these functions are not reentrant, so +must be used with caution in multi-threaded applications. + +Support for streams has been removed and the string to be printed will +always be sent to stdout via the @code{write} syscall. The string is not +buffered before it is sent to write. + +This option requires Newlib Nano IO, so GCC must be configured with +@samp{--enable-newlib-nano-formatted-io}. + @item -mcode-region= @itemx -mdata-region= @opindex mcode-region diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 45ec73ab7d2..7f7acb3f887 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-11-04 Jozef Lawrynowicz + + * gcc.target/msp430/tiny-printf.c: New test. + 2019-11-04 Jozef Lawrynowicz * gcc.target/msp430/devices/csv-using-env-var.c: New test. diff --git a/gcc/testsuite/gcc.target/msp430/tiny-printf.c b/gcc/testsuite/gcc.target/msp430/tiny-printf.c new file mode 100644 index 00000000000..55ef5f76ca4 --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/tiny-printf.c @@ -0,0 +1,3 @@ +/* { dg-do compile } */ +/* { dg-options "-mtiny-printf" } */ +/* { dg-error "GCC must be configured with --enable-newlib-nano-formatted-io to use -mtiny-printf" "" { target { ! newlib_nano_io } } 0 } */