From 2e62f3a4b3c307e2abec0cb0302ec601b8f693e8 Mon Sep 17 00:00:00 2001
From: Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
Date: Thu, 15 Sep 2016 15:54:50 -0300
Subject: [PATCH 1/3] Add #ifdef case for 16 bits in cow-stdexcept.cc
Added #ifdef case for when void* is 16 bits so it compiles in AVR
target.
---
libstdc++-v3/ChangeLog | 4 ++++
libstdc++-v3/src/c++11/cow-stdexcept.cc | 11 ++++++++---
2 files changed, 12 insertions(+), 3 deletions(-)
@@ -1,3 +1,7 @@
+2016-11-10 Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
+
+ * src/c++11/cow-stdexcept.cc: Add special case for 16 bit pointers
+
2016-11-09 Tim Shen <timshen@google.com>
* libstdc++-v3/include/bits/regex.h (regex_iterator::regex_iterator()):
@@ -208,6 +208,8 @@ extern void* _ZGTtnaX (size_t sz) __attribute__((weak));
extern void _ZGTtdlPv (void* ptr) __attribute__((weak));
extern uint8_t _ITM_RU1(const uint8_t *p)
ITM_REGPARM __attribute__((weak));
+extern uint16_t _ITM_RU2(const uint16_t *p)
+ ITM_REGPARM __attribute__((weak));
extern uint32_t _ITM_RU4(const uint32_t *p)
ITM_REGPARM __attribute__((weak));
extern uint64_t _ITM_RU8(const uint64_t *p)
@@ -272,12 +274,15 @@ _txnal_cow_string_C1_for_exceptions(void* that, const char* s,
static void* txnal_read_ptr(void* const * ptr)
{
static_assert(sizeof(uint64_t) == sizeof(void*)
- || sizeof(uint32_t) == sizeof(void*),
- "Pointers must be 32 bits or 64 bits wide");
+ || sizeof(uint32_t) == sizeof(void*)
+ || sizeof(uint16_t) == sizeof(void*),
+ "Pointers must be 16 bits, 32 bits or 64 bits wide");
#if __UINTPTR_MAX__ == __UINT64_MAX__
return (void*)_ITM_RU8((const uint64_t*)ptr);
-#else
+#elif __UINTPTR_MAX__ == __UINT32_MAX__
return (void*)_ITM_RU4((const uint32_t*)ptr);
+#else
+ return (void*)_ITM_RU2((const uint16_t*)ptr);
#endif
}
--
2.10.2
From 7ed4af72fe0bdee1a38c7487955590fb64f76a5d Mon Sep 17 00:00:00 2001
From: Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
Date: Thu, 15 Sep 2016 18:52:57 -0300
Subject: [PATCH 2/3] Use temporary int objects to access struct tm members
Call _M_extract_* functions family through temporary int objects, so
it doesn't convert from lvalue to rvalue through a temporary in AVR
because of the incompatible types used in AVR-Libc.
This fixes compilation errors with AVR-Libc while compiling libstdc++
for AVR target.
---
libstdc++-v3/ChangeLog | 5 +++
libstdc++-v3/include/bits/locale_facets_nonio.tcc | 44 ++++++++++++++++-------
2 files changed, 37 insertions(+), 12 deletions(-)
@@ -1,5 +1,10 @@
2016-11-10 Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
+ * include/bits/locale_facets_nonio.tcc: Avoid compilation errors
+ with non-standard struct tm.
+
+2016-11-10 Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
+
* src/c++11/cow-stdexcept.cc: Add special case for 16 bit pointers
2016-11-09 Tim Shen <timshen@google.com>
@@ -659,30 +659,38 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
// Abbreviated weekday name [tm_wday]
const char_type* __days1[7];
__tp._M_days_abbreviated(__days1);
- __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days1,
+ __tm->tm_wday = __mem;
+ __beg = _M_extract_name(__beg, __end, __mem, __days1,
7, __io, __tmperr);
+ __mem = __tm->tm_wday;
break;
case 'A':
// Weekday name [tm_wday].
const char_type* __days2[7];
__tp._M_days(__days2);
- __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days2,
+ __mem = __tm->tm_wday;
+ __beg = _M_extract_name(__beg, __end, __mem, __days2,
7, __io, __tmperr);
+ __tm->tm_wday = __mem;
break;
case 'h':
case 'b':
// Abbreviated month name [tm_mon]
const char_type* __months1[12];
__tp._M_months_abbreviated(__months1);
- __beg = _M_extract_name(__beg, __end, __tm->tm_mon,
+ __mem = __tm->tm_mon;
+ __beg = _M_extract_name(__beg, __end, __mem,
__months1, 12, __io, __tmperr);
+ __tm->tm_mon = __mem;
break;
case 'B':
// Month name [tm_mon].
const char_type* __months2[12];
__tp._M_months(__months2);
- __beg = _M_extract_name(__beg, __end, __tm->tm_mon,
+ __mem = __tm->tm_mon;
+ __beg = _M_extract_name(__beg, __end, __mem,
__months2, 12, __io, __tmperr);
+ __tm->tm_mon = __mem;
break;
case 'c':
// Default time and date representation.
@@ -693,18 +701,22 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
break;
case 'd':
// Day [01, 31]. [tm_mday]
- __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2,
+ __mem = __tm->tm_mday;
+ __beg = _M_extract_num(__beg, __end, __mem, 1, 31, 2,
__io, __tmperr);
+ __tm->tm_mday = __mem;
break;
case 'e':
// Day [1, 31], with single digits preceded by
// space. [tm_mday]
+ __mem = __tm->tm_mday;
if (__ctype.is(ctype_base::space, *__beg))
- __beg = _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9,
+ __beg = _M_extract_num(++__beg, __end, __mem, 1, 9,
1, __io, __tmperr);
else
- __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31,
+ __beg = _M_extract_num(__beg, __end, __mem, 10, 31,
2, __io, __tmperr);
+ __tm->tm_mday = __mem;
break;
case 'D':
// Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year]
@@ -715,13 +727,17 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
break;
case 'H':
// Hour [00, 23]. [tm_hour]
- __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2,
+ __mem = __tm->tm_hour;
+ __beg = _M_extract_num(__beg, __end, __mem, 0, 23, 2,
__io, __tmperr);
+ __tm->tm_hour = __mem;
break;
case 'I':
// Hour [01, 12]. [tm_hour]
- __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2,
+ __mem = __tm->tm_hour;
+ __beg = _M_extract_num(__beg, __end, __mem, 1, 12, 2,
__io, __tmperr);
+ __tm->tm_hour = __mem;
break;
case 'm':
// Month [01, 12]. [tm_mon]
@@ -732,8 +748,10 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
break;
case 'M':
// Minute [00, 59]. [tm_min]
- __beg = _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2,
+ __mem = __tm->tm_min;
+ __beg = _M_extract_num(__beg, __end, __mem, 0, 59, 2,
__io, __tmperr);
+ __tm->tm_min = __mem;
break;
case 'n':
if (__ctype.narrow(*__beg, 0) == '\n')
@@ -752,11 +770,13 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
// Seconds. [tm_sec]
// [00, 60] in C99 (one leap-second), [00, 61] in C89.
#if _GLIBCXX_USE_C99
- __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 60, 2,
+ __mem = __tm->tm_sec;
+ __beg = _M_extract_num(__beg, __end, __mem, 0, 60, 2,
#else
- __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 61, 2,
+ __beg = _M_extract_num(__beg, __end, __mem, 0, 61, 2,
#endif
__io, __tmperr);
+ __tm->tm_sec = __mem;
break;
case 't':
if (__ctype.narrow(*__beg, 0) == '\t')
--
2.10.2
From 5bec19a49d6ae7e18327bb1b323275f78ef5aa42 Mon Sep 17 00:00:00 2001
From: Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
Date: Thu, 15 Sep 2016 16:05:02 -0300
Subject: [PATCH 3/3] Enable libstdc++ compilation in AVR targets
Enable libstdc++ compilation in AVR targets with AVR-Libc. Most
floating point math functions are already defined in AVR-Libc, so
defines are in place to avoid multiple definition of these functions.
---
libstdc++-v3/ChangeLog | 5 +++++
libstdc++-v3/configure | 49 +++++++++++++++++++++++++++++++++++++++++++++
libstdc++-v3/crossconfig.m4 | 26 ++++++++++++++++++++++++
3 files changed, 80 insertions(+)
@@ -1,5 +1,10 @@
2016-11-10 Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
+ * crossconfig.m4: Add avr target for cross-compilation
+ * configure: Regenerate
+
+2016-11-10 Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
+
* include/bits/locale_facets_nonio.tcc: Avoid compilation errors
with non-standard struct tm.
@@ -28840,6 +28840,55 @@ case "${host}" in
# This is a freestanding configuration; there is nothing to do here.
;;
+ avr*-*-*)
+ $as_echo "#define HAVE_ACOSF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_ASINF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_ATAN2F 1" >>confdefs.h
+
+ $as_echo "#define HAVE_ATANF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_CEILF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_COSF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_COSHF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_EXPF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_FABSF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_FLOORF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_FMODF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_FREXPF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_SQRTF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_HYPOTF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_LDEXPF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_LOG10F 1" >>confdefs.h
+
+ $as_echo "#define HAVE_LOGF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_MODFF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_POWF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_SINF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_SINHF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_TANF 1" >>confdefs.h
+
+ $as_echo "#define HAVE_TANHF 1" >>confdefs.h
+
+ ;;
+
mips*-sde-elf*)
# These definitions are for the SDE C library rather than newlib.
SECTION_FLAGS='-ffunction-sections -fdata-sections'
@@ -9,6 +9,32 @@ case "${host}" in
# This is a freestanding configuration; there is nothing to do here.
;;
+ avr*-*-*)
+ AC_DEFINE(HAVE_ACOSF)
+ AC_DEFINE(HAVE_ASINF)
+ AC_DEFINE(HAVE_ATAN2F)
+ AC_DEFINE(HAVE_ATANF)
+ AC_DEFINE(HAVE_CEILF)
+ AC_DEFINE(HAVE_COSF)
+ AC_DEFINE(HAVE_COSHF)
+ AC_DEFINE(HAVE_EXPF)
+ AC_DEFINE(HAVE_FABSF)
+ AC_DEFINE(HAVE_FLOORF)
+ AC_DEFINE(HAVE_FMODF)
+ AC_DEFINE(HAVE_FREXPF)
+ AC_DEFINE(HAVE_SQRTF)
+ AC_DEFINE(HAVE_HYPOTF)
+ AC_DEFINE(HAVE_LDEXPF)
+ AC_DEFINE(HAVE_LOG10F)
+ AC_DEFINE(HAVE_LOGF)
+ AC_DEFINE(HAVE_MODFF)
+ AC_DEFINE(HAVE_POWF)
+ AC_DEFINE(HAVE_SINF)
+ AC_DEFINE(HAVE_SINHF)
+ AC_DEFINE(HAVE_TANF)
+ AC_DEFINE(HAVE_TANHF)
+ ;;
+
mips*-sde-elf*)
# These definitions are for the SDE C library rather than newlib.
SECTION_FLAGS='-ffunction-sections -fdata-sections'
--
2.10.2