[PATCH 1/2] score: Add RTEMS_WEAK

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Jul 23 12:21:33 UTC 2020


Update #4032.
---
 cpukit/include/rtems/score/basedefs.h  | 12 +++++++
 testsuites/sptests/Makefile.am         |  2 +-
 testsuites/sptests/spmisc01/init.c     | 15 ++++++++
 testsuites/sptests/spmisc01/spmisc01.h | 45 ++++++++++++++++++++++++
 testsuites/sptests/spmisc01/strong.c   | 47 ++++++++++++++++++++++++++
 5 files changed, 120 insertions(+), 1 deletion(-)
 create mode 100644 testsuites/sptests/spmisc01/spmisc01.h
 create mode 100644 testsuites/sptests/spmisc01/strong.c

diff --git a/cpukit/include/rtems/score/basedefs.h b/cpukit/include/rtems/score/basedefs.h
index e301292375..a934507d80 100644
--- a/cpukit/include/rtems/score/basedefs.h
+++ b/cpukit/include/rtems/score/basedefs.h
@@ -197,6 +197,18 @@
   #define RTEMS_ALIAS( _target )
 #endif
 
+/**
+ * @brief Instructs the compiler to define a weak function.
+ *
+ * Use this attribute for function definitions.  Do not use it for function
+ * declarations.
+ */
+#if defined(__GNUC__)
+  #define RTEMS_WEAK __attribute__((__weak__))
+#else
+  #define RTEMS_WEAK
+#endif
+
 /**
  * @brief Instructs the compiler to generate a weak alias to the specified
  * target function.
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index 5404ba4302..854ec3daf8 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -1409,7 +1409,7 @@ if TEST_spmisc01
 sp_tests += spmisc01
 sp_screens += spmisc01/spmisc01.scn
 sp_docs += spmisc01/spmisc01.doc
-spmisc01_SOURCES = spmisc01/init.c
+spmisc01_SOURCES = spmisc01/init.c spmisc01/strong.c
 spmisc01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spmisc01) \
 	$(support_includes)
 endif
diff --git a/testsuites/sptests/spmisc01/init.c b/testsuites/sptests/spmisc01/init.c
index 9090069973..e64fa4e480 100644
--- a/testsuites/sptests/spmisc01/init.c
+++ b/testsuites/sptests/spmisc01/init.c
@@ -21,6 +21,8 @@
 
 #include <tmacros.h>
 
+#include "spmisc01.h"
+
 const char rtems_test_name[] = "SPMISC 1";
 
 RTEMS_INLINE_ROUTINE int inline_func(void)
@@ -70,6 +72,16 @@ static int alias_func(void) RTEMS_ALIAS(noinline_func);
 
 int weak_alias_func(void) RTEMS_WEAK_ALIAS(noinline_func);
 
+RTEMS_WEAK int weak_or_strong(void)
+{
+  return 99;
+}
+
+RTEMS_WEAK int weak_2(void)
+{
+  return 111;
+}
+
 static char aligned_variable RTEMS_ALIGNED(64);
 
 typedef struct {
@@ -205,6 +217,9 @@ static void Init(rtems_task_argument arg)
   rtems_test_assert(sizeof(packed_struct) == 5);
   rtems_test_assert(alias_func() == 14);
   rtems_test_assert(weak_alias_func() == 14);
+  pull_in_strong();
+  rtems_test_assert(weak_or_strong() == 77);
+  rtems_test_assert(weak_2() == 111);
   rtems_test_assert(((uintptr_t) &aligned_variable) % 64 == 0);
   rtems_test_assert(offsetof(aligned_member_struct, aligned_member) % 64 == 0);
   unreachable();
diff --git a/testsuites/sptests/spmisc01/spmisc01.h b/testsuites/sptests/spmisc01/spmisc01.h
new file mode 100644
index 0000000000..6dbf9ca23c
--- /dev/null
+++ b/testsuites/sptests/spmisc01/spmisc01.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+ */
+
+#ifndef _SPMISC01_H
+#define _SPMISC01_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int weak_or_strong(void);
+
+void pull_in_strong(void);
+
+int weak_2(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SPMISC01_H */
diff --git a/testsuites/sptests/spmisc01/strong.c b/testsuites/sptests/spmisc01/strong.c
new file mode 100644
index 0000000000..6341131b67
--- /dev/null
+++ b/testsuites/sptests/spmisc01/strong.c
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "spmisc01.h"
+
+int weak_or_strong(void)
+{
+  return 77;
+}
+
+void pull_in_strong(void)
+{
+  /* Do nothing */
+}
+
+RTEMS_WEAK int weak_2(void)
+{
+  return 222;
+}
-- 
2.26.2



More information about the devel mailing list