diff mbox

[2/4] Nios II: sysdeps/nios2 portions

Message ID 533597C0.7060802@codesourcery.com
State New
Headers show

Commit Message

Chung-Lin Tang March 28, 2014, 3:39 p.m. UTC
These are the parts that reside in sysdeps/nios2.

Thanks,
Chung-Lin

        * sysdeps/nios2/Implies: New file.
        * sysdeps/nios2/Makefile: New file.
        * sysdeps/nios2/Subdirs: New file.
        * sysdeps/nios2/Versions: New file.
        * sysdeps/nios2/__longjmp.S: New file.
        * sysdeps/nios2/abort-instr.h: New file.
        * sysdeps/nios2/backtrace.c: New file.
        * sysdeps/nios2/bsd-_setjmp.S: New file.
        * sysdeps/nios2/bsd-setjmp.S: New file.
        * sysdeps/nios2/configure.ac: New file.
        * sysdeps/nios2/crti.S: New file.
        * sysdeps/nios2/crtn.S: New file.
        * sysdeps/nios2/dl-init.c: New file.
        * sysdeps/nios2/dl-machine.h: New file.
        * sysdeps/nios2/dl-sysdep.h: New file.
        * sysdeps/nios2/dl-tls.h: New file.
        * sysdeps/nios2/dl-trampoline.S: New file.
        * sysdeps/nios2/gccframe.h: New file.
        * sysdeps/nios2/gmp-mparam.h: New file.
        * sysdeps/nios2/jmpbuf-offsets.h: New file.
        * sysdeps/nios2/jmpbuf-unwind.h: New file.
        * sysdeps/nios2/ldsodefs.h: New file.
        * sysdeps/nios2/libc-tls.c: New file.
        * sysdeps/nios2/libm-test-ulps: New file.
        * sysdeps/nios2/machine-gmon.h: New file.
        * sysdeps/nios2/math-tests.h: New file.
        * sysdeps/nios2/memusage.h: New file.
        * sysdeps/nios2/preconfigure: New file.
        * sysdeps/nios2/s_fma.c: New file.
        * sysdeps/nios2/s_fmaf.c: New file.
        * sysdeps/nios2/setjmp.S: New file.
        * sysdeps/nios2/shlib-versions: New file.
        * sysdeps/nios2/sotruss-lib.c: New file.
        * sysdeps/nios2/stackguard-macros.h: New file.
        * sysdeps/nios2/stackinfo.h: New file.
        * sysdeps/nios2/start.S: New file.
        * sysdeps/nios2/sysdep.h: New file.
        * sysdeps/nios2/tls-macros.h: New file.
        * sysdeps/nios2/tst-audit.h: New file.
        * sysdeps/nios2/bits/endian.h: New file.
        * sysdeps/nios2/bits/fenv.h: New file.
        * sysdeps/nios2/bits/link.h: New file.
        * sysdeps/nios2/bits/setjmp.h: New file.
        * sysdeps/nios2/nptl/pthread_spin_lock.c: New file.
        * sysdeps/nios2/nptl/pthread_spin_trylock.c: New file.
        * sysdeps/nios2/nptl/pthreaddef.h: New file.
        * sysdeps/nios2/nptl/tcb-offsets.sym: New file.
        * sysdeps/nios2/nptl/tls.h: New file.
        * sysdeps/nios2/soft-fp/sfp-machine.h: New file.

Comments

Joseph Myers March 28, 2014, 5:07 p.m. UTC | #1
On Fri, 28 Mar 2014, Chung-Lin Tang wrote:

>         * sysdeps/nios2/configure.ac: New file.

And presumably:

	* sysdeps/nios2/configure: New generated file.

> diff --git a/sysdeps/nios2/Makefile b/sysdeps/nios2/Makefile
> new file mode 100644
> index 0000000..34c678a
> --- /dev/null
> +++ b/sysdeps/nios2/Makefile
> @@ -0,0 +1,41 @@
> +# Copyright (C) 1993-2014 Free Software Foundation, Inc.
> +# This file is part of the GNU C Library.
> +
> +# The GNU C Library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU Lesser General Public
> +# License as published by the Free Software Foundation; either
> +# version 2.1 of the License, or (at your option) any later version.
> +
> +# The GNU C Library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +# Lesser General Public License for more details.
> +
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with the GNU C Library; if not, write to the Free
> +# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> +# 02111-1307 USA.

Please fix all files using FSF postal addresses, in any patch in this 
series, to use <http://www.gnu.org/licenses/> instead.

> +ifeq ($(subdir),debug)
> +CFLAGS-backtrace.c += -funwind-tables
> +CFLAGS-tst-backtrace2.c += -funwind-tables
> +CFLAGS-tst-backtrace3.c += -funwind-tables
> +CFLAGS-tst-backtrace4.c += -funwind-tables
> +CFLAGS-tst-backtrace5.c += -funwind-tables
> +CFLAGS-tst-backtrace6.c += -funwind-tables

Only the setting of CFLAGS-backtrace.c is needed; the others are in 
debug/Makefile.

> diff --git a/sysdeps/nios2/__longjmp.S b/sysdeps/nios2/__longjmp.S

Make sure you've checked for any need for CFI directives in this code.

> +/* Define bits representing the exception.
> +   Nios II doesn't support FPU exceptions, and these are defined just to
> +   avoid undefined symbols.  */

No, that's not correct.  Follow what Tile / MicroBlaze does, define only 
__FE_UNDEFINED / FE_TONEAREST as rounding modes, only FE_ALL_EXCEPT for 
exceptions, and use the Tile / MicroBlaze math_private.h to avoid any need 
for the other macros to be defined to build glibc.

> +#ifdef __USE_GNU
> +/* Floating-point environment where none of the exceptions are masked.  */
> +# define FE_NOMASK_ENV  ((const fenv_t *) -2)
> +#endif

Don't define this either, given you don't implement it.

