This adds a test to verify the incremental linking in RTL. Update #3740 --- spec/build/bsps/tstnolibdl.yml | 1 + spec/build/testsuites/libtests/dl12.yml | 46 ++++++++ spec/build/testsuites/libtests/grp.yml | 2 + testsuites/libtests/dl12/dl-load.c | 138 ++++++++++++++++++++++++ testsuites/libtests/dl12/dl-load.h | 33 ++++++ testsuites/libtests/dl12/dl12-o1.c | 42 ++++++++ testsuites/libtests/dl12/dl12-o2.c | 42 ++++++++ testsuites/libtests/dl12/dl12.doc | 47 ++++++++ testsuites/libtests/dl12/dl12.scn | 15 +++ testsuites/libtests/dl12/init.c | 103 ++++++++++++++++++ 10 files changed, 469 insertions(+) create mode 100644 spec/build/testsuites/libtests/dl12.yml create mode 100644 testsuites/libtests/dl12/dl-load.c create mode 100644 testsuites/libtests/dl12/dl-load.h create mode 100644 testsuites/libtests/dl12/dl12-o1.c create mode 100644 testsuites/libtests/dl12/dl12-o2.c create mode 100644 testsuites/libtests/dl12/dl12.doc create mode 100644 testsuites/libtests/dl12/dl12.scn create mode 100644 testsuites/libtests/dl12/init.c
diff --git a/spec/build/bsps/tstnolibdl.yml b/spec/build/bsps/tstnolibdl.yml index 3e09033f37..7f45f55520 100644 --- a/spec/build/bsps/tstnolibdl.yml +++ b/spec/build/bsps/tstnolibdl.yml @@ -15,6 +15,7 @@ actions: - dl09 - dl10 - dl11 + - dl12 build-type: option copyrights: - Copyright (C) 2020 embedded brains GmbH & Co. KG diff --git a/spec/build/testsuites/libtests/dl12.yml b/spec/build/testsuites/libtests/dl12.yml new file mode 100644 index 0000000000..fbd8098358 --- /dev/null +++ b/spec/build/testsuites/libtests/dl12.yml @@ -0,0 +1,46 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: script +cflags: [] +copyrights: +- Copyright (C) 2020 embedded brains GmbH & Co. KG +cppflags: [] +do-build: | + path = "testsuites/libtests/dl12/" + objs = [] + objs.append(self.cc(bld, bic, path + "dl12-o1.c")) + objs.append(self.cc(bld, bic, path + "dl12-o2.c")) + def ld(self, bld, bic, flags, source, target): + bld(rule="${LD} " + flags + " ${SRC} -o ${TGT}", + source=source, + target=target) + return target + objs = [ld(self, bld, bic, '-r', objs, "testsuites/libtests/dl12/dl12-inc.o")] + tar = path + "dl12.tar" + self.tar(bld, objs, [path], tar) + tar_c, tar_h = self.bin2c(bld, tar) + objs = [] + objs.append(self.cc(bld, bic, tar_c)) + objs.append(self.cc(bld, bic, path + "init.c", deps=[tar_h], cppflags=bld.env.TEST_DL12_CPPFLAGS)) + objs.append(self.cc(bld, bic, path + "dl-load.c")) + dl12_pre = path + "dl12.pre" + self.link_cc(bld, bic, objs, dl12_pre) + dl12_sym_o = path + "dl12-sym.o" + objs.append(dl12_sym_o) + self.rtems_syms(bld, dl12_pre, dl12_sym_o) + self.link_cc(bld, bic, objs, "testsuites/libtests/dl12.exe") +do-configure: null +enabled-by: +- and: + - not: TEST_DL12_EXCLUDE + - BUILD_LIBDL +includes: +- testsuites/libtests/dl12 +ldflags: [] +links: [] +prepare-build: null +prepare-configure: null +stlib: [] +target: testsuites/libtests/dl12.exe +type: build +use-after: [] +use-before: [] diff --git a/spec/build/testsuites/libtests/grp.yml b/spec/build/testsuites/libtests/grp.yml index fae2396a2f..c63d845983 100644 --- a/spec/build/testsuites/libtests/grp.yml +++ b/spec/build/testsuites/libtests/grp.yml @@ -110,6 +110,8 @@ links: uid: dl10 - role: build-dependency uid: dl11 +- role: build-dependency + uid: dl12 - role: build-dependency uid: dumpbuf01 - role: build-dependency diff --git a/testsuites/libtests/dl12/dl-load.c b/testsuites/libtests/dl12/dl-load.c new file mode 100644 index 0000000000..e928d0c27d --- /dev/null +++ b/testsuites/libtests/dl12/dl-load.c @@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (c) 2014 Chris Johns <chr...@rtems.org>. All rights reserved. + * Copyright (c) 2019 On-Line Applications Research + * + * 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. + */ + +#include <stdio.h> + +#include <dlfcn.h> + +#include "dl-load.h" + +#include <rtems/rtl/rtl-shell.h> +#include <rtems/rtl/rtl-trace.h> + +#define TEST_TRACE 0 +#if TEST_TRACE + #define DL_DEBUG_TRACE (RTEMS_RTL_TRACE_ALL & ~RTEMS_RTL_TRACE_ALLOCATOR) + #define DL_RTL_CMDS 1 +#else + #define DL_DEBUG_TRACE 0 + #define DL_RTL_CMDS 0 +#endif + +typedef const void *(*call_t)(void); + +static void* dl_load_obj(const char* name) +{ + void* handle; + int unresolved; + char* message = "loaded"; + + printf("load: %s\n", name); + + handle = dlopen (name, RTLD_NOW | RTLD_GLOBAL); + if (!handle) + { + printf("dlopen failed: %s\n", dlerror()); + return NULL; + } + + if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0) + message = "dlinfo error checking unresolved status"; + else if (unresolved) + message = "has unresolved externals"; + + printf ("handle: %p %s\n", handle, message); + + return handle; +} + +int dl_load_test(void) +{ + void* handle; + call_t call; + const void* dl_o1_str_addr; + const void* dl_o2_str_addr; + +#if DL_DEBUG_TRACE + rtems_rtl_trace_set_mask (DL_DEBUG_TRACE); +#endif + + handle = dl_load_obj("/dl12-inc.o"); + if (!handle) + return 1; + +#if DL_RTL_CMDS + { + char* list[] = { "rtl", "list", NULL }; + rtems_rtl_shell_command (2, list); + char* sym[] = { "rtl", "sym", NULL }; + rtems_rtl_shell_command (2, sym); + } +#endif + + call = dlsym (handle, "dl_o1_func"); + if (call == NULL) + { + printf("dlsym failed: symbol not found\n"); + return 1; + } + + printf("\nAbout to call dl_o1_func at address %p\n", call); + + dl_o1_str_addr = call (); + + printf("\ndl_o1_func string literal address: %p\n", dl_o1_str_addr); + + call = dlsym (handle, "dl_o2_func"); + if (call == NULL) + { + printf("dlsym failed: symbol not found\n"); + return 1; + } + + printf("\nAbout to call dl_o2_func at address %p\n", call); + + dl_o2_str_addr = call (); + + printf("\ndl_o2_func string literal address: %p\n", dl_o2_str_addr); + + if (dl_o1_str_addr == dl_o2_str_addr) { + printf("\nTwo symbols from different object files have the same address!\n"); + return 1; + } + + if (dlclose (handle) < 0) + { + printf("dlclose obj failed: %s\n", dlerror()); + return 1; + } + + printf ("\nhandle: %p closed\n", handle); + + return 0; +} diff --git a/testsuites/libtests/dl12/dl-load.h b/testsuites/libtests/dl12/dl-load.h new file mode 100644 index 0000000000..142b195626 --- /dev/null +++ b/testsuites/libtests/dl12/dl-load.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (c) 2014 Chris Johns <chr...@rtems.org>. 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 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. + */ + +#if !defined(_DL_LOAD_H_) +#define _DL_LOAD_H_ + +int dl_load_test(void); + +#endif diff --git a/testsuites/libtests/dl12/dl12-o1.c b/testsuites/libtests/dl12/dl12-o1.c new file mode 100644 index 0000000000..fe7b5d3185 --- /dev/null +++ b/testsuites/libtests/dl12/dl12-o1.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (c) 2014 Chris Johns <chr...@rtems.org>. All rights reserved. + * Copyright (c) 2019 On-Line Applications Research + * + * 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. + */ + +#include <rtems/test-printer.h> + +#define printf(...) rtems_printf(&rtems_test_printer, __VA_ARGS__); + +const void *dl_o1_func (void); + +const void *dl_o1_func (void) +{ + const char *str = "string_from_dl_o1_func"; + + printf(str); + + return str; +} diff --git a/testsuites/libtests/dl12/dl12-o2.c b/testsuites/libtests/dl12/dl12-o2.c new file mode 100644 index 0000000000..9c975ba47e --- /dev/null +++ b/testsuites/libtests/dl12/dl12-o2.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (c) 2014 Chris Johns <chr...@rtems.org>. All rights reserved. + * Copyright (c) 2019 On-Line Applications Research + * + * 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. + */ + +#include <rtems/test-printer.h> + +#define printf(...) rtems_printf(&rtems_test_printer, __VA_ARGS__); + +const void *dl_o2_func (void); + +const void *dl_o2_func (void) +{ + const char *str = "string_from_dl_o2_func"; + + printf(str); + + return str; +} diff --git a/testsuites/libtests/dl12/dl12.doc b/testsuites/libtests/dl12/dl12.doc new file mode 100644 index 0000000000..70544877b2 --- /dev/null +++ b/testsuites/libtests/dl12/dl12.doc @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: BSD-2-Clause + +# Copyright (c) 2014 Chris Johns <chr...@rtems.org> +# +# 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. +# + +This file describes the directives and concepts tested by this test set. + +test set name: dl12 + +directives: + + dlopen + dlinfo + dlsym + dlclose + +concepts: + ++ Load an incrementally linked object. ++ Check there are no unresolved externals. ++ Locate the dl_o1_func symbol. + Call the dl_o1_func sym and store the returned address. + Locate the dl_o2_func symbol. + Call the dl_o2_func sym and store the returned address. + Compare the returned values. The addresses must not be the same. ++ Unload the object. diff --git a/testsuites/libtests/dl12/dl12.scn b/testsuites/libtests/dl12/dl12.scn new file mode 100644 index 0000000000..b01489cee1 --- /dev/null +++ b/testsuites/libtests/dl12/dl12.scn @@ -0,0 +1,15 @@ +*** BEGIN OF TEST libdl (RTL) 12 *** +load: /dl12-inc.o +handle: 0x4003d8d0 loaded + +About to call dl_o1_func at address 0x4003df80 +string_from_dl_o1_func +dl_o1_func string literal address: 0x4003df40 + +About to call dl_o2_func at address 0x4003dfa4 +string_from_dl_o2_func +dl_o2_func string literal address: 0x4003df58 + +handle: 0x4003d8d0 closed + +*** END OF TEST libdl (RTL) 12 *** diff --git a/testsuites/libtests/dl12/init.c b/testsuites/libtests/dl12/init.c new file mode 100644 index 0000000000..b2d6001a23 --- /dev/null +++ b/testsuites/libtests/dl12/init.c @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (c) 2014 Chris Johns <chr...@rtems.org>. 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 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 "tmacros.h" + +#include <errno.h> +#include <string.h> +#include <stdint.h> +#include <unistd.h> + +#include <rtems/rtl/rtl.h> +#include <rtems/imfs.h> + +#include "dl-load.h" + +const char rtems_test_name[] = "libdl (RTL) 12"; + +/* forward declarations to avoid warnings */ +static rtems_task Init(rtems_task_argument argument); + +#include "dl12-tar.h" + +#define TARFILE_START dl12_tar +#define TARFILE_SIZE dl12_tar_size + +static int test(void) +{ + int ret; + ret = dl_load_test(); + if (ret) + rtems_test_exit(ret); + return 0; +} + +static void Init(rtems_task_argument arg) +{ + int te; + + TEST_BEGIN(); + + te = rtems_tarfs_load("/", (void *)TARFILE_START, (size_t)TARFILE_SIZE); + if (te != 0) + { + printf("untar failed: %d\n", te); + rtems_test_exit(1); + exit (1); + } + + test(); + + TEST_END(); + + rtems_test_exit(0); +} + +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER + +#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4 + +#define CONFIGURE_MAXIMUM_TASKS 1 + +#define CONFIGURE_MAXIMUM_SEMAPHORES 1 + +#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT_TASK_STACK_SIZE (CONFIGURE_MINIMUM_TASK_STACK_SIZE + (4U * 1024U)) + +#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT) + +#define CONFIGURE_INIT + +#include <rtems/confdefs.h> -- 2.44.0 _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel