[PATCH 1/2] score: Add RTEMS_WEAK

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Apr 9 04:50:22 UTC 2020


---
 cpukit/include/rtems/score/basedefs.h  | 12 ++++++++
 testsuites/sptests/Makefile.am         |  2 +-
 testsuites/sptests/spmisc01/init.c     |  9 ++++++
 testsuites/sptests/spmisc01/spmisc01.h | 51 ++++++++++++++++++++++++++++++++++
 testsuites/sptests/spmisc01/strong.c   | 42 ++++++++++++++++++++++++++++
 5 files changed, 115 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 4589bea4aa..87f980ccda 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 62bb1aa685..a8b9ac482a 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -1464,7 +1464,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 8d713c4219..d18402a13c 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,11 @@ 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;
+}
+
 static char aligned_variable RTEMS_ALIGNED(64);
 
 typedef struct {
@@ -209,6 +216,8 @@ 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(((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..0bd0fbbfca
--- /dev/null
+++ b/testsuites/sptests/spmisc01/spmisc01.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup %
+ *
+ * @brief %
+ */
+
+/*
+ * 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);
+
+#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..4a2d3b6f11
--- /dev/null
+++ b/testsuites/sptests/spmisc01/strong.c
@@ -0,0 +1,42 @@
+/* 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 */
+}
-- 
2.16.4



More information about the devel mailing list