Skip to content

Commit a47f3b6

Browse files
libsel4test: retain _test_type and _test_case sections
unused attribute does not prevent the sections from being garbage-collected during link-time optimisation. This may trigger undefined references errors to [__start|__stop]_test_case symbols that are expected to be emitted by the linker anyway. Adding "retain" attribute makes sure that the section and its associated symbols are kept regardless of linker's garbage collection. Another fix could be adding "nostart-stop-gc" to the linker flags, but since it is only one section (_test_case) where its __start/__stop symbols are references, adding retain to it makes more sense. This additional functionality requires binutils version 2.36 or later. Sponsored by: DARPA. Signed-off-by: Hesham Almatary <hesham.almatary@cl.cam.ac.uk>
1 parent bb87a71 commit a47f3b6

File tree

1 file changed

+2
-2
lines changed
  • libsel4test/include/sel4test

1 file changed

+2
-2
lines changed

libsel4test/include/sel4test/test.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ typedef struct test_type {
9696
/* Declare a test type.
9797
* For now, we put the test types in a separate elf section. */
9898
#define DEFINE_TEST_TYPE(_name, _id, _set_up_test_type, _tear_down_test_type, _set_up, _tear_down, _run_test) \
99-
__attribute__((used)) __attribute__((section("_test_type"))) struct test_type TEST_TYPE_ ##_name = { \
99+
__attribute__((used,retain)) __attribute__((section("_test_type"))) struct test_type TEST_TYPE_ ##_name = { \
100100
.name = #_name, \
101101
.id = _id, \
102102
.set_up_test_type = _set_up_test_type, \
@@ -131,7 +131,7 @@ typedef struct testcase ALIGN(sizeof(struct testcase)) testcase_t;
131131
* that it is accepted by C++ compilers.
132132
*/
133133
#define DEFINE_TEST_WITH_TYPE(_name, _description, _function, _test_type, _enabled) \
134-
__attribute__((used)) __attribute__((section("_test_case"))) struct testcase TEST_ ## _name = { \
134+
__attribute__((used,retain)) __attribute__((section("_test_case"))) struct testcase TEST_ ## _name = { \
135135
#_name, \
136136
_description, \
137137
(test_fn)_function, \

0 commit comments

Comments
 (0)