> +unsigned int
> +internal_function
> +_dl_nios2_get_gp_value (struct link_map *main_map)
> +{
> +  ElfW(Dyn)* dyn = main_map->l_ld;

Space before rather than after "*" here.

> +  asm("nextpc\t%0\n\t"

asm, like a function call, should have a space before the "(", here and 
elsewhere.

> +      "1: movhi\t%1, %%hiadj(_GLOBAL_OFFSET_TABLE_ - 1b)\n\t"
> +      "addi\t%1, %1, %%lo( _GLOBAL_OFFSET_TABLE_ - 1b)\n\t"

Stray space after "(".

> +#ifndef RTLD_BOOTSTRAP_UDIV
> +static inline unsigned int __attribute__((always_inline))
> +nios2_rtld_bootstrap_udiv (unsigned int num, unsigned int den)

If we end up with an approach where an architecture defines such a macro / 
function, it should at least be conditional on compiler-defined macros 
saying whether hardware division is available - if it is available you can 
just use it, as on other architectures.  If GCC doesn't predefine such a 
macro that can be tested to indicate availability of hardware divide, add 
such a macro (if we end up going this way in glibc), __nios2_hw_divide or 
similar - likewise for hardware multiply if that's only conditionally 
available and we end up with division implemented in terms of multiply in 
glibc.

> +  if (__builtin_expect (r_type == R_NIOS2_RELATIVE, 0))
> +    *reloc_addr = map->l_addr + reloc->r_addend;
> +  else if (__builtin_expect (r_type == R_NIOS2_NONE, 0))

Please use the __glibc_likely / __glibc_unlikely macros in new code 
instead of direct use of __builtin_expect.

> +/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
> + * present, but it is presumed absent.  */
> +#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)

That seems like a bad default for a new platform.  Since you said 
kernel/userspace interface issues can be fixed, the kernel should be 
changed to default to non-executable stack without needing PT_GNU_STACK, 
and glibc changed to match, unless there is some strong reason to do 
otherwise.
diff mbox

Patch

diff --git a/sysdeps/nios2/Implies b/sysdeps/nios2/Implies
new file mode 100644
index 0000000..2d7b0d4
--- /dev/null
+++ b/sysdeps/nios2/Implies
@@ -0,0 +1,4 @@ 
+wordsize-32
+ieee754/dbl-64
+ieee754/flt-32
+nios2/soft-fp
diff --git a/sysdeps/nios2/Makefile b/sysdeps/nios2/Makefile
new file mode 100644
index 0000000..34c678a
--- /dev/null
+++ b/sysdeps/nios2/Makefile
@@ -0,0 +1,41 @@ 
+# Copyright (C) 1993-2014 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA.
+
+pic-ccflag = -fpic
+
+# We don't support long doubles as a distinct type.  We don't need to set
+# this variable; it's here mostly for documentational purposes.
+long-double-fcts = no
+
+ifeq ($(subdir),soft-fp)
+sysdep_routines += $(filter-out sqrtsf2,$(gcc-single-routines)) \
+  $(filter-out sqrtdf2,$(gcc-double-routines))
+endif
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
+
+ifeq ($(subdir),debug)
+CFLAGS-backtrace.c += -funwind-tables
+CFLAGS-tst-backtrace2.c += -funwind-tables
+CFLAGS-tst-backtrace3.c += -funwind-tables
+CFLAGS-tst-backtrace4.c += -funwind-tables
+CFLAGS-tst-backtrace5.c += -funwind-tables
+CFLAGS-tst-backtrace6.c += -funwind-tables
+endif
diff --git a/sysdeps/nios2/Subdirs b/sysdeps/nios2/Subdirs
new file mode 100644
index 0000000..87eadf3
--- /dev/null
+++ b/sysdeps/nios2/Subdirs
@@ -0,0 +1 @@ 
+soft-fp
diff --git a/sysdeps/nios2/Versions b/sysdeps/nios2/Versions
new file mode 100644
index 0000000..fd0110e
--- /dev/null
+++ b/sysdeps/nios2/Versions
@@ -0,0 +1,12 @@ 
+libc {
+  GLIBC_2.20 {
+    __adddf3; __addsf3; __divdf3; __divsf3; __eqdf2; __eqsf2; __extendsfdf2;
+    __fixdfdi; __fixdfsi; __fixsfdi; __fixsfsi;
+    __fixunsdfdi; __fixunsdfsi; __fixunssfdi; __fixunssfsi;
+    __floatdidf; __floatdisf; __floatsidf; __floatsisf;
+    __floatundidf; __floatundisf; __floatunsidf; __floatunsisf;
+    __gedf2; __gesf2; __gtdf2; __gtsf2; __ledf2; __lesf2; __ltdf2; __ltsf2;
+    __muldf3; __mulsf3; __nedf2; __nesf2; __negdf2; __negsf2;
+    __subdf3; __subsf3; __truncdfsf2; __unorddf2; __unordsf2;
+  }
+}
diff --git a/sysdeps/nios2/__longjmp.S b/sysdeps/nios2/__longjmp.S
new file mode 100644
index 0000000..7a32cf5
--- /dev/null
+++ b/sysdeps/nios2/__longjmp.S
@@ -0,0 +1,47 @@ 
+/* Copyright (C) 2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <jmpbuf-offsets.h>
+
+/* __longjmp(jmpbuf, val) */
+
+ENTRY (__longjmp)
+	mov	r2, r5
+	bne	r5, zero, 1f
+	movi	r2, 1
+1:
+#ifdef	PTR_MANGLE
+	PTR_MANGLE_GUARD (r3)
+#endif
+	ldw	r16, (JB_R16*4)(r4)
+	ldw	r17, (JB_R17*4)(r4)
+	ldw	r18, (JB_R18*4)(r4)
+	ldw	r19, (JB_R19*4)(r4)
+	ldw	r20, (JB_R20*4)(r4)
+	ldw	r21, (JB_R21*4)(r4)
+	ldw	r22, (JB_R22*4)(r4)
+	ldw	ra,  (JB_RA*4)(r4)
+	ldw	fp,  (JB_FP*4)(r4)
+	ldw	sp,  (JB_SP*4)(r4)
+#ifdef	PTR_DEMANGLE
+	PTR_DEMANGLE (ra, ra, r3)
+	PTR_DEMANGLE (fp, fp, r3)
+	PTR_DEMANGLE (sp, sp, r3)
+#endif
+	ret
+END (__longjmp)
diff --git a/sysdeps/nios2/abort-instr.h b/sysdeps/nios2/abort-instr.h
new file mode 100644
index 0000000..17502e4
--- /dev/null
+++ b/sysdeps/nios2/abort-instr.h
@@ -0,0 +1,2 @@ 
+/* An instruction which should crash any program is an unused trap.  */
+#define ABORT_INSTRUCTION asm ("trap 31")
diff --git a/sysdeps/nios2/backtrace.c b/sysdeps/nios2/backtrace.c
new file mode 100644
index 0000000..27ce597
--- /dev/null
+++ b/sysdeps/nios2/backtrace.c
@@ -0,0 +1 @@ 
+#include <sysdeps/x86_64/backtrace.c>
diff --git a/sysdeps/nios2/bits/endian.h b/sysdeps/nios2/bits/endian.h
new file mode 100644
index 0000000..164f9e4
--- /dev/null
+++ b/sysdeps/nios2/bits/endian.h
@@ -0,0 +1,12 @@ 
+/* The Nios II architecture has selectable endianness.  */
+
+#ifndef _ENDIAN_H
+# error "Never use <bits/endian.h> directly; include <endian.h> instead."
+#endif
+
+#ifdef __nios2_big_endian__
+# define __BYTE_ORDER __BIG_ENDIAN
+#endif
+#ifdef __nios2_little_endian__
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
diff --git a/sysdeps/nios2/bits/fenv.h b/sysdeps/nios2/bits/fenv.h
new file mode 100644
index 0000000..6a38e9f
--- /dev/null
+++ b/sysdeps/nios2/bits/fenv.h
@@ -0,0 +1,68 @@ 
+/* Copyright (C) 2012-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _FENV_H
+# error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
+#endif
+
+/* Define bits representing the exception.
+   Nios II doesn't support FPU exceptions, and these are defined just to
+   avoid undefined symbols.  */
+enum
+  {
+    FE_INVALID =
+#define FE_INVALID	1
+      FE_INVALID,
+    FE_DIVBYZERO =
+#define FE_DIVBYZERO	2
+      FE_DIVBYZERO,
+    FE_INEXACT =
+#define FE_INEXACT	4
+      FE_INEXACT
+  };
+
+/* All supported exceptions.  */
+#define FE_ALL_EXCEPT	\
+	(FE_INVALID | FE_DIVBYZERO | FE_INEXACT)
+
+/* Nios II supports only rounding to nearest.  The rest are defined to aviod
+   undefined symbols.  */
+enum
+  {
+    __FE_UNDEFINED = 0,
+
+    FE_TONEAREST =
+#define FE_TONEAREST	1
+      FE_TONEAREST,
+    FE_TOWARDZERO =
+#define FE_TOWARDZERO	2
+      FE_TOWARDZERO
+  };
+
+/* Type representing exception flags. */
+typedef unsigned int fexcept_t;
+
+/* Type representing floating-point environment.  */
+typedef unsigned int fenv_t;
+
+/* If the default argument is used we use this value.  */
+#define FE_DFL_ENV	((const fenv_t *) -1)
+
+#ifdef __USE_GNU
+/* Floating-point environment where none of the exceptions are masked.  */
+# define FE_NOMASK_ENV  ((const fenv_t *) -2)
+#endif
diff --git a/sysdeps/nios2/bits/link.h b/sysdeps/nios2/bits/link.h
new file mode 100644
index 0000000..3067f52
--- /dev/null
+++ b/sysdeps/nios2/bits/link.h
@@ -0,0 +1,54 @@ 
+/* Copyright (C) 2009-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef	_LINK_H
+# error "Never include <bits/link.h> directly; use <link.h> instead."
+#endif
+
+/* Registers for entry into PLT on Nios II.  */
+typedef struct La_nios2_regs
+{
+  uint32_t lr_reg[4]; /* r4 through r7 */
+  uint32_t lr_ra;
+  uint32_t lr_sp;
+} La_nios2_regs;
+
+/* Return values for calls from PLT on Nios II.  */
+typedef struct La_nios2_retval
+{
+  uint32_t lrv_r2;
+  uint32_t lrv_r3;
+} La_nios2_retval;
+
+__BEGIN_DECLS
+
+extern Elf32_Addr la_nios2_gnu_pltenter (Elf32_Sym *__sym, unsigned int __ndx,
+					 uintptr_t *__refcook,
+					 uintptr_t *__defcook,
+					 La_nios2_regs *__regs,
+					 unsigned int *__flags,
+					 const char *__symname,
+					 long int *__framesizep);
+extern unsigned int la_nios2_gnu_pltexit (Elf32_Sym *__sym, unsigned int __ndx,
+					  uintptr_t *__refcook,
+					  uintptr_t *__defcook,
+					  const La_nios2_regs *__inregs,
+					  La_nios2_retval *__outregs,
+					  const char *symname);
+
+__END_DECLS
diff --git a/sysdeps/nios2/bits/setjmp.h b/sysdeps/nios2/bits/setjmp.h
new file mode 100644
index 0000000..4ee4abd
--- /dev/null
+++ b/sysdeps/nios2/bits/setjmp.h
@@ -0,0 +1,31 @@ 
+/* Define the machine-dependent type `jmp_buf'.  Nios II version.
+   Copyright (C) 1992-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _NIOS2_BITS_SETJMP_H
+#define _NIOS2_BITS_SETJMP_H 1
+
+#if !defined(_SETJMP_H) && !defined(_PTHREAD_H)
+# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
+#endif
+
+/* Saves r16-r22 (callee-saved, including GOT pointer), sp (stack pointer),
+   fp (frame pointer), and ra (return address).  */
+typedef int __jmp_buf[10];
+
+#endif /* _NIOS2_BITS_SETJMP_H */
diff --git a/sysdeps/nios2/bsd-_setjmp.S b/sysdeps/nios2/bsd-_setjmp.S
new file mode 100644
index 0000000..4e6a2da
--- /dev/null
+++ b/sysdeps/nios2/bsd-_setjmp.S
@@ -0,0 +1 @@ 
+/* _setjmp is in setjmp.S  */
diff --git a/sysdeps/nios2/bsd-setjmp.S b/sysdeps/nios2/bsd-setjmp.S
new file mode 100644
index 0000000..1da848d
--- /dev/null
+++ b/sysdeps/nios2/bsd-setjmp.S
@@ -0,0 +1 @@ 
+/* setjmp is in setjmp.S  */
diff --git a/sysdeps/nios2/configure.ac b/sysdeps/nios2/configure.ac
new file mode 100644
index 0000000..f05f438
--- /dev/null
+++ b/sysdeps/nios2/configure.ac
@@ -0,0 +1,13 @@ 
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/nios2.
+
+# Nios II big endian is not yet supported.
+AC_CACHE_CHECK([for big endian],
+  [libc_cv_nios2_be],
+  [AC_EGREP_CPP(yes,[#ifdef __nios2_big_endian__
+                      yes
+                     #endif
+  ], libc_cv_nios2_be=yes, libc_cv_nios2_be=no)])
+if test $libc_cv_nios2_be = yes; then
+  AC_MSG_ERROR([Big endian not supported for Nios II])
+fi
diff --git a/sysdeps/nios2/crti.S b/sysdeps/nios2/crti.S
new file mode 100644
index 0000000..9c9030b
--- /dev/null
+++ b/sysdeps/nios2/crti.S
@@ -0,0 +1,96 @@ 
+/* Special .init and .fini section support for Nios II.
+   Copyright (C) 2012-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file with other
+   programs, and to distribute those programs without any restriction
+   coming from the use of this file. (The GNU Lesser General Public
+   License restrictions do apply in other respects; for example, they
+   cover modification of the file, and distribution when not linked
+   into another program.)
+
+   Note that people who make modified versions of this file are not
+   obligated to grant this special exception for their modified
+   versions; it is their choice whether to do so. The GNU Lesser
+   General Public License gives permission to release a modified
+   version without this exception; this exception also makes it
+   possible to release a modified version which carries forward this
+   exception.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* crti.S puts a function prologue at the beginning of the .init and
+   .fini sections and defines global symbols for those addresses, so
+   they can be called as functions.  The symbols _init and _fini are
+   magic and cause the linker to emit DT_INIT and DT_FINI.  */
+
+#include <libc-symbols.h>
+
+#ifndef PREINIT_FUNCTION
+# define PREINIT_FUNCTION __gmon_start__
+#endif
+
+#ifndef PREINIT_FUNCTION_WEAK
+# define PREINIT_FUNCTION_WEAK 1
+#endif
+
+#if PREINIT_FUNCTION_WEAK
+	weak_extern (PREINIT_FUNCTION)
+#else
+	.hidden PREINIT_FUNCTION
+#endif
+
+	.section .init,"ax",@progbits
+	.align	2
+	.global	_init
+	.type	_init, @function
+_init:
+	addi	sp, sp, -8
+	stw	r22, 0(sp)
+	nextpc	r22
+	1:
+	movhi	r8, %hiadj(_gp_got - 1b)
+	addi	r8, r8, %lo(_gp_got - 1b)
+	add	r22, r22, r8
+	stw	ra, 4(sp)
+#if PREINIT_FUNCTION_WEAK
+	movhi	r2, %got_hiadj(PREINIT_FUNCTION)
+	addi	r2, r2, %got_lo(PREINIT_FUNCTION)
+	add	r2, r2, r22
+	ldw	r2, 0(r2)
+	beq	r2, zero, .L5
+#endif
+	movhi	r2, %call_hiadj(PREINIT_FUNCTION)
+	addi	r2, r2, %call_lo(PREINIT_FUNCTION)
+	add	r2, r2, r22
+	ldw	r2, 0(r2)
+	callr	r2
+.L5:
+
+	.section .fini,"ax",@progbits
+	.align	2
+	.global	_fini
+	.type	_fini, @function
+_fini:
+	addi	sp, sp, -8
+	stw	r22, 0(sp)
+	nextpc	r22
+	1:
+	movhi	r8, %hiadj(_gp_got - 1b)
+	addi	r8, r8, %lo(_gp_got - 1b)
+	stw	ra, 4(sp)
+	add	r22, r22, r8
diff --git a/sysdeps/nios2/crtn.S b/sysdeps/nios2/crtn.S
new file mode 100644
index 0000000..324c43c
--- /dev/null
+++ b/sysdeps/nios2/crtn.S
@@ -0,0 +1,49 @@ 
+/* Special .init and .fini section support for Nios II.
+   Copyright (C) 2012-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file with other
+   programs, and to distribute those programs without any restriction
+   coming from the use of this file. (The GNU Lesser General Public
+   License restrictions do apply in other respects; for example, they
+   cover modification of the file, and distribution when not linked
+   into another program.)
+
+   Note that people who make modified versions of this file are not
+   obligated to grant this special exception for their modified
+   versions; it is their choice whether to do so. The GNU Lesser
+   General Public License gives permission to release a modified
+   version without this exception; this exception also makes it
+   possible to release a modified version which carries forward this
+   exception.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* crtn.S puts function epilogues in the .init and .fini sections
+   corresponding to the prologues in crti.S. */
+
+	.section .init,"ax",@progbits
+	ldw	ra, 4(sp)
+	ldw	r22, 0(sp)
+	addi	sp, sp, 8
+	ret
+
+	.section .fini,"ax",@progbits
+	ldw	ra, 4(sp)
+	ldw	r22, 0(sp)
+	addi	sp, sp, 8
+	ret
diff --git a/sysdeps/nios2/dl-init.c b/sysdeps/nios2/dl-init.c
new file mode 100644
index 0000000..de9d495
--- /dev/null
+++ b/sysdeps/nios2/dl-init.c
@@ -0,0 +1,30 @@ 
+/* Copyright (C) 2008-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <elf/dl-init.c>
+
+unsigned int
+internal_function
+_dl_nios2_get_gp_value (struct link_map *main_map)
+{
+  ElfW(Dyn)* dyn = main_map->l_ld;
+  for (dyn = main_map->l_ld; dyn->d_tag != DT_NULL; ++dyn)
+    if (dyn->d_tag == DT_NIOS2_GP)
+      return (unsigned int)(dyn->d_un.d_ptr);
+  return 0;
+}
diff --git a/sysdeps/nios2/dl-machine.h b/sysdeps/nios2/dl-machine.h
new file mode 100644
index 0000000..cc096d0
--- /dev/null
+++ b/sysdeps/nios2/dl-machine.h
@@ -0,0 +1,364 @@ 
+/* Machine-dependent ELF dynamic relocation inline functions.  Nios II version.
+   Copyright (C) 1995-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef dl_machine_h
+#define dl_machine_h
+
+#define ELF_MACHINE_NAME "nios2"
+
+#include <string.h>
+#include <link.h>
+#include <dl-tls.h>
+
+/* Return nonzero iff ELF header is compatible with the running host.  */
+static inline int
+elf_machine_matches_host (const Elf32_Ehdr *ehdr)
+{
+  return ehdr->e_machine == EM_ALTERA_NIOS2;
+}
+
+
+/* Return the link-time address of _DYNAMIC.  Conveniently, this is the
+   first element of the GOT.  */
+static inline Elf32_Addr
+elf_machine_dynamic (void)
+{
+  Elf32_Addr *dynamic;
+  int tmp;
+  asm("nextpc\t%0\n\t"
+      "1: movhi\t%1, %%hiadj(_GLOBAL_OFFSET_TABLE_ - 1b)\n\t"
+      "addi\t%1, %1, %%lo( _GLOBAL_OFFSET_TABLE_ - 1b)\n\t"
+      "add\t%0, %0, %1\n"
+      : "=r" (dynamic), "=r" (tmp));
+  return *dynamic;
+}
+
+
+/* Return the run-time load address of the shared object.  */
+static inline Elf32_Addr
+elf_machine_load_address (void)
+{
+  Elf32_Addr result;
+  int tmp;
+  asm("nextpc\t%0\n\t"
+      "1: movhi\t%1, %%hiadj(1b)\n\t"
+      "addi\t%1, %1, %%lo(1b)\n\t"
+      "sub\t%0, %0, %1\n"
+      : "=r" (result), "=r" (tmp));
+  return result;
+}
+
+/* Set up the loaded object described by L so its unrelocated PLT
+   entries will jump to the on-demand fixup code in dl-runtime.c.  */
+
+static inline int __attribute__ ((always_inline))
+elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
+{
+  extern void _dl_runtime_resolve (Elf32_Word);
+
+  if (l->l_info[DT_JMPREL] && lazy)
+    {
+      /* The GOT entries for functions in the PLT have not yet been filled
+         in.  Their initial contents will arrange when called to load r15 with
+         an offset into the .got section, load r14 with
+	 _GLOBAL_OFFSET_TABLE_[1], and then jump to _GLOBAL_OFFSET_TABLE[2].
+      */
+      Elf32_Addr *got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
+      got[1] = (Elf32_Addr) l;	/* Identify this shared object.  */
+
+      /* This function will get called to fix up the GOT entry indicated by
+	 the offset on the stack, and then jump to the resolved address.  */
+      got[2] = (Elf32_Addr) &_dl_runtime_resolve;
+    }
+
+  return lazy;
+}
+
+/* Initial entry point code for the dynamic linker.
+   The C function `_dl_start' is the real entry point;
+   its return value is the user program's entry point.  */
+
+#define RTLD_START asm("\
+.text\n\
+.globl _start\n\
+.type _start, %function\n\
+_start:\n\
+        /* At start time, all the args are on the stack.  */\n\
+        mov r4, sp\n\
+\n\
+        /* Start the calculation of the GOT pointer.  */\n\
+        nextpc r22\n\
+1:      movhi r8, %hiadj(_gp_got - 1b)\n\
+        addi r8, r8, %lo(_gp_got - 1b)\n\
+\n\
+        /* Figure out where _dl_start will need to return to.  */\n\
+        movhi ra, %hiadj(2f - 1b)\n\
+        addi ra, ra, %lo(2f - 1b)\n\
+        add ra, ra, r22\n\
+\n\
+        /* Finish the calculation of the GOT pointer.  */\n\
+        add r22, r22, r8\n\
+\n\
+        br _dl_start\n\
+\n\
+        /* Save the returned user entry point.  */\n\
+2:      mov r16, r2\n\
+\n\
+        /* Initialize gp.  */\n\
+        ldw r4, %got(_rtld_local)(r22)\n\
+        ldw r4, 0(r4)\n\
+        ldw r8, %call(_dl_nios2_get_gp_value)(r22)\n\
+        callr r8\n\
+        mov gp, r2\n\
+\n\
+        /* Find the number of arguments to skip.  */\n\
+        ldw r8, %got(_dl_skip_args)(r22)\n\
+        ldw r8, 0(r8)\n\
+\n\
+        /* Find the main_map from the GOT.  */\n\
+        ldw r4, %got(_rtld_local)(r22)\n\
+        ldw r4, 0(r4)\n\
+\n\
+        /* Find argc.  */\n\
+        ldw r5, 0(sp)\n\
+        sub r5, r5, r8\n\
+        stw r5, 0(sp)\n\
+\n\
+        /* Find the first unskipped argument.  */\n\
+        slli r8, r8, 2\n\
+        addi r6, sp, 4\n\
+        add r9, r6, r8\n\
+        mov r10, r6\n\
+\n\
+        /* Shuffle argv down.  */\n\
+3:      ldw r11, 0(r9)\n\
+        stw r11, 0(r10)\n\
+        addi r9, r9, 4\n\
+        addi r10, r10, 4\n\
+        bne r11, zero, 3b\n\
+\n\
+        /* Shuffle envp down.  */\n\
+        mov r7, r10\n\
+4:      ldw r11, 0(r9)\n\
+        stw r11, 0(r10)\n\
+        addi r9, r9, 4\n\
+        addi r10, r10, 4\n\
+        bne r11, zero, 4b\n\
+\n\
+        /* Shuffle auxv down.  */\n\
+5:      ldw r11, 4(r9)\n\
+        stw r11, 4(r10)\n\
+        ldw r11, 0(r9)\n\
+        stw r11, 0(r10)\n\
+        addi r9, r9, 8\n\
+        addi r10, r10, 8\n\
+        bne r11, zero, 5b\n\
+\n\
+        /* Update _dl_argv.  */\n\
+        ldw r2, %got(_dl_argv)(r22)\n\
+        stw r6, 0(r2)\n\
+\n\
+        /* Call _dl_init through the PLT.  */\n\
+        ldw r8, %call(_dl_init)(r22)\n\
+        callr r8\n\
+\n\
+        /* Find the finalization function.  */\n\
+        ldw r4, %got(_dl_fini)(r22)\n\
+\n\
+        /* Jump to the user's entry point.  */\n\
+        jmp r16\n\
+");
+
+/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so
+   PLT entries should not be allowed to define the value.
+   ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
+   of the main executable's symbols, as for a COPY reloc.  */
+#define elf_machine_type_class(type)				\
+  ((((type) == R_NIOS2_JUMP_SLOT				\
+     || (type) == R_NIOS2_TLS_DTPMOD				\
+     || (type) == R_NIOS2_TLS_DTPREL				\
+     || (type) == R_NIOS2_TLS_TPREL) * ELF_RTYPE_CLASS_PLT)	\
+   | (((type) == R_NIOS2_COPY) * ELF_RTYPE_CLASS_COPY))
+
+/* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
+#define ELF_MACHINE_JMP_SLOT  R_NIOS2_JUMP_SLOT
+
+/* The Nios II never uses Elf32_Rel relocations.  */
+#define ELF_MACHINE_NO_REL 1
+#define ELF_MACHINE_NO_RELA 0
+
+/* Fixup a PLT entry to bounce directly to the function at VALUE.  */
+
+static inline Elf32_Addr
+elf_machine_fixup_plt (struct link_map *map, lookup_t t,
+		       const Elf32_Rela *reloc,
+		       Elf32_Addr *reloc_addr, Elf32_Addr value)
+{
+  return *reloc_addr = value;
+}
+
+/* Return the final value of a plt relocation.  */
+static inline Elf32_Addr
+elf_machine_plt_value (struct link_map *map, const Elf32_Rela *reloc,
+                       Elf32_Addr value)
+{
+  return value;
+}
+
+/* Names of the architecture-specific auditing callback functions.  */
+#define ARCH_LA_PLTENTER nios2_gnu_pltenter
+#define ARCH_LA_PLTEXIT nios2_gnu_pltexit
+
+#ifndef RTLD_BOOTSTRAP_UDIV
+static inline unsigned int __attribute__((always_inline))
+nios2_rtld_bootstrap_udiv (unsigned int num, unsigned int den)
+{
+  unsigned int bit = 1;
+  unsigned int res = 0;
+
+  while (den < num && bit && !(den & (1L << 31)))
+    {
+      den <<= 1;
+      bit <<= 1;
+    }
+
+  while (bit)
+    {
+      if (num >= den)
+	{
+	  num -= den;
+	  res |= bit;
+	}
+      bit >>= 1;
+      den >>= 1;
+    }
+
+  return res;
+}
+# define RTLD_BOOTSTRAP_UDIV(A, B) nios2_rtld_bootstrap_udiv (A, B)
+#endif
+
+#endif /* dl_machine_h */
+
+#ifdef RESOLVE_MAP
+
+/* Perform the relocation specified by RELOC and SYM (which is fully resolved).
+   LOADADDR is the load address of the object; INFO is an array indexed
+   by DT_* of the .dynamic section info.  */
+
+auto inline void __attribute__ ((always_inline))
+elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
+                  const ElfW(Sym) *sym, const struct r_found_version *version,
+                  void *const reloc_addr_arg, int skip_ifunc)
+{
+  Elf32_Addr *const reloc_addr = reloc_addr_arg;
+  const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
+
+  if (__builtin_expect (r_type == R_NIOS2_RELATIVE, 0))
+    *reloc_addr = map->l_addr + reloc->r_addend;
+  else if (__builtin_expect (r_type == R_NIOS2_NONE, 0))
+    return;
+  else
+    {
+      const Elf32_Sym *const refsym = sym;
+      struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
+      Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
+
+      switch (r_type)
+	{
+        case R_NIOS2_COPY:
+          if (sym == NULL)
+            /* This can happen in trace mode if an object could not be
+               found.  */
+            break;
+          if (sym->st_size > refsym->st_size
+              || (sym->st_size < refsym->st_size && GLRO(dl_verbose)))
+            {
+              const char *strtab;
+
+              strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
+              _dl_error_printf ("\
+%s: Symbol `%s' has different size in shared object, consider re-linking\n",
+				rtld_progname ?: "<program name unknown>",
+				strtab + refsym->st_name);
+            }
+          memcpy (reloc_addr_arg, (void *) value,
+                  MIN (sym->st_size, refsym->st_size));
+          break;
+	case R_NIOS2_GLOB_DAT:
+	case R_NIOS2_JUMP_SLOT:
+# ifdef RTLD_BOOTSTRAP
+          /* Fix weak undefined references.  */
+          if (sym != NULL && sym->st_value == 0)
+            *reloc_addr = 0;
+          else
+# endif
+            *reloc_addr = value;
+          break;
+#ifndef RTLD_BOOTSTRAP
+        case R_NIOS2_TLS_DTPMOD:
+          /* Get the information from the link map returned by the
+             resolv function.  */
+          if (sym_map != NULL)
+            *reloc_addr = sym_map->l_tls_modid;
+          break;
+
+        case R_NIOS2_TLS_DTPREL:
+          *reloc_addr = reloc->r_addend + TLS_DTPREL_VALUE(sym);
+          break;
+
+        case R_NIOS2_TLS_TPREL:
+          if (sym != NULL)
+            {
+              CHECK_STATIC_TLS (map, sym_map);
+              *reloc_addr = reloc->r_addend + TLS_TPREL_VALUE(sym_map, sym);
+            }
+          break;
+#endif
+        case R_NIOS2_BFD_RELOC_32:
+          *reloc_addr = value + reloc->r_addend;
+          break;
+
+	default:
+          _dl_reloc_bad_type (map, r_type, 0);
+          break;
+	}
+    }
+}
+
+auto inline void __attribute__((always_inline))
+elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
+			   void *const reloc_addr_arg)
+{
+  Elf32_Addr *const reloc_addr = reloc_addr_arg;
+  *reloc_addr = l_addr + reloc->r_addend;
+}
+
+auto inline void __attribute__((always_inline))
+elf_machine_lazy_rel (struct link_map *map,
+		      ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
+		      int skip_ifunc)
+{
+  Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
+  if (ELF32_R_TYPE (reloc->r_info) == R_NIOS2_JUMP_SLOT)
+    *reloc_addr += l_addr;
+  else
+    _dl_reloc_bad_type (map, ELF32_R_TYPE (reloc->r_info), 1);
+}
+
+#endif /* RESOLVE_MAP */
diff --git a/sysdeps/nios2/dl-sysdep.h b/sysdeps/nios2/dl-sysdep.h
new file mode 100644
index 0000000..8963259
--- /dev/null
+++ b/sysdeps/nios2/dl-sysdep.h
@@ -0,0 +1,24 @@ 
+/* System-specific settings for dynamic linker code.  Nios II version.
+   Copyright (C) 2009-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include_next <dl-sysdep.h>
+
+/* _dl_argv cannot be attribute_relro, because _dl_start_user
+   might write into it after _dl_start returns.  */
+#define DL_ARGV_NOT_RELRO 1
diff --git a/sysdeps/nios2/dl-tls.h b/sysdeps/nios2/dl-tls.h
new file mode 100644
index 0000000..61483c4
--- /dev/null
+++ b/sysdeps/nios2/dl-tls.h
@@ -0,0 +1,48 @@ 
+/* Thread-local storage handling in the ELF dynamic linker.  Nios II version.
+   Copyright (C) 2012-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+
+/* Type used for the representation of TLS information in the GOT.  */
+typedef struct
+{
+  unsigned long int ti_module;
+  unsigned long int ti_offset;
+} tls_index;
+
+/* The thread pointer points 0x7000 past the first static TLS block.  */
+#define TLS_TP_OFFSET		0x7000
+
+/* Dynamic thread vector pointers point 0x8000 past the start of each
+   TLS block.  */
+#define TLS_DTV_OFFSET		0x8000
+
+/* Compute the value for a GOTTPREL reloc.  */
+#define TLS_TPREL_VALUE(sym_map, sym) \
+  ((sym_map)->l_tls_offset + (sym)->st_value - TLS_TP_OFFSET)
+
+/* Compute the value for a DTPREL reloc.  */
+#define TLS_DTPREL_VALUE(sym) \
+  ((sym)->st_value - TLS_DTV_OFFSET)
+
+extern void *__tls_get_addr (tls_index *ti);
+
+# define GET_ADDR_OFFSET	(ti->ti_offset + TLS_DTV_OFFSET)
+# define __TLS_GET_ADDR(__ti)	(__tls_get_addr (__ti) - TLS_DTV_OFFSET)
+
+/* Value used for dtv entries for which the allocation is delayed.  */
+#define TLS_DTV_UNALLOCATED	((void *) -1l)
diff --git a/sysdeps/nios2/dl-trampoline.S b/sysdeps/nios2/dl-trampoline.S
new file mode 100644
index 0000000..5dc32ea
--- /dev/null
+++ b/sysdeps/nios2/dl-trampoline.S
@@ -0,0 +1,80 @@ 
+/* PLT trampolines.  Nios II version.
+   Copyright (C) 2005-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <libc-symbols.h>
+
+	.text
+	.globl _dl_runtime_resolve
+	cfi_startproc
+_dl_runtime_resolve:
+/* The runtime resolver receives the original function arguments in r4
+   through r7, the shared library identifier from GOT[1]? in r14, and the
+   relocation index times four in r15. It updates the corresponding PLT GOT
+   entry so that the PLT entry will transfer control directly to the target
+   in the future, and then transfers control to the target. */
+	/* Save arguments and return address.  */
+	subi sp, sp, 28
+	cfi_adjust_cfa_offset (28)
+	stw r22, 24(sp)
+	cfi_rel_offset (r22, 24)
+	stw r8, 20(sp)  /* save r8, because this might be a call to mcount */
+	cfi_rel_offset (r8, 20)
+	stw r7, 16(sp)
+	cfi_rel_offset (r7, 16)
+	stw r6, 12(sp)
+	cfi_rel_offset (r6, 12)
+	stw r5, 8(sp)
+	cfi_rel_offset (r5, 8)
+	stw r4, 4(sp)
+	cfi_rel_offset (r4, 4)
+	stw ra, 0(sp)
+	cfi_rel_offset (ra, 0)
+
+	/* Get pointer to linker struct.  */
+	mov r4, r14
+
+	/* Get the relocation offset.  We're given a multiple of 4 and
+	   need a multiple of 12, so multiply by 3. */
+	slli r5, r15, 1
+	add r5, r5, r15
+
+	/* Call the fixup routine.  */
+	nextpc r22
+1:	movhi r2, %hiadj(_gp_got - 1b)
+	addi r2, r2, %lo(_gp_got - 1b)
+	add r22, r22, r2
+	ldw r2, %call(_dl_fixup)(r22)
+	callr r2
+
+	/* Restore the arguments and return address.  */
+	ldw ra, 0(sp)
+	ldw r4, 4(sp)
+	ldw r5, 8(sp)
+	ldw r6, 12(sp)
+	ldw r7, 16(sp)
+	ldw r8, 20(sp)
+	ldw r22, 24(sp)
+	addi sp, sp, 28
+	cfi_adjust_cfa_offset (-28)
+
+	/* Jump to the newly found address.  */
+	jmp r2
+
+	cfi_endproc
diff --git a/sysdeps/nios2/gccframe.h b/sysdeps/nios2/gccframe.h
new file mode 100644
index 0000000..2898897
--- /dev/null
+++ b/sysdeps/nios2/gccframe.h
@@ -0,0 +1,20 @@ 
+/* Copyright (C) 2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define FIRST_PSEUDO_REGISTER 40
+
+#include <sysdeps/generic/gccframe.h>
diff --git a/sysdeps/nios2/gmp-mparam.h b/sysdeps/nios2/gmp-mparam.h
new file mode 100644
index 0000000..876e49e
--- /dev/null
+++ b/sysdeps/nios2/gmp-mparam.h
@@ -0,0 +1,28 @@ 
+/* gmp-mparam.h -- Compiler/machine parameter header file.
+
+Copyright (C) 2014 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library; see the file COPYING.LIB.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#define BITS_PER_MP_LIMB 32
+#define BYTES_PER_MP_LIMB 4
+#define BITS_PER_LONGINT 32
+#define BITS_PER_INT 32
+#define BITS_PER_SHORTINT 16
+#define BITS_PER_CHAR 8
+
+#define IEEE_DOUBLE_BIG_ENDIAN 0
diff --git a/sysdeps/nios2/jmpbuf-offsets.h b/sysdeps/nios2/jmpbuf-offsets.h
new file mode 100644
index 0000000..5047863
--- /dev/null
+++ b/sysdeps/nios2/jmpbuf-offsets.h
@@ -0,0 +1,49 @@ 
+/* Private macros for accessing __jmp_buf contents.  Nios II version.
+   Copyright (C) 2006-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* Save offsets within __jmp_buf.  */
+#define JB_R16 0
+#define JB_R17 1
+#define JB_R18 2
+#define JB_R19 3
+#define JB_R20 4
+#define JB_R21 5
+#define JB_R22 6
+#define JB_SP  7
+#define JB_FP  8
+#define JB_RA  9
+
+#ifndef  __ASSEMBLER__
+#include <setjmp.h>
+#include <stdint.h>
+#include <sysdep.h>
+
+static inline uintptr_t __attribute__ ((unused))
+_jmpbuf_sp (__jmp_buf jmpbuf)
+{
+  uintptr_t sp = jmpbuf[JB_SP];
+#ifdef PTR_DEMANGLE
+  PTR_DEMANGLE (sp);
+#endif
+  return sp;
+}
+#endif
+
+/* Helper for generic ____longjmp_chk(). */
+#define JB_FRAME_ADDRESS(buf) ((void *) _jmpbuf_sp (buf))
diff --git a/sysdeps/nios2/jmpbuf-unwind.h b/sysdeps/nios2/jmpbuf-unwind.h
new file mode 100644
index 0000000..c307b74
--- /dev/null
+++ b/sysdeps/nios2/jmpbuf-unwind.h
@@ -0,0 +1,37 @@ 
+/* Copyright (C) 2005-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <setjmp.h>
+#include <jmpbuf-offsets.h>
+#include <stdint.h>
+#include <unwind.h>
+
+/* Test if longjmp to JMPBUF would unwind the frame
+   containing a local variable at ADDRESS.  */
+
+#define _JMPBUF_UNWINDS(jmpbuf, address, demangle) \
+  ((void *) (address) < (void *) demangle (jmpbuf[JB_SP]))
+
+#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
+  _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
+
+#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
+  ((uintptr_t) (_address) - (_adj) < (uintptr_t) (_jmpbuf_sp (_jmpbuf) - (_adj)))
+
+/* We use the normal longjmp for unwinding.  */
+#define __libc_unwind_longjmp(buf, val) __libc_longjmp (buf, val)
diff --git a/sysdeps/nios2/ldsodefs.h b/sysdeps/nios2/ldsodefs.h
new file mode 100644
index 0000000..0a9dc27
--- /dev/null
+++ b/sysdeps/nios2/ldsodefs.h
@@ -0,0 +1,42 @@ 
+/* Run-time dynamic linker data structures for loaded ELF shared objects.
+   Copyright (C) 2000-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _NIOS2_LDSODEFS_H
+#define _NIOS2_LDSODEFS_H 1
+
+struct La_nios2_regs;
+struct La_nios2_retval;
+
+#define ARCH_PLTENTER_MEMBERS						    \
+    Elf32_Addr (*nios2_gnu_pltenter) (Elf32_Sym *, unsigned int,	    \
+				      uintptr_t *, uintptr_t *,	            \
+				      const struct La_nios2_regs *,         \
+				      unsigned int *, const char *name,     \
+				      long int *framesizep);
+
+#define ARCH_PLTEXIT_MEMBERS						    \
+    unsigned int (*nios2_gnu_pltexit) (Elf64_Sym *, unsigned int,	    \
+				       uintptr_t *, uintptr_t *,	    \
+				       const struct La_nios2_regs *,        \
+				       struct La_nios2_retval *,	    \
+				       const char *);
+
+#include_next <ldsodefs.h>
+
+#endif
diff --git a/sysdeps/nios2/libc-tls.c b/sysdeps/nios2/libc-tls.c
new file mode 100644
index 0000000..f25c989
--- /dev/null
+++ b/sysdeps/nios2/libc-tls.c
@@ -0,0 +1,33 @@ 
+/* Thread-local storage handling in the ELF dynamic linker.  Nios II version.
+   Copyright (C) 2005-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <csu/libc-tls.c>
+#include <dl-tls.h>
+
+/* On Nios II, linker optimizations are not required, so __tls_get_addr
+   can be called even in statically linked binaries.  In this case module
+   must be always 1 and PT_TLS segment exist in the binary, otherwise it
+   would not link.  */
+
+void *
+__tls_get_addr (tls_index *ti)
+{
+  dtv_t *dtv = THREAD_DTV ();
+  return (char *) dtv[1].pointer.val + GET_ADDR_OFFSET;
+}
diff --git a/sysdeps/nios2/libm-test-ulps b/sysdeps/nios2/libm-test-ulps
new file mode 100644
index 0000000..02daaeb
--- /dev/null
+++ b/sysdeps/nios2/libm-test-ulps
@@ -0,0 +1,337 @@ 
+# Begin of automatic generation
+
+# Maximal error of functions:
+Function: "acosh":
+double: 1
+idouble: 1
+
+Function: "asinh":
+double: 1
+float: 1
+ifloat: 1
+
+Function: "atan2":
+float: 1
+ifloat: 1
+
+Function: "atanh":
+float: 1
+ifloat: 1
+
+Function: Real part of "cacos":
+double: 1
+float: 2
+idouble: 1
+ifloat: 2
+
+Function: Imaginary part of "cacos":
+double: 1
+float: 2
+idouble: 1
+ifloat: 2
+
+Function: Real part of "cacosh":
+double: 1
+float: 2
+idouble: 1
+ifloat: 2
+
+Function: Imaginary part of "cacosh":
+double: 1
+float: 2
+idouble: 1
+ifloat: 2
+
+Function: Real part of "casin":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Imaginary part of "casin":
+double: 1
+float: 2
+idouble: 1
+ifloat: 2
+
+Function: Real part of "casinh":
+double: 1
+float: 2
+idouble: 1
+ifloat: 2
+
+Function: Imaginary part of "casinh":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Real part of "catan":
+float: 1
+ifloat: 1
+
+Function: Imaginary part of "catan":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Real part of "catanh":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Imaginary part of "catanh":
+float: 1
+ifloat: 1
+
+Function: "cbrt":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Real part of "ccos":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Imaginary part of "ccos":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Real part of "ccosh":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Imaginary part of "ccosh":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Real part of "cexp":
+double: 2
+float: 1
+idouble: 2
+ifloat: 1
+
+Function: Imaginary part of "cexp":
+double: 1
+float: 2
+idouble: 1
+ifloat: 2
+
+Function: Real part of "clog":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Imaginary part of "clog":
+float: 1
+ifloat: 1
+
+Function: Real part of "clog10":
+double: 2
+float: 2
+idouble: 2
+ifloat: 2
+
+Function: Imaginary part of "clog10":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: "cos":
+float: 1
+ifloat: 1
+
+Function: "cosh":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Real part of "cpow":
+double: 2
+float: 4
+idouble: 2
+ifloat: 4
+
+Function: Imaginary part of "cpow":
+float: 2
+ifloat: 2
+
+Function: Real part of "csin":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Real part of "csinh":
+float: 1
+ifloat: 1
+
+Function: Imaginary part of "csinh":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Real part of "csqrt":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Imaginary part of "csqrt":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Real part of "ctan":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: Imaginary part of "ctan":
+double: 2
+float: 1
+idouble: 2
+ifloat: 1
+
+Function: Real part of "ctanh":
+double: 2
+float: 1
+idouble: 2
+ifloat: 1
+
+Function: Imaginary part of "ctanh":
+double: 2
+float: 2
+idouble: 2
+ifloat: 2
+
+Function: "erf":
+double: 1
+idouble: 1
+
+Function: "erfc":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: "exp10":
+double: 1
+idouble: 1
+
+Function: "expm1":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: "gamma":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: "hypot":
+double: 1
+idouble: 1
+
+Function: "j0":
+double: 2
+float: 2
+idouble: 2
+ifloat: 2
+
+Function: "j1":
+double: 1
+float: 2
+idouble: 1
+ifloat: 2
+
+Function: "jn":
+double: 4
+float: 4
+idouble: 4
+ifloat: 4
+
+Function: "lgamma":
+double: 1
+float: 1
+idouble: 1
+ifloat: 1
+
+Function: "log":
+float: 1
+ifloat: 1
+
+Function: "log10":
+double: 1
+float: 2
+idouble: 1
+ifloat: 2
+
+Function: "log1p":
+float: 1
+ifloat: 1
+
+Function: "pow":
+float: 1
+ifloat: 1
+
+Function: "pow10":
+double: 1
+idouble: 1
+
+Function: "pow_tonearest":
+float: 1
+ifloat: 1
+
+Function: "sin":
+float: 1
+ifloat: 1
+
+Function: "sincos":
+float: 1
+ifloat: 1
+
+Function: "tgamma":
+double: 4
+float: 3
+idouble: 4
+ifloat: 3
+
+Function: "y0":
+double: 2
+float: 1
+idouble: 2
+ifloat: 1
+
+Function: "y1":
+double: 3
+float: 2
+idouble: 3
+ifloat: 2
+
+Function: "yn":
+double: 3
+float: 2
+idouble: 3
+ifloat: 2
+
+# end of automatic generation
diff --git a/sysdeps/nios2/machine-gmon.h b/sysdeps/nios2/machine-gmon.h
new file mode 100644
index 0000000..3adae3f
--- /dev/null
+++ b/sysdeps/nios2/machine-gmon.h
@@ -0,0 +1,67 @@ 
+/* Machine-dependent definitions for profiling support.  Nios II version.
+   Copyright (C) 1996-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+
+#define _MCOUNT_DECL(frompc, selfpc) \
+static void __attribute_used__ __mcount_internal (u_long frompc, u_long selfpc)
+
+/* This macro/func MUST save r4, r5, r6, r7 and r8 because the compiler inserts
+   blind calls to mcount(), ignoring the fact that mcount may clobber
+   registers; therefore, mcount may NOT clobber registers.  */
+
+#if defined(__PIC__) || defined(PIC)
+#define NIOS2_MCOUNT_CALL \
+	"nextpc r3\n\t"                                       \
+	"1: movhi r2, %hiadj(_gp_got - 1b)\n\t" \
+	"addi r2, r2, %lo(_gp_got - 1b)\n\t"    \
+	"add r2, r2, r3\n\t"                                  \
+	"ldw r2, %call(__mcount_internal)(r2)\n\t"              \
+	"callr r2\n\t"
+#else
+#define NIOS2_MCOUNT_CALL \
+	"call\tmcount_internal\n\t"
+#endif
+
+#define MCOUNT						\
+asm(							\
+	".globl _mcount\n\t"				\
+	".type _mcount,@function\n\t"			\
+	"_mcount:\n\t"					\
+	"subi sp, sp, 24\n\t"				\
+	"stw ra, 20(sp)\n\t"				\
+	"stw r8, 16(sp)\n\t"				\
+	"stw r7, 12(sp)\n\t"				\
+	"stw r6, 8(sp)\n\t"				\
+	"stw r5, 4(sp)\n\t"				\
+	"stw r4, 0(sp)\n\t"				\
+	"mov r4, r8\n\t"				\
+	"mov r5, ra\n\t"				\
+	NIOS2_MCOUNT_CALL				\
+	"ldw ra, 20(sp)\n\t"				\
+	"ldw r8, 16(sp)\n\t"				\
+	"ldw r7, 12(sp)\n\t"				\
+	"ldw r6, 8(sp)\n\t"				\
+	"ldw r5, 4(sp)\n\t"				\
+	"ldw r4, 0(sp)\n\t"				\
+	"addi sp, sp, 24\n\t"				\
+	"ret\n\t"					\
+	".size _mcount, . - _mcount\n\t"		\
+);
+
diff --git a/sysdeps/nios2/math-tests.h b/sysdeps/nios2/math-tests.h
new file mode 100644
index 0000000..42cfa15
--- /dev/null
+++ b/sysdeps/nios2/math-tests.h
@@ -0,0 +1,28 @@ 
+/* Configuration for math tests.  Nios II version.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Current Nios II soft-float does not support exceptions or rounding
+   modes.  */
+#define ROUNDING_TESTS_float(MODE)	((MODE) == FE_TONEAREST)
+#define ROUNDING_TESTS_double(MODE)	((MODE) == FE_TONEAREST)
+#define ROUNDING_TESTS_long_double(MODE)	((MODE) == FE_TONEAREST)
+#define EXCEPTION_TESTS_float	0
+#define EXCEPTION_TESTS_double	0
+#define EXCEPTION_TESTS_long_double	0
+
+#include_next <math-tests.h>
diff --git a/sysdeps/nios2/memusage.h b/sysdeps/nios2/memusage.h
new file mode 100644
index 0000000..4af47de
--- /dev/null
+++ b/sysdeps/nios2/memusage.h
@@ -0,0 +1,24 @@ 
+/* Copyright (C) 2000-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+
+#define GETSP() ({ register uintptr_t stack_ptr asm ("%sp"); stack_ptr; })
+
+#define uatomic32_t unsigned int
+
+#include <sysdeps/generic/memusage.h>
diff --git a/sysdeps/nios2/nptl/pthread_spin_lock.c b/sysdeps/nios2/nptl/pthread_spin_lock.c
new file mode 100644
index 0000000..9da9e7d
--- /dev/null
+++ b/sysdeps/nios2/nptl/pthread_spin_lock.c
@@ -0,0 +1,30 @@ 
+/* Copyright (C) 2005-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <atomic.h>
+#include "pthreadP.h"
+
+int
+pthread_spin_lock (pthread_spinlock_t *lock)
+{
+  while (atomic_compare_and_exchange_val_acq (lock, 1, 0) != 0)
+   while (*lock != 0)
+    ;
+
+  return 0;
+}
diff --git a/sysdeps/nios2/nptl/pthread_spin_trylock.c b/sysdeps/nios2/nptl/pthread_spin_trylock.c
new file mode 100644
index 0000000..e9680c8
--- /dev/null
+++ b/sysdeps/nios2/nptl/pthread_spin_trylock.c
@@ -0,0 +1,27 @@ 
+/* Copyright (C) 2005-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <atomic.h>
+#include "pthreadP.h"
+
+int
+pthread_spin_trylock (pthread_spinlock_t *lock)
+{
+  return atomic_compare_and_exchange_val_acq (lock, 1, 0) ? EBUSY : 0;
+}
diff --git a/sysdeps/nios2/nptl/pthreaddef.h b/sysdeps/nios2/nptl/pthreaddef.h
new file mode 100644
index 0000000..9c9c0d3
--- /dev/null
+++ b/sysdeps/nios2/nptl/pthreaddef.h
@@ -0,0 +1,38 @@ 
+/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* Default stack size.  */
+#define ARCH_STACK_DEFAULT_SIZE	(2 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning.  */
+#define STACK_ALIGN		4
+
+/* Minimal stack size after allocating thread descriptor and guard size.  */
+#define MINIMAL_REST_STACK	2048
+
+/* Alignment requirement for TCB.  */
+#define TCB_ALIGNMENT		4
+
+
+/* Location of current stack frame.  */
+#define CURRENT_STACK_FRAME	__builtin_frame_address (0)
+
+
+/* XXX Until we have a better place keep the definitions here.  */
+#define __exit_thread_inline(val) \
+  INLINE_SYSCALL (exit, 1, (val))
diff --git a/sysdeps/nios2/nptl/tcb-offsets.sym b/sysdeps/nios2/nptl/tcb-offsets.sym
new file mode 100644
index 0000000..d9ae952
--- /dev/null
+++ b/sysdeps/nios2/nptl/tcb-offsets.sym
@@ -0,0 +1,14 @@ 
+#include <sysdep.h>
+#include <tls.h>
+
+--
+
+-- Abuse tls.h macros to derive offsets relative to the thread register.
+# undef __thread_self
+# define __thread_self          ((void *) 0)
+# define thread_offsetof(mem)   ((ptrdiff_t) THREAD_SELF + offsetof (struct pthread, mem))
+
+MULTIPLE_THREADS_OFFSET		thread_offsetof (header.multiple_threads)
+PID_OFFSET			thread_offsetof (pid)
+TID_OFFSET			thread_offsetof (tid)
+POINTER_GUARD			(offsetof (tcbhead_t, pointer_guard) - TLS_TCB_OFFSET - sizeof (tcbhead_t))
diff --git a/sysdeps/nios2/nptl/tls.h b/sysdeps/nios2/nptl/tls.h
new file mode 100644
index 0000000..38c2275
--- /dev/null
+++ b/sysdeps/nios2/nptl/tls.h
@@ -0,0 +1,170 @@ 
+/* Definition for thread-local data handling.  NPTL/Nios II version.
+   Copyright (C) 2012-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _TLS_H
+#define _TLS_H	1
+
+#include <dl-sysdep.h>
+
+#ifndef __ASSEMBLER__
+# include <stdbool.h>
+# include <stddef.h>
+# include <stdint.h>
+
+/* Type for the dtv.  */
+typedef union dtv
+{
+  size_t counter;
+  struct
+  {
+    void *val;
+    bool is_static;
+  } pointer;
+} dtv_t;
+
+#else /* __ASSEMBLER__ */
+# include <tcb-offsets.h>
+#endif /* __ASSEMBLER__ */
+
+
+#ifndef __ASSEMBLER__
+
+/* Get system call information.  */
+# include <sysdep.h>
+
+/* The TP points to the start of the thread blocks.  */
+# define TLS_DTV_AT_TP	1
+# define TLS_TCB_AT_TP	0
+
+/* Get the thread descriptor definition.  */
+# include <nptl/descr.h>
+
+typedef struct
+{
+  dtv_t *dtv;
+  uintptr_t pointer_guard;
+  unsigned spare[6];
+} tcbhead_t;
+
+register struct pthread *__thread_self __asm__("r23");
+
+#define READ_THREAD_POINTER() ((void *) __thread_self)
+
+/* This is the size of the initial TCB.  Because our TCB is before the thread
+   pointer, we don't need this.  */
+# define TLS_INIT_TCB_SIZE	0
+
+/* Alignment requirements for the initial TCB.  */
+# define TLS_INIT_TCB_ALIGN	__alignof__ (struct pthread)
+
+/* This is the size of the TCB.  Because our TCB is before the thread
+   pointer, we don't need this.  */
+# define TLS_TCB_SIZE		0
+
+/* Alignment requirements for the TCB.  */
+# define TLS_TCB_ALIGN		__alignof__ (struct pthread)
+
+/* This is the size we need before TCB - actually, it includes the TCB.  */
+# define TLS_PRE_TCB_SIZE \
+  (sizeof (struct pthread)						      \
+   + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
+
+/* The thread pointer (in hardware register r23) points to the end of
+   the TCB + 0x7000, as for PowerPC and MIPS.  */
+# define TLS_TCB_OFFSET 0x7000
+
+/* Install the dtv pointer.  The pointer passed is to the element with
+   index -1 which contain the length.  */
+# define INSTALL_DTV(tcbp, dtvp) \
+  (((tcbhead_t *) (tcbp))[-1].dtv = (dtvp) + 1)
+
+/* Install new dtv for current thread.  */
+# define INSTALL_NEW_DTV(dtv) \
+  (THREAD_DTV() = (dtv))
+
+/* Return dtv of given thread descriptor.  */
+# define GET_DTV(tcbp) \
+  (((tcbhead_t *) (tcbp))[-1].dtv)
+
+/* Code to initially initialize the thread pointer.  */
+# define TLS_INIT_TP(tcbp, secondcall) \
+  (__thread_self = (struct pthread *) ((char *) tcbp + TLS_TCB_OFFSET), NULL)
+
+/* Return the address of the dtv for the current thread.  */
+# define THREAD_DTV() \
+  (((tcbhead_t *) (READ_THREAD_POINTER () - TLS_TCB_OFFSET))[-1].dtv)
+
+/* Return the thread descriptor for the current thread.  */
+# define THREAD_SELF \
+ ((struct pthread *) (READ_THREAD_POINTER ()			     \
+		      - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
+
+/* Magic for libthread_db to know how to do THREAD_SELF.  */
+# define DB_THREAD_SELF \
+  REGISTER (32, 32, 23 * 4, -TLS_PRE_TCB_SIZE - TLS_TCB_OFFSET)
+
+/* Access to data in the thread descriptor is easy.  */
+# define THREAD_GETMEM(descr, member) \
+  descr->member
+# define THREAD_GETMEM_NC(descr, member, idx) \
+  descr->member[idx]
+# define THREAD_SETMEM(descr, member, value) \
+  descr->member = (value)
+# define THREAD_SETMEM_NC(descr, member, idx, value) \
+  descr->member[idx] = (value)
+
+# define THREAD_GET_POINTER_GUARD()				\
+  (((tcbhead_t *) (READ_THREAD_POINTER ()			\
+		   - TLS_TCB_OFFSET))[-1].pointer_guard)
+# define THREAD_SET_POINTER_GUARD(value)	\
+  (THREAD_GET_POINTER_GUARD () = (value))
+# define THREAD_COPY_POINTER_GUARD(descr)				\
+  (((tcbhead_t *) ((void *) (descr)					\
+		   + TLS_PRE_TCB_SIZE))[-1].pointer_guard		\
+   = THREAD_GET_POINTER_GUARD())
+
+/* l_tls_offset == 0 is perfectly valid on Nios II, so we have to use some
+   different value to mean unset l_tls_offset.  */
+# define NO_TLS_OFFSET		-1
+
+/* Get and set the global scope generation counter in struct pthread.  */
+#define THREAD_GSCOPE_FLAG_UNUSED 0
+#define THREAD_GSCOPE_FLAG_USED   1
+#define THREAD_GSCOPE_FLAG_WAIT   2
+#define THREAD_GSCOPE_RESET_FLAG() \
+  do									     \
+    { int __res								     \
+	= atomic_exchange_rel (&THREAD_SELF->header.gscope_flag,	     \
+			       THREAD_GSCOPE_FLAG_UNUSED);		     \
+      if (__res == THREAD_GSCOPE_FLAG_WAIT)				     \
+	lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE);   \
+    }									     \
+  while (0)
+#define THREAD_GSCOPE_SET_FLAG() \
+  do									     \
+    {									     \
+      THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED;	     \
+      atomic_write_barrier ();						     \
+    }									     \
+  while (0)
+#define THREAD_GSCOPE_WAIT() \
+  GL(dl_wait_lookup_done) ()
+
+#endif /* __ASSEMBLER__ */
+
+#endif	/* tls.h */
diff --git a/sysdeps/nios2/preconfigure b/sysdeps/nios2/preconfigure
new file mode 100644
index 0000000..4b5bd49
--- /dev/null
+++ b/sysdeps/nios2/preconfigure
@@ -0,0 +1,6 @@ 
+case "$machine" in
+nios2*)
+	base_machine=nios2
+	machine=nios2
+	;;
+esac
diff --git a/sysdeps/nios2/s_fma.c b/sysdeps/nios2/s_fma.c
new file mode 100644
index 0000000..d9613fa
--- /dev/null
+++ b/sysdeps/nios2/s_fma.c
@@ -0,0 +1 @@ 
+#include <soft-fp/fmadf4.c>
diff --git a/sysdeps/nios2/s_fmaf.c b/sysdeps/nios2/s_fmaf.c
new file mode 100644
index 0000000..aa5c9b2
--- /dev/null
+++ b/sysdeps/nios2/s_fmaf.c
@@ -0,0 +1 @@ 
+#include <soft-fp/fmasf4.c>
diff --git a/sysdeps/nios2/setjmp.S b/sysdeps/nios2/setjmp.S
new file mode 100644
index 0000000..c3c9da1
--- /dev/null
+++ b/sysdeps/nios2/setjmp.S
@@ -0,0 +1,76 @@ 
+/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.
+*/
+
+#include <sysdep.h>
+#include <jmpbuf-offsets.h>
+
+	.text
+ENTRY(setjmp)
+	movi	r5, 1
+	br	__sigsetjmp
+END(setjmp)
+
+ENTRY(_setjmp)
+	mov	r5, zero
+	br	__sigsetjmp
+END(_setjmp)
+libc_hidden_def (_setjmp)
+
+/* Save the current program position in ENV and return 0.  */
+ENTRY(__sigsetjmp)
+#ifdef	PTR_MANGLE
+	PTR_MANGLE_GUARD (r9)
+#endif
+	stw	r16, (JB_R16*4)(r4)
+	stw	r17, (JB_R17*4)(r4)
+	stw	r18, (JB_R18*4)(r4)
+	stw	r19, (JB_R19*4)(r4)
+	stw	r20, (JB_R20*4)(r4)
+	stw	r21, (JB_R21*4)(r4)
+	stw	r22, (JB_R22*4)(r4)
+#ifdef	PTR_MANGLE
+	PTR_MANGLE (r6, ra, r9)
+	PTR_MANGLE (r7, fp, r9)
+	PTR_MANGLE (r8, sp, r9)
+	stw	r6,  (JB_RA*4)(r4)
+	stw	r7,  (JB_FP*4)(r4)
+	stw	r8,  (JB_SP*4)(r4)
+#else
+	stw	ra,  (JB_RA*4)(r4)
+	stw	fp,  (JB_FP*4)(r4)
+	stw	sp,  (JB_SP*4)(r4)
+#endif
+#if defined NOT_IN_libc && defined IS_IN_rtld
+	/* In ld.so we never save the signal mask.  */
+	mov r2, zero
+	ret
+#else
+	/* Save the signal mask if requested.  */
+#if defined(__PIC__) || defined(PIC)
+        nextpc r2
+1:	movhi r3, %hiadj(__sigjmp_save - 1b)
+	addi r3, r3, %lo(__sigjmp_save - 1b)
+	add r2, r2, r3
+	jmp r2
+#else
+	jmpi __sigjmp_save
+#endif
+#endif
+END (__sigsetjmp)
+libc_hidden_def (__sigsetjmp)
diff --git a/sysdeps/nios2/shlib-versions b/sysdeps/nios2/shlib-versions
new file mode 100644
index 0000000..2e40c18
--- /dev/null
+++ b/sysdeps/nios2/shlib-versions
@@ -0,0 +1,2 @@ 
+nios2-.*-linux.*         DEFAULT                 GLIBC_2.20
+nios2-.*-linux.*         ld=ld-linux-nios2.so.1
diff --git a/sysdeps/nios2/soft-fp/sfp-machine.h b/sysdeps/nios2/soft-fp/sfp-machine.h
new file mode 100644
index 0000000..95eefc1
--- /dev/null
+++ b/sysdeps/nios2/soft-fp/sfp-machine.h
@@ -0,0 +1,51 @@ 
+#define _FP_W_TYPE_SIZE		32
+#define _FP_W_TYPE		unsigned long
+#define _FP_WS_TYPE		signed long
+#define _FP_I_TYPE		long
+
+#define _FP_MUL_MEAT_S(R,X,Y)				\
+  _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
+#define _FP_MUL_MEAT_D(R,X,Y)				\
+  _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
+#define _FP_MUL_MEAT_Q(R,X,Y)				\
+  _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
+
+#define _FP_MUL_MEAT_DW_S(R,X,Y)				\
+  _FP_MUL_MEAT_DW_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
+#define _FP_MUL_MEAT_DW_D(R,X,Y)				\
+  _FP_MUL_MEAT_DW_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
+#define _FP_MUL_MEAT_DW_Q(R,X,Y)				\
+  _FP_MUL_MEAT_DW_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
+
+#define _FP_DIV_MEAT_S(R,X,Y)	_FP_DIV_MEAT_1_loop(S,R,X,Y)
+#define _FP_DIV_MEAT_D(R,X,Y)	_FP_DIV_MEAT_2_udiv(D,R,X,Y)
+#define _FP_DIV_MEAT_Q(R,X,Y)	_FP_DIV_MEAT_4_udiv(Q,R,X,Y)
+
+#define _FP_NANFRAC_S		((_FP_QNANBIT_S << 1) - 1)
+#define _FP_NANFRAC_D		((_FP_QNANBIT_D << 1) - 1), -1
+#define _FP_NANFRAC_Q		((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1
+#define _FP_NANSIGN_S		0
+#define _FP_NANSIGN_D		0
+#define _FP_NANSIGN_Q		0
+
+#define _FP_KEEPNANFRACP 1
+#define _FP_QNANNEGATEDP 0
+
+/* This is arbitrarily taken from the PowerPC version.  */
+#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP)			\
+  do {								\
+    if ((_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)		\
+	&& !(_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs))	\
+      {								\
+	R##_s = Y##_s;						\
+	_FP_FRAC_COPY_##wc(R,Y);				\
+      }								\
+    else							\
+      {								\
+	R##_s = X##_s;						\
+	_FP_FRAC_COPY_##wc(R,X);				\
+      }								\
+    R##_c = FP_CLS_NAN;						\
+  } while (0)
+
+#define _FP_TININESS_AFTER_ROUNDING 0
diff --git a/sysdeps/nios2/sotruss-lib.c b/sysdeps/nios2/sotruss-lib.c
new file mode 100644
index 0000000..7154417
--- /dev/null
+++ b/sysdeps/nios2/sotruss-lib.c
@@ -0,0 +1,51 @@ 
+/* Override generic sotruss-lib.c to define actual functions for Nios II.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define HAVE_ARCH_PLTENTER
+#define HAVE_ARCH_PLTEXIT
+
+#include <elf/sotruss-lib.c>
+
+ElfW(Addr)
+la_nios2_gnu_pltenter (ElfW(Sym) *sym __attribute__ ((unused)),
+		       unsigned int ndx __attribute__ ((unused)),
+		       uintptr_t *refcook, uintptr_t *defcook,
+		       La_nios2_regs *regs, unsigned int *flags,
+		       const char *symname, long int *framesizep)
+{
+  print_enter (refcook, defcook, symname,
+	       regs->lr_reg[0], regs->lr_reg[1], regs->lr_reg[2],
+	       *flags);
+
+  /* No need to copy anything, we will not need the parameters in any case.  */
+  *framesizep = 0;
+
+  return sym->st_value;
+}
+
+unsigned int
+la_nios2_gnu_pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
+		      uintptr_t *defcook,
+		      const struct La_nios2_regs *inregs,
+		      struct La_nios2_retval *outregs, const char *symname)
+{
+  print_exit (refcook, defcook, symname, outregs->lrv_r2);
+
+  return 0;
+}
diff --git a/sysdeps/nios2/stackguard-macros.h b/sysdeps/nios2/stackguard-macros.h
new file mode 100644
index 0000000..55a5771
--- /dev/null
+++ b/sysdeps/nios2/stackguard-macros.h
@@ -0,0 +1,6 @@ 
+#include <stdint.h>
+
+extern uintptr_t __stack_chk_guard;
+#define STACK_CHK_GUARD __stack_chk_guard
+
+#define POINTER_CHK_GUARD THREAD_GET_POINTER_GUARD()
diff --git a/sysdeps/nios2/stackinfo.h b/sysdeps/nios2/stackinfo.h
new file mode 100644
index 0000000..fd2e328
--- /dev/null
+++ b/sysdeps/nios2/stackinfo.h
@@ -0,0 +1,33 @@ 
+/* Copyright (C) 2012-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This file contains a bit of information about the stack allocation
+   of the processor.  */
+
+#ifndef _STACKINFO_H
+#define _STACKINFO_H	1
+
+#include <elf.h>
+
+/* On Nios II the stack grows down.  */
+#define _STACK_GROWS_DOWN	1
+
+/* Default to an executable stack.  PF_X can be overridden if PT_GNU_STACK is
+ * present, but it is presumed absent.  */
+#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X)
+
+#endif	/* stackinfo.h */
diff --git a/sysdeps/nios2/start.S b/sysdeps/nios2/start.S
new file mode 100644
index 0000000..0ff2e30
--- /dev/null
+++ b/sysdeps/nios2/start.S
@@ -0,0 +1,147 @@ 
+/* Startup code for Nios II
+   Copyright (C) 1995-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file with other
+   programs, and to distribute those programs without any restriction
+   coming from the use of this file. (The GNU Lesser General Public
+   License restrictions do apply in other respects; for example, they
+   cover modification of the file, and distribution when not linked
+   into another program.)
+
+   Note that people who make modified versions of this file are not
+   obligated to grant this special exception for their modified
+   versions; it is their choice whether to do so. The GNU Lesser
+   General Public License gives permission to release a modified
+   version without this exception; this exception also makes it
+   possible to release a modified version which carries forward this
+   exception.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* This is the canonical entry point, usually the first thing in the text
+   segment.
+
+	Note that the code in the .init section has already been run.
+	This includes _init and _libc_init
+
+	The stack pointer, sp, will point to the argument count on the stack.
+	The initial state of the stack when a userspace process is started is:
+
+	    Purpose			Start Address	Length
+	    Unspecified			High Addresses
+	    Referenced strings, etc.			Varies
+	    Unspecified
+	    Null auxilliary vector entry		4bytes
+	    Auxilliary vector entries			8bytes each
+	    NULL terminator for envp			4bytes
+	    Environment pointers	sp+8+4*argc	4bytes each
+	    NULL terminator for argv	sp+4+4*argc	4bytes
+	    Argument pointers		sp+4		4bytes each
+	    Argument count		sp		4bytes
+	    Unspecified			Low Addresses
+
+	If the application should register a destructor function with atexit,
+	the pointer will be placed in r4. Otherwise r4 will be zero.
+
+	The contents of all other registers are unspecified. User code should
+	set fp to zero to mark the end of the frame chain.
+
+	The auxilliary vector is a series of pairs of 32-bit tag and 32-bit
+	value, terminated by an AT_NULL tag.
+*/
+
+	.text
+	.globl _start
+	.type _start,%function
+_start:
+	/* Set up the global pointer.  */
+	movhi	gp, %hiadj(_gp)
+	addi	gp, gp, %lo(_gp)
+
+	/* Save the stack pointer.  */
+	mov	r2, sp
+
+	/* Create room on the stack for the fini, rtld_fini and stack_end args
+	   to __libc_start_main. */
+	subi	sp, sp, 12
+
+	/* Push stack_end */
+	stw	r2, 8(sp)
+
+	/* Push rtld_fini */
+	stw	r4, 4(sp)
+
+	/* Set up the GOT pointer.  */
+	nextpc	r22
+1:	movhi	r2, %hiadj(_gp_got - 1b)
+	addi	r2, r2, %lo(_gp_got - 1b)
+	add	r22, r22, r2
+
+	/* Push fini */
+	movhi	r8, %call_hiadj(__libc_csu_fini)
+	addi	r8, r8, %call_lo(__libc_csu_fini)
+	add	r8, r8, r22
+	ldw	r8, 0(r8)
+	stw	r8, 0(sp)
+
+	/* r7 == init */
+	movhi	r7, %call_hiadj(__libc_csu_init)
+	addi	r7, r7, %call_lo(__libc_csu_init)
+	add	r7, r7, r22
+	ldw	r7, 0(r7)
+
+	/* r6 == argv */
+	addi	r6, sp, 16
+
+	/* r5 == argc */
+	ldw	r5, 12(sp)
+
+	/* r4 == main */
+	movhi	r4, %call_hiadj(main)
+	addi	r4, r4, %call_lo(main)
+	add	r4, r4, r22
+	ldw	r4, 0(r4)
+
+	/* fp == 0 */
+	mov	fp, zero
+
+	/* __libc_start_main (main, argc, argv, init, fini, rtld_fini,
+			      stack_end) */
+
+	/* Let the libc call main and exit with its return code.  */
+	movhi	r2, %call_hiadj(__libc_start_main)
+	addi	r2, r2, %call_lo(__libc_start_main)
+	add	r2, r2, r22
+	ldw	r2, 0(r2)
+	callr	r2
+
+	/* should never get here....*/
+	movhi	r2, %call_hiadj(abort)
+	addi	r2, r2, %call_lo(abort)
+	add	r2, r2, r22
+	ldw	r2, 0(r2)
+	callr	r2
+
+/* Define a symbol for the first piece of initialized data.  */
+	.data
+	.globl __data_start
+__data_start:
+	.long 0
+	.weak data_start
+	data_start = __data_start
diff --git a/sysdeps/nios2/sysdep.h b/sysdeps/nios2/sysdep.h
new file mode 100644
index 0000000..2e907db
--- /dev/null
+++ b/sysdeps/nios2/sysdep.h
@@ -0,0 +1,65 @@ 
+/* Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdeps/generic/sysdep.h>
+
+#ifdef	__ASSEMBLER__
+
+/* Syntactic details of assembler.  */
+
+#define ASM_SIZE_DIRECTIVE(name) .size name,.-name
+
+#define ENTRY(name)						 \
+  .globl C_SYMBOL_NAME(name);					 \
+  .type C_SYMBOL_NAME(name),%function;				 \
+  C_LABEL(name)							 \
+  cfi_startproc;						 \
+  CALL_MCOUNT;
+
+#undef  END
+#define END(name)				\
+  cfi_endproc;					\
+  ASM_SIZE_DIRECTIVE(name)
+
+#ifdef PROF
+
+# ifdef __PIC__
+#  define CALL_MCOUNT				\
+  mov r8, ra;					\
+  nextpc r2;					\
+1:						\
+  movhi r3, %hiadj(_gp_got - 1b);		\
+  addi r3, r3, %lo(_gp_got - 1b);		\
+  add r2, r2, r3;				\
+  ldw r2, %call(_mcount)(r2);			\
+  callr r2;					\
+  mov ra, r8;					\
+  ret;
+# else
+#  define CALL_MCOUNT				\
+  mov r8, ra;					\
+  call _mount;					\
+  mov ra, r8;					\
+  ret;
+# endif
+
+#else
+# define CALL_MCOUNT		/* Do nothing.  */
+#endif
+
+#endif	/* __ASSEMBLER__ */
diff --git a/sysdeps/nios2/tls-macros.h b/sysdeps/nios2/tls-macros.h
new file mode 100644
index 0000000..7029530
--- /dev/null
+++ b/sysdeps/nios2/tls-macros.h
@@ -0,0 +1,46 @@ 
+#define TLS_LE(x)					\
+  ({ int *__result;					\
+     asm ("addi %0, r23, %%tls_le(" #x ")"		\
+	  : "=r" (__result));		                \
+     __result; })
+
+#define TLS_IE(x)					\
+  ({ int *__result;					\
+     int __tmp;                                         \
+     asm ("nextpc %0 ; "                                \
+          "1: movhi %1, %%hiadj(_gp_got - 1b) ; "	\
+          "addi %1, %1, %%lo(_gp_got - 1b) ; "		\
+          "add %0, %0, %1 ; "                           \
+          "ldw %1, %%tls_ie(" #x ")(%0) ; "        	\
+	  "add %1, r23, %1"              		\
+          : "=&r" (__tmp), "=&r" (__result));           \
+     __result; })
+
+#define TLS_LD(x)					\
+  ({ char *__result;					\
+     char *__result2;                                   \
+     int *__result3;                                    \
+     int __tmp;                                         \
+     extern void *__tls_get_addr (void *);		\
+     asm ("nextpc %0 ; "                                \
+          "1: movhi %1, %%hiadj(_gp_got - 1b) ; "	\
+          "addi %1, %1, %%lo(_gp_got - 1b) ; "		\
+          "add %0, %0, %1 ; "                           \
+          "addi %0, %0, %%tls_ldm(" #x ")"              \
+          : "=r" (__result), "=r" (__tmp));             \
+     __result2 = (char *)__tls_get_addr (__result);	\
+     asm ("addi %0, %1, %%tls_ldo(" #x ")"              \
+	  : "=r" (__result3) : "r" (__result2));        \
+     __result3; })
+
+#define TLS_GD(x)					\
+  ({ int *__result;					\
+     int __tmp;                                         \
+     extern void *__tls_get_addr (void *);		\
+     asm ("nextpc %0 ; "                                \
+          "1: movhi %1, %%hiadj(_gp_got - 1b) ; "	\
+          "addi %1, %1, %%lo(_gp_got - 1b) ; "		\
+          "add %0, %0, %1 ; "                           \
+          "addi %0, %0, %%tls_gd(" #x ")"		\
+	  : "=r" (__result), "=r" (__tmp));		\
+     (int *)__tls_get_addr (__result); })
diff --git a/sysdeps/nios2/tst-audit.h b/sysdeps/nios2/tst-audit.h
new file mode 100644
index 0000000..5c5c4be
--- /dev/null
+++ b/sysdeps/nios2/tst-audit.h
@@ -0,0 +1,24 @@ 
+/* Definitions for testing PLT entry/exit auditing.  Nios II version.
+   Copyright (C) 2009-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#define pltenter la_nios2_gnu_pltenter
+#define pltexit la_nios2_gnu_pltexit
+#define La_regs La_nios2_regs
+#define La_retval La_nios2_retval
+#define int_retval lrv_r2