Sebastian Huber
2018-07-27 08:28:47 UTC
Signed-off-by: Sebastian Huber <***@embedded-brains.de>
---
libgloss/riscv/crt0.S | 11 -----------
newlib/libc/misc/fini.c | 5 +++++
newlib/libc/misc/init.c | 5 +++++
newlib/libc/misc/local.h | 29 +++++++++++++++++++++++++++++
4 files changed, 39 insertions(+), 11 deletions(-)
create mode 100644 newlib/libc/misc/local.h
diff --git a/libgloss/riscv/crt0.S b/libgloss/riscv/crt0.S
index 3d2a12de5..588becfae 100644
--- a/libgloss/riscv/crt0.S
+++ b/libgloss/riscv/crt0.S
@@ -41,14 +41,3 @@ _start:
call main
tail exit
.size _start, .-_start
-
- .global _init
- .type _init, @function
- .global _fini
- .type _fini, @function
-_init:
-_fini:
- # These don't have to do anything since we use init_array/fini_array.
- ret
- .size _init, .-_init
- .size _fini, .-_fini
diff --git a/newlib/libc/misc/fini.c b/newlib/libc/misc/fini.c
index ab4203bf8..be1089b8e 100644
--- a/newlib/libc/misc/fini.c
+++ b/newlib/libc/misc/fini.c
@@ -12,12 +12,15 @@
/* Handle ELF .{pre_init,init,fini}_array sections. */
#include <sys/types.h>
+#include "local.h"
#ifdef HAVE_INITFINI_ARRAY
extern void (*__fini_array_start []) (void) __attribute__((weak));
extern void (*__fini_array_end []) (void) __attribute__((weak));
+#ifndef _MISC_NO_INIT_FINI
extern void _fini (void);
+#endif
/* Run all the cleanup routines. */
void
@@ -30,6 +33,8 @@ __libc_fini_array (void)
for (i = count; i > 0; i--)
__fini_array_start[i-1] ();
+#ifndef _MISC_NO_INIT_FINI
_fini ();
+#endif
}
#endif
diff --git a/newlib/libc/misc/init.c b/newlib/libc/misc/init.c
index c85d6020f..090997062 100644
--- a/newlib/libc/misc/init.c
+++ b/newlib/libc/misc/init.c
@@ -12,6 +12,7 @@
/* Handle ELF .{pre_init,init,fini}_array sections. */
#include <sys/types.h>
+#include "local.h"
#ifdef HAVE_INITFINI_ARRAY
@@ -21,7 +22,9 @@ extern void (*__preinit_array_end []) (void) __attribute__((weak));
extern void (*__init_array_start []) (void) __attribute__((weak));
extern void (*__init_array_end []) (void) __attribute__((weak));
+#ifndef _MISC_NO_INIT_FINI
extern void _init (void);
+#endif
/* Iterate over all the init routines. */
void
@@ -34,7 +37,9 @@ __libc_init_array (void)
for (i = 0; i < count; i++)
__preinit_array_start[i] ();
+#ifndef _MISC_NO_INIT_FINI
_init ();
+#endif
count = __init_array_end - __init_array_start;
for (i = 0; i < count; i++)
diff --git a/newlib/libc/misc/local.h b/newlib/libc/misc/local.h
new file mode 100644
index 000000000..dc16e11b7
--- /dev/null
+++ b/newlib/libc/misc/local.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined __riscv
+#define _MISC_NO_INIT_FINI
+#endif
---
libgloss/riscv/crt0.S | 11 -----------
newlib/libc/misc/fini.c | 5 +++++
newlib/libc/misc/init.c | 5 +++++
newlib/libc/misc/local.h | 29 +++++++++++++++++++++++++++++
4 files changed, 39 insertions(+), 11 deletions(-)
create mode 100644 newlib/libc/misc/local.h
diff --git a/libgloss/riscv/crt0.S b/libgloss/riscv/crt0.S
index 3d2a12de5..588becfae 100644
--- a/libgloss/riscv/crt0.S
+++ b/libgloss/riscv/crt0.S
@@ -41,14 +41,3 @@ _start:
call main
tail exit
.size _start, .-_start
-
- .global _init
- .type _init, @function
- .global _fini
- .type _fini, @function
-_init:
-_fini:
- # These don't have to do anything since we use init_array/fini_array.
- ret
- .size _init, .-_init
- .size _fini, .-_fini
diff --git a/newlib/libc/misc/fini.c b/newlib/libc/misc/fini.c
index ab4203bf8..be1089b8e 100644
--- a/newlib/libc/misc/fini.c
+++ b/newlib/libc/misc/fini.c
@@ -12,12 +12,15 @@
/* Handle ELF .{pre_init,init,fini}_array sections. */
#include <sys/types.h>
+#include "local.h"
#ifdef HAVE_INITFINI_ARRAY
extern void (*__fini_array_start []) (void) __attribute__((weak));
extern void (*__fini_array_end []) (void) __attribute__((weak));
+#ifndef _MISC_NO_INIT_FINI
extern void _fini (void);
+#endif
/* Run all the cleanup routines. */
void
@@ -30,6 +33,8 @@ __libc_fini_array (void)
for (i = count; i > 0; i--)
__fini_array_start[i-1] ();
+#ifndef _MISC_NO_INIT_FINI
_fini ();
+#endif
}
#endif
diff --git a/newlib/libc/misc/init.c b/newlib/libc/misc/init.c
index c85d6020f..090997062 100644
--- a/newlib/libc/misc/init.c
+++ b/newlib/libc/misc/init.c
@@ -12,6 +12,7 @@
/* Handle ELF .{pre_init,init,fini}_array sections. */
#include <sys/types.h>
+#include "local.h"
#ifdef HAVE_INITFINI_ARRAY
@@ -21,7 +22,9 @@ extern void (*__preinit_array_end []) (void) __attribute__((weak));
extern void (*__init_array_start []) (void) __attribute__((weak));
extern void (*__init_array_end []) (void) __attribute__((weak));
+#ifndef _MISC_NO_INIT_FINI
extern void _init (void);
+#endif
/* Iterate over all the init routines. */
void
@@ -34,7 +37,9 @@ __libc_init_array (void)
for (i = 0; i < count; i++)
__preinit_array_start[i] ();
+#ifndef _MISC_NO_INIT_FINI
_init ();
+#endif
count = __init_array_end - __init_array_start;
for (i = 0; i < count; i++)
diff --git a/newlib/libc/misc/local.h b/newlib/libc/misc/local.h
new file mode 100644
index 000000000..dc16e11b7
--- /dev/null
+++ b/newlib/libc/misc/local.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined __riscv
+#define _MISC_NO_INIT_FINI
+#endif
--
2.13.7
2.13.7