Project import
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..24529e5
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,127 @@
+#
+# Copyright (c) 2010-2011 Nest, Inc.
+# All rights reserved.
+#
+# This document is the property of Nest. It is considered
+# confidential and proprietary information.
+#
+# This document may not be reproduced or transmitted in any form,
+# in whole or in part, without the express written permission of
+# Nest.
+#
+# Description:
+#
+
+include pre.mak
+
+ifeq ($(BUILD_FEATURE_NEWLIB),1)
+
+PackageName := newlib
+
+PackageExtension := tar.gz
+PackageSeparator := -
+
+PackagePatchArgs := -p1
+
+PackageVersion := 1.20.0
+PackageArchive := $(PackageName)$(PackageSeparator)$(PackageVersion).$(PackageExtension)
+PackageSourceDir := $(PackageName)$(PackageSeparator)$(PackageVersion)
+
+PackageBuildMakefile = $(call GenerateBuildPaths,Makefile)
+
+CleanPaths += $(PackageLicenseFile)
+
+all: $(PackageDefaultGoal)
+
+# Generate the package license contents.
+
+#$(PackageLicenseFile): $(PackageSourceDir)/COPYRIGHT
+# $(copy-result)
+
+# Extract the source from the archive and apply patches, if any.
+
+$(PackageSourceDir): $(PackageArchive) $(PackagePatchPaths)
+ $(expand-and-patch-package)
+
+# Prepare the sources.
+
+.PHONY: source
+source: | $(PackageSourceDir)
+
+# Patch the sources, if necessary.
+
+.PHONY: patch
+patch: source
+
+# Configure the source for building.
+
+$(PackageBuildMakefile): | $(PackageSourceDir) $(BuildDirectory)
+ cd $(BuildDirectory) && \
+ $(CURDIR)/$(PackageSourceDir)/configure \
+ --target=arm-none-eabi \
+ --prefix=/usr \
+ --enable-interwork \
+ --disable-newlib-supplied-syscalls \
+ --disable-newlib-io-float \
+ --with-gnu-ld \
+ --with-gnu-as \
+ --disable-shared \
+ --disable-newlib-atexit-dynamic-alloc \
+ --disable-multilib
+
+
+
+.PHONY: configure
+configure: source $(PackageBuildMakefile)
+
+# Build the source.
+#
+
+.PHONY: build
+build: configure | $(BuildDirectory)
+ $(Verbose)unset MAKEFLAGS \
+ && $(MAKE) -C $(BuildDirectory) \
+ CC_FOR_TARGET="$(CC)" \
+ CXX_FOR_TARGET="$(CXX)" \
+ AS_FOR_TARGET=$(AS) \
+ AR_FOR_TARGET=$(AR) \
+ LD_FOR_TARGET=$(LD) \
+ NM_FOR_TARGET=$(NM) \
+ OBJDUMP_FOR_TARGET=$(OBJDUMP) \
+ RANLIB_FOR_TARGET=$(RANLIB) \
+ READELF_FOR_TARGET=$(READELF) \
+ STRIP_FOR_TARGET=$(STRIP) \
+ CFLAGS_FOR_TARGET="-ffunction-sections -fdata-sections -DPREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__ -Os -fomit-frame-pointer -mcpu=cortex-m3 -mthumb -D__thumb2__ -D__BUFSIZ__=256 -DMALLOC_LOCK_FUNCTION=__nl_malloc_lock -DMALLOC_UNLOCK_FUNCTION=__nl_malloc_unlock" \
+ CCASFLAGS="-mcpu=cortex-m3 -mthumb -D__thumb2__"
+
+.PHONY: prepare
+prepare: stage
+
+# Stage the build to a temporary installation area.
+#
+.PHONY: stage
+stage: build | $(ResultDirectory)
+ $(Verbose)unset MAKEFLAGS && \
+ $(MAKE) -C $(BuildDirectory) \
+ CC_FOR_TARGET="$(CC)" \
+ CXX_FOR_TARGET="$(CXX)" \
+ AS_FOR_TARGET=$(AS) \
+ AR_FOR_TARGET=$(AR) \
+ LD_FOR_TARGET=$(LD) \
+ NM_FOR_TARGET=$(NM) \
+ OBJDUMP_FOR_TARGET=$(OBJDUMP) \
+ RANLIB_FOR_TARGET=$(RANLIB) \
+ READELF_FOR_TARGET=$(READELF) \
+ STRIP_FOR_TARGET=$(STRIP) \
+ DESTDIR=$(ResultDirectory) \
+ install
+
+
+clean:
+ $(Verbose)$(RM) $(RMFLAGS) -r $(PackageSourceDir)
+ $(Verbose)$(RM) $(RMFLAGS) -r $(BuildDirectory)
+ $(Verbose)$(RM) $(RMFLAGS) -r $(ResultDirectory)
+
+endif # ifeq ($(BUILD_FEATURE_NEWLIB),1)
+
+include post.mak
diff --git a/newlib-1.20.0.tar.gz b/newlib-1.20.0.tar.gz
new file mode 100644
index 0000000..cce6d27
--- /dev/null
+++ b/newlib-1.20.0.tar.gz
Binary files differ
diff --git a/newlib.patches/newlib-50.description b/newlib.patches/newlib-50.description
new file mode 100644
index 0000000..d86f4ed
--- /dev/null
+++ b/newlib.patches/newlib-50.description
@@ -0,0 +1 @@
+Fix for __USER_LABEL_PREFIX__ not being concatenated properly by clang preprocessor
diff --git a/newlib.patches/newlib-50.patch b/newlib.patches/newlib-50.patch
new file mode 100644
index 0000000..4f49eb6
--- /dev/null
+++ b/newlib.patches/newlib-50.patch
@@ -0,0 +1,42 @@
+diff -aruN newlib-1.20.0/libgloss/arm/Makefile.in newlib-1.20.0-new//libgloss/arm/Makefile.in
+--- newlib-1.20.0/libgloss/arm/Makefile.in 2011-06-29 08:32:09.000000000 -0700
++++ newlib-1.20.0-new//libgloss/arm/Makefile.in 2012-09-17 18:17:04.011270636 -0700
+@@ -93,7 +93,9 @@
+ # build a test program for each target board. Just trying to get
+ # it to link is a good test, so we ignore all the errors for now.
+ #
+-all: ${CRT0} ${LINUX_CRT0} ${LINUX_BSP} ${REDBOOT_CRT0} ${REDBOOT_OBJS} ${RDPMON_CRT0} ${RDPMON_BSP} ${RDIMON_CRT0} ${RDIMON_BSP}
++all: ${CRT0}
++
++#${LINUX_CRT0} ${LINUX_BSP} ${REDBOOT_CRT0} ${REDBOOT_OBJS} ${RDPMON_CRT0} ${RDPMON_BSP} ${RDIMON_CRT0} ${RDIMON_BSP}
+
+ #
+ # here's where we build the test programs for each target
+@@ -146,7 +148,9 @@
+ rm -f Makefile config.status *~
+
+ .PHONY: install info install-info clean-info
+-install: ${CRT0_INSTALL} ${LINUX_INSTALL} ${REDBOOT_INSTALL} ${RDPMON_INSTALL} ${RDIMON_INSTALL} ${IQ80310_INSTALL} ${PID_INSTALL}
++install: ${CRT0_INSTALL}
++
++#${LINUX_INSTALL} ${REDBOOT_INSTALL} ${RDPMON_INSTALL} ${RDIMON_INSTALL} ${IQ80310_INSTALL} ${PID_INSTALL}
+
+ install-crt0:
+ ${INSTALL_DATA} ${CRT0} $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x
+diff -aruN newlib-1.20.0/newlib/libc/machine/arm/setjmp.S newlib-1.20.0-new//newlib/libc/machine/arm/setjmp.S
+--- newlib-1.20.0/newlib/libc/machine/arm/setjmp.S 2009-05-13 11:31:55.000000000 -0700
++++ newlib-1.20.0-new//newlib/libc/machine/arm/setjmp.S 2012-09-17 18:12:26.807156599 -0700
+@@ -6,11 +6,8 @@
+ #define CONCAT(a, b) CONCAT2(a, b)
+ #define CONCAT2(a, b) a##b
+
+-#ifndef __USER_LABEL_PREFIX__
+-#error __USER_LABEL_PREFIX__ not defined
+-#endif
++#define SYM(x) _##x
+
+-#define SYM(x) CONCAT (__USER_LABEL_PREFIX__, x)
+
+ #ifdef __ELF__
+ #define TYPE(x) .type SYM(x),function
+
diff --git a/newlib.patches/newlib-51.description b/newlib.patches/newlib-51.description
new file mode 100644
index 0000000..4adb533
--- /dev/null
+++ b/newlib.patches/newlib-51.description
@@ -0,0 +1 @@
+s/__warning__/deprecated/
diff --git a/newlib.patches/newlib-51.patch b/newlib.patches/newlib-51.patch
new file mode 100644
index 0000000..7d2fb26
--- /dev/null
+++ b/newlib.patches/newlib-51.patch
@@ -0,0 +1,21 @@
+diff -aruN newlib-1.20.0/newlib/libc/include/stdlib.h newlib-1.20.0-new/newlib/libc/include/stdlib.h
+--- newlib-1.20.0/newlib/libc/include/stdlib.h 2010-07-19 11:21:11.000000000 -0700
++++ newlib-1.20.0-new/newlib/libc/include/stdlib.h 2012-09-25 17:54:04.708256826 -0700
+@@ -107,14 +107,14 @@
+ int _EXFUN(mkostemps,(char *, int, int));
+ int _EXFUN(mkstemp,(char *));
+ int _EXFUN(mkstemps,(char *, int));
+-char * _EXFUN(mktemp,(char *) _ATTRIBUTE ((__warning__ ("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
++char * _EXFUN(mktemp,(char *) _ATTRIBUTE ((deprecated("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
+ #endif
+ char * _EXFUN(_mkdtemp_r, (struct _reent *, char *));
+ int _EXFUN(_mkostemp_r, (struct _reent *, char *, int));
+ int _EXFUN(_mkostemps_r, (struct _reent *, char *, int, int));
+ int _EXFUN(_mkstemp_r, (struct _reent *, char *));
+ int _EXFUN(_mkstemps_r, (struct _reent *, char *, int));
+-char * _EXFUN(_mktemp_r, (struct _reent *, char *) _ATTRIBUTE ((__warning__ ("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
++char * _EXFUN(_mktemp_r, (struct _reent *, char *) _ATTRIBUTE ((deprecated ("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
+ #endif
+ _VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, int(*_compar)(const _PTR, const _PTR)));
+ int _EXFUN(rand,(_VOID));
+
diff --git a/newlib.patches/newlib-52.patch b/newlib.patches/newlib-52.patch
new file mode 100644
index 0000000..9afe2d7
--- /dev/null
+++ b/newlib.patches/newlib-52.patch
@@ -0,0 +1,43 @@
+--- newlib-1.20.0/newlib/libc/stdlib/mallocr.c 2010-05-31 12:15:41.000000000 -0700
++++ newlib-1.20.0-new/newlib/libc/stdlib/mallocr.c 2013-05-02 12:03:25.831542637 -0700
+@@ -303,13 +303,22 @@
+
+ #include <reent.h>
+
++#ifndef MALLOC_LOCK_FUNCTION
++#define MALLOC_LOCK_FUNCTION __malloc_lock
++#endif
++
++#ifndef MALLOC_UNLOCK_FUNCTION
++#define MALLOC_UNLOCK_FUNCTION __malloc_unlock
++#endif
++
+ #define POINTER_UINT unsigned _POINTER_INT
+ #define SEPARATE_OBJECTS
+ #define HAVE_MMAP 0
+ #define MORECORE(size) _sbrk_r(reent_ptr, (size))
+ #define MORECORE_CLEARS 0
+-#define MALLOC_LOCK __malloc_lock(reent_ptr)
+-#define MALLOC_UNLOCK __malloc_unlock(reent_ptr)
++
++#define MALLOC_LOCK MALLOC_LOCK_FUNCTION(reent_ptr)
++#define MALLOC_UNLOCK MALLOC_UNLOCK_FUNCTION(reent_ptr)
+
+ #ifdef __CYGWIN__
+ # undef _WIN32
+@@ -325,11 +334,11 @@
+ #endif
+
+ #if __STD_C
+-extern void __malloc_lock(struct _reent *);
+-extern void __malloc_unlock(struct _reent *);
++extern void MALLOC_LOCK_FUNCTION(struct _reent *);
++extern void MALLOC_UNLOCK_FUNCTION(struct _reent *);
+ #else
+-extern void __malloc_lock();
+-extern void __malloc_unlock();
++extern void MALLOC_LOCK_FUNCTION();
++extern void MALLOC_UNLOCK_FUNCTION();
+ #endif
+
+ #if __STD_C
diff --git a/newlib.patches/newlib-53.patch b/newlib.patches/newlib-53.patch
new file mode 100644
index 0000000..9c7ca88
--- /dev/null
+++ b/newlib.patches/newlib-53.patch
@@ -0,0 +1,11 @@
+--- newlib-1.20.0/newlib/libc/locale/ldpart.c 2008-11-24 13:27:33.000000000 -0800
++++ newlib-1.20.0/newlib/libc/locale/ldpart.c.new 2017-06-23 11:07:01.323063165 -0700
+@@ -94,7 +94,7 @@
+ if (!_PathLocale)
+ goto no_locale;
+ /* Range checking not needed, 'name' size is limited */
+- strcpy(filename, _PathLocale);
++ strncpy(filename, _PathLocale, PATH_MAX);
+ strcat(filename, "/");
+ strcat(filename, name);
+ strcat(filename, "/");
diff --git a/newlib.patches/newlib-54.description b/newlib.patches/newlib-54.description
new file mode 100644
index 0000000..5e92588
--- /dev/null
+++ b/newlib.patches/newlib-54.description
@@ -0,0 +1,2 @@
+ANT-466: Fixed Security SAST Defect: 10491 - STRING_OVERFLOW, as detected by Coverity
+(strcpying into a fixed-size buffer from a non-fixed-size buffer)
diff --git a/newlib.patches/newlib-54.patch b/newlib.patches/newlib-54.patch
new file mode 100644
index 0000000..af70fee
--- /dev/null
+++ b/newlib.patches/newlib-54.patch
@@ -0,0 +1,14 @@
+diff -aruN newlib-1.20.0/newlib/libc/locale/lctype.c newlibDup/newlib/libc/locale/lctype.c
+--- newlib-1.20.0/newlib/libc/locale/lctype.c 2010-05-03 02:25:32.000000000 -0700
++++ newlibDup/newlib/libc/locale/lctype.c 2017-08-17 09:33:23.812683710 -0700
+@@ -82,7 +82,9 @@
+ _ctype_using_locale = 0;
+ else
+ {
+- _ctype_locale.codeset = strcpy (_ctype_locale_buf, charset);
++ // Strncpy'ed to prevent memory overruns, limited to (_CTYPE_BUF_SIZE - 1) to prevent
++ // overwriting of the last null char in _ctype_locale_buf that is needed for a string
++ _ctype_locale.codeset = strncpy (_ctype_locale_buf, charset, (_CTYPE_BUF_SIZE - 1));
+ char *mbc = _ctype_locale_buf + _CTYPE_BUF_SIZE - 2;
+ mbc[0] = mb_cur_max;
+ mbc[1] = '\0';
diff --git a/newlib.url b/newlib.url
new file mode 100644
index 0000000..858e60d
--- /dev/null
+++ b/newlib.url
@@ -0,0 +1 @@
+ftp://sourceware.org/pub/newlib/newlib-1.20.0.tar.gz
diff --git a/newlib.version b/newlib.version
new file mode 100644
index 0000000..3989355
--- /dev/null
+++ b/newlib.version
@@ -0,0 +1 @@
+1.20.0