diff options
Diffstat (limited to 'cpukit/libdl')
53 files changed, 2840 insertions, 498 deletions
diff --git a/cpukit/libdl/dlfcn-shell.c b/cpukit/libdl/dlfcn-shell.c index 67a6e6b8b7..6ea2501347 100644 --- a/cpukit/libdl/dlfcn-shell.c +++ b/cpukit/libdl/dlfcn-shell.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * Shell command wrappers for the Dynamic Loading API. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/dlfcn.c b/cpukit/libdl/dlfcn.c index e90ed43668..bc485f5b98 100644 --- a/cpukit/libdl/dlfcn.c +++ b/cpukit/libdl/dlfcn.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * This is the POSIX interface to run-time loading of code into RTEMS. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #include <stdint.h> #include <dlfcn.h> #include <rtems/rtl/rtl.h> diff --git a/cpukit/libdl/rap-shell.c b/cpukit/libdl/rap-shell.c index 78a3b539b9..48b9a246e7 100644 --- a/cpukit/libdl/rap-shell.c +++ b/cpukit/libdl/rap-shell.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2013 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * Shell command wrappers for the RTEMS Application loader. */ +/* + * COPYRIGHT (c) 2013 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rap.c b/cpukit/libdl/rap.c index e6585c706b..1a93721aec 100644 --- a/cpukit/libdl/rap.c +++ b/cpukit/libdl/rap.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * This is the RAP implementation. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rtl-alloc-check.py b/cpukit/libdl/rtl-alloc-check.py index c2145a768e..dc59c43c6d 100644 --- a/cpukit/libdl/rtl-alloc-check.py +++ b/cpukit/libdl/rtl-alloc-check.py @@ -1,10 +1,5 @@ -# -# Copyright (c) 2019 Chris Johns <chrisj@rtems.org>. -# All rights reserved. -# -# The license and distribution terms for this file may be -# found in the file LICENSE in this distribution or at -# http://www.rtems.org/license/LICENSE. +# SPDX-License-Identifier: BSD-2-Clause + # # Check the allocations for libdl: # @@ -13,7 +8,30 @@ # 2. Load and unload object files. # # 3. Capture the trace output and feed to this tool + +# Copyright (c) 2019 Chris Johns <chrisj@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. from __future__ import print_function diff --git a/cpukit/libdl/rtl-alloc-heap.c b/cpukit/libdl/rtl-alloc-heap.c index f1bdcca507..f90233874e 100644 --- a/cpukit/libdl/rtl-alloc-heap.c +++ b/cpukit/libdl/rtl-alloc-heap.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Allocator for the standard heap. */ +/* + * COPYRIGHT (c) 2012,2023 Chris Johns <chrisj@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. + */ + #include <stdlib.h> #include "rtl-alloc-heap.h" @@ -34,6 +54,9 @@ rtems_rtl_alloc_heap (rtems_rtl_alloc_cmd cmd, free (*address); *address = NULL; break; + case RTEMS_RTL_ALLOC_RESIZE: + *address = realloc (*address, size); + break; case RTEMS_RTL_ALLOC_LOCK: _RTEMS_Lock_allocator(); break; diff --git a/cpukit/libdl/rtl-alloc-heap.h b/cpukit/libdl/rtl-alloc-heap.h index 6b7018b400..e3990b9f70 100644 --- a/cpukit/libdl/rtl-alloc-heap.h +++ b/cpukit/libdl/rtl-alloc-heap.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Allocator for the standard heap. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_ALLOC_HEAP_H_) #define _RTEMS_RTL_ALLOC_HEAP_H_ diff --git a/cpukit/libdl/rtl-allocator.c b/cpukit/libdl/rtl-allocator.c index 647c0c89a4..7503183367 100644 --- a/cpukit/libdl/rtl-allocator.c +++ b/cpukit/libdl/rtl-allocator.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Allocator */ +/* + * COPYRIGHT (c) 2012, 2018, 2023 Chris Johns <chrisj@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. + */ + #include <stdio.h> #include <string.h> @@ -90,6 +110,39 @@ rtems_rtl_alloc_del (rtems_rtl_alloc_tag tag, void* address) rtems_rtl_unlock (); } +void* rtems_rtl_alloc_resize (rtems_rtl_alloc_tag tag, + void* address, + size_t size, + bool zero) +{ + rtems_rtl_data* rtl = rtems_rtl_lock (); + const void* prev_address = address; + + /* + * Resize memory of an existing allocation. The address field is set + * by the allocator and may change. + */ + if (rtl != NULL) + rtl->allocator.allocator (RTEMS_RTL_ALLOC_RESIZE, tag, &address, size); + + rtems_rtl_unlock (); + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) + printf ("rtl: alloc: resize: %s%s prev-addr=%p addr=%p size=%zu\n", + rtems_rtl_trace_tag_label (tag), prev_address == address ? "" : " MOVED", + prev_address, address, size); + + /* + * Only zero the memory if asked to and the resize was successful. We + * cannot clear the resized area if bigger than the previouis allocation + * because we do not have the original size. + */ + if (address != NULL && zero) + memset (address, 0, size); + + return address; +} + void rtems_rtl_alloc_wr_enable (rtems_rtl_alloc_tag tag, void* address) { @@ -257,21 +310,23 @@ rtems_rtl_alloc_module_new (void** text_base, size_t text_size, { *text_base = *const_base = *data_base = *bss_base = NULL; - if (text_size) + if (data_size != 0) { - *text_base = rtems_rtl_alloc_new (rtems_rtl_alloc_text_tag (), - text_size, false); - if (!*text_base) + *data_base = rtems_rtl_alloc_new (rtems_rtl_alloc_data_tag (), + data_size, false); + if (*data_base == NULL) { + rtems_rtl_alloc_module_del (text_base, const_base, eh_base, + data_base, bss_base); return false; } } - if (const_size) + if (bss_size != 0) { - *const_base = rtems_rtl_alloc_new (rtems_rtl_alloc_const_tag (), - const_size, false); - if (!*const_base) + *bss_base = rtems_rtl_alloc_new (rtems_rtl_alloc_bss_tag (), + bss_size, false); + if (*bss_base == NULL) { rtems_rtl_alloc_module_del (text_base, const_base, eh_base, data_base, bss_base); @@ -279,11 +334,11 @@ rtems_rtl_alloc_module_new (void** text_base, size_t text_size, } } - if (eh_size) + if (eh_size != 0) { *eh_base = rtems_rtl_alloc_new (rtems_rtl_alloc_eh_tag (), eh_size, false); - if (!*eh_base) + if (*eh_base == NULL) { rtems_rtl_alloc_module_del (text_base, const_base, eh_base, data_base, bss_base); @@ -291,11 +346,11 @@ rtems_rtl_alloc_module_new (void** text_base, size_t text_size, } } - if (data_size) + if (const_size != 0) { - *data_base = rtems_rtl_alloc_new (rtems_rtl_alloc_data_tag (), - data_size, false); - if (!*data_base) + *const_base = rtems_rtl_alloc_new (rtems_rtl_alloc_const_tag (), + const_size, false); + if (*const_base == NULL) { rtems_rtl_alloc_module_del (text_base, const_base, eh_base, data_base, bss_base); @@ -303,14 +358,72 @@ rtems_rtl_alloc_module_new (void** text_base, size_t text_size, } } - if (bss_size) + if (text_size != 0) { - *bss_base = rtems_rtl_alloc_new (rtems_rtl_alloc_bss_tag (), - bss_size, false); - if (!*bss_base) + *text_base = rtems_rtl_alloc_new (rtems_rtl_alloc_text_tag (), + text_size, false); + if (*text_base == NULL) + { + return false; + } + } + + return true; +} + +bool +rtems_rtl_alloc_module_resize (void** text_base, size_t text_size, + void** const_base, size_t const_size, + void** eh_base, size_t eh_size, + void** data_base, size_t data_size, + void** bss_base, size_t bss_size) +{ + if (data_size != 0) + { + *data_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_data_tag (), + *data_base, data_size, false); + if (*data_base == NULL) + { + return false; + } + } + + if (bss_size != 0) + { + *bss_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_bss_tag (), + *bss_base, bss_size, false); + if (*bss_base == NULL) + { + return false; + } + } + + if (eh_size != 0) + { + *eh_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_eh_tag (), + *eh_base, eh_size, false); + if (*eh_base == NULL) + { + return false; + } + } + + if (const_size != 0) + { + *const_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_const_tag (), + *const_base, const_size, false); + if (*const_base == NULL) + { + return false; + } + } + + if (text_size != 0) + { + *text_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_text_tag (), + *text_base, text_size, false); + if (*text_base == NULL) { - rtems_rtl_alloc_module_del (text_base, const_base, eh_base, - data_base, bss_base); return false; } } diff --git a/cpukit/libdl/rtl-archive.c b/cpukit/libdl/rtl-archive.c index 6eba1585b6..4a6d2cbf0b 100644 --- a/cpukit/libdl/rtl-archive.c +++ b/cpukit/libdl/rtl-archive.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Archive */ +/* + * COPYRIGHT (c) 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -1154,6 +1174,7 @@ rtems_rtl_obj_archive_find_obj (int fd, */ if (header[0] == '/') { + const char* name_ = *name; off_t extended_off; switch (header[1]) @@ -1170,7 +1191,7 @@ rtems_rtl_obj_archive_find_obj (int fd, * return the result. */ *extended_file_names = *ooffset + RTEMS_RTL_AR_FHDR_SIZE; - if (*name[0] == '/' && *name[1] == '/') + if (name_[0] == '/' && name_[1] == '/') { *ooffset = *ooffset + RTEMS_RTL_AR_FHDR_SIZE; return true; diff --git a/cpukit/libdl/rtl-bit-alloc.c b/cpukit/libdl/rtl-bit-alloc.c index b494797e7d..7014dc8b62 100644 --- a/cpukit/libdl/rtl-bit-alloc.c +++ b/cpukit/libdl/rtl-bit-alloc.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2019 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -17,6 +12,31 @@ * should be small and the minimum allocator a 32bit work or higher. */ +/* + * COPYRIGHT (c) 2019 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rtl-bit-alloc.h b/cpukit/libdl/rtl-bit-alloc.h index d977473a96..9b4e6c31fb 100644 --- a/cpukit/libdl/rtl-bit-alloc.h +++ b/cpukit/libdl/rtl-bit-alloc.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2019 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Bit Allocator Header */ +/* + * COPYRIGHT (c) 2019 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_BIT_ALLOC_H_) #define _RTEMS_RTL_BIT_ALLOC_H_ diff --git a/cpukit/libdl/rtl-chain-iterator.c b/cpukit/libdl/rtl-chain-iterator.c index 4e98c203d1..edc8f9ad5b 100644 --- a/cpukit/libdl/rtl-chain-iterator.c +++ b/cpukit/libdl/rtl-chain-iterator.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * A means of executing an iterator on a chain. */ +/* + * COPYRIGHT (c) 2012 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rtl-chain-iterator.h b/cpukit/libdl/rtl-chain-iterator.h index 5811715da0..8304fe1a24 100644 --- a/cpukit/libdl/rtl-chain-iterator.h +++ b/cpukit/libdl/rtl-chain-iterator.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Chain Iterator. */ +/* + * COPYRIGHT (c) 2012 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_CHAIN_ITERATOR_H_) #define _RTEMS_RTL_CHAIN_ITERATOR_H_ diff --git a/cpukit/libdl/rtl-debugger.c b/cpukit/libdl/rtl-debugger.c index 1ab619d194..3c25605f5e 100644 --- a/cpukit/libdl/rtl-debugger.c +++ b/cpukit/libdl/rtl-debugger.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -22,6 +17,31 @@ * operation based on the r_state field. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rtl-elf.c b/cpukit/libdl/rtl-elf.c index 75b3d9c953..dd6d8617bb 100644 --- a/cpukit/libdl/rtl-elf.c +++ b/cpukit/libdl/rtl-elf.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012-2019 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * This is the RTL implementation. */ +/* + * COPYRIGHT (c) 2012-2019 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -158,12 +178,19 @@ rtems_rtl_elf_find_symbol (rtems_rtl_obj* obj, /* * If the symbol type is STT_NOTYPE the symbol references a global - * symbol. The gobal symbol table is searched to find it and that value + * symbol. The global symbol table is searched to find it and that value * returned. If the symbol is local to the object module the section for the * symbol is located and it's base added to the symbol's value giving an * absolute location. + * + * If the symbols type of TLS return the symbols value. It is the + * offset from the thread's TLS area base. The offset is set by the + * linker for the base image and by the TLS allocator for loaded + * modules. There is no section and no absolute base. */ - if (ELF_ST_TYPE(sym->st_info) == STT_NOTYPE || sym->st_shndx == SHN_COMMON) + if (ELF_ST_TYPE (sym->st_info) == STT_NOTYPE || + sym->st_shndx == SHN_COMMON || + ELF_ST_TYPE (sym->st_info) == STT_TLS) { /* * Search the object file then the global table for the symbol. @@ -172,7 +199,7 @@ rtems_rtl_elf_find_symbol (rtems_rtl_obj* obj, if (!*symbol) return false; - *value = (Elf_Addr) (*symbol)->value; + *value = (Elf_Addr)(uintptr_t) (*symbol)->value; return true; } @@ -182,7 +209,7 @@ rtems_rtl_elf_find_symbol (rtems_rtl_obj* obj, if (!sect) return false; - *value = sym->st_value + (Elf_Addr) sect->base; + *value = sym->st_value + (Elf_Addr)(uintptr_t) sect->base; return true; } @@ -227,6 +254,13 @@ rtems_rtl_elf_reloc_parser (rtems_rtl_obj* obj, rtems_rtl_elf_rel_status rs; /* + * TLS are not parsed. + */ + if (ELF_ST_TYPE (sym->st_info) == STT_TLS) { + return true; + } + + /* * Check the reloc record to see if a trampoline is needed. */ if (is_rela) @@ -282,7 +316,7 @@ rtems_rtl_elf_reloc_parser (rtems_rtl_obj* obj, * Find the symbol's object file. It cannot be NULL so ignore that result * if returned, it means something is corrupted. We are in an iterator. */ - rtems_rtl_obj* sobj = rtems_rtl_find_obj_with_symbol (symbol); + rtems_rtl_obj* sobj = rtems_rtl_find_obj_with_symbol (symbol); if (sobj != NULL) { /* @@ -771,7 +805,7 @@ rtems_rtl_elf_tramp_resolve_reloc (rtems_rtl_unresolv_rec* rec, } if (unresolved || rs == rtems_rtl_elf_rel_tramp_add) - tramp->obj->tramps_size += tramp->obj->tramp_size; + ++tramp->obj->tramp_slots; if (rs == rtems_rtl_elf_rel_failure) { *failure = true; @@ -784,7 +818,7 @@ rtems_rtl_elf_tramp_resolve_reloc (rtems_rtl_unresolv_rec* rec, } static bool -rtems_rtl_elf_alloc_trampoline (rtems_rtl_obj* obj, size_t unresolved) +rtems_rtl_elf_find_trampolines (rtems_rtl_obj* obj, size_t unresolved) { rtems_rtl_tramp_data td = { 0 }; td.obj = obj; @@ -795,21 +829,20 @@ rtems_rtl_elf_alloc_trampoline (rtems_rtl_obj* obj, size_t unresolved) if (td.failure) return false; rtems_rtl_trampoline_remove (obj); - obj->tramp_relocs = obj->tramp_size == 0 ? 0 : obj->tramps_size / obj->tramp_size; + obj->tramp_relocs = obj->tramp_slots; if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: tramp:elf: tramps: %zu count:%zu total:%zu\n", + printf ("rtl: tramp:elf: tramps: slots:%zu count:%zu total:%zu\n", obj->tramp_relocs, td.count, td.total); /* * Add on enough space to handle the unresolved externals that need to be * resolved at some point in time. They could all require fixups and * trampolines. */ - obj->tramps_size += obj->tramp_size * unresolved; + obj->tramp_slots += unresolved; if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: tramp:elf: slots: %zu (%zu)\n", - obj->tramp_size == 0 ? 0 : obj->tramps_size / obj->tramp_size, - obj->tramps_size); - return rtems_rtl_obj_alloc_trampoline (obj); + printf ("rtl: tramp:elf: slots:%zu (%zu)\n", + obj->tramp_slots, obj->tramp_slots * obj->tramp_slot_size); + return true; } static bool @@ -1151,7 +1184,7 @@ rtems_rtl_elf_symbols_load (rtems_rtl_obj* obj, rtems_chain_set_off_chain (&osym->node); memcpy (string, name, strlen (name) + 1); osym->name = string; - osym->value = (uint8_t*) value; + osym->value = (void*) (intptr_t) value; osym->data = symbol.st_shndx; if (rtems_rtl_trace (RTEMS_RTL_TRACE_SYMBOL)) @@ -1696,7 +1729,7 @@ rtems_rtl_elf_file_load (rtems_rtl_obj* obj, int fd) /* * Set the format's architecture's maximum tramp size. */ - obj->tramp_size = rtems_rtl_elf_relocate_tramp_max_size (); + obj->tramp_slot_size = rtems_rtl_elf_relocate_tramp_max_size (); /* * Parse the section information first so we have the memory map of the object @@ -1745,13 +1778,23 @@ rtems_rtl_elf_file_load (rtems_rtl_obj* obj, int fd) if (!rtems_rtl_obj_alloc_sections (obj, fd, rtems_rtl_elf_arch_alloc, &ehdr)) return false; - if (!rtems_rtl_obj_load_symbols (obj, fd, rtems_rtl_elf_symbols_locate, &ehdr)) + if (!rtems_rtl_elf_dependents (obj, &relocs)) return false; - if (!rtems_rtl_elf_dependents (obj, &relocs)) + if (!rtems_rtl_elf_find_trampolines (obj, relocs.unresolved)) return false; - if (!rtems_rtl_elf_alloc_trampoline (obj, relocs.unresolved)) + /* + * Resize the sections to allocate the trampoline memory as part of + * the text section. + */ + if (rtems_rtl_obj_has_trampolines (obj)) + { + if (!rtems_rtl_obj_resize_sections (obj)) + return false; + } + + if (!rtems_rtl_obj_load_symbols (obj, fd, rtems_rtl_elf_symbols_locate, &ehdr)) return false; /* diff --git a/cpukit/libdl/rtl-elf.h b/cpukit/libdl/rtl-elf.h index 3bbc0bd9ee..0476c1ecd7 100644 --- a/cpukit/libdl/rtl-elf.h +++ b/cpukit/libdl/rtl-elf.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012-2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker ELF Headers */ +/* + * COPYRIGHT (c) 2012-2018 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_ELF_H_) #define _RTEMS_RTL_ELF_H_ @@ -31,7 +51,7 @@ extern "C" { /* * Do not add '()'. Leave plain. */ -#if defined(__powerpc64__) || defined(__arch64__) || (__riscv_xlen == 64) +#if defined(__powerpc64__) || defined(__aarch64__) || (__riscv_xlen == 64) #define ELFSIZE 64 #else #define ELFSIZE 32 diff --git a/cpukit/libdl/rtl-error.c b/cpukit/libdl/rtl-error.c index f7c046861c..b3234031d7 100644 --- a/cpukit/libdl/rtl-error.c +++ b/cpukit/libdl/rtl-error.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012-2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Error */ +/* + * COPYRIGHT (c) 2012-2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rtl-error.h b/cpukit/libdl/rtl-error.h index 576384ed5d..38268c3bae 100644 --- a/cpukit/libdl/rtl-error.h +++ b/cpukit/libdl/rtl-error.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Error */ +/* + * COPYRIGHT (c) 2012 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_ERROR_H_) #define _RTEMS_RTL_ERROR_H_ diff --git a/cpukit/libdl/rtl-find-file.c b/cpukit/libdl/rtl-find-file.c index b354a1dce2..7821355fd9 100644 --- a/cpukit/libdl/rtl-find-file.c +++ b/cpukit/libdl/rtl-find-file.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012-2013 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Error */ +/* + * COPYRIGHT (c) 2012-2013 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rtl-find-file.h b/cpukit/libdl/rtl-find-file.h index 86cd8fe313..b4cd9f6c84 100644 --- a/cpukit/libdl/rtl-find-file.h +++ b/cpukit/libdl/rtl-find-file.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012-2013 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Object Support. */ +/* + * COPYRIGHT (c) 2012-2013 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_FIND_FILE_H_) #define _RTEMS_RTL_FIND_FILE_H_ diff --git a/cpukit/libdl/rtl-mdreloc-aarch64.c b/cpukit/libdl/rtl-mdreloc-aarch64.c new file mode 100644 index 0000000000..1eb1d1e87d --- /dev/null +++ b/cpukit/libdl/rtl-mdreloc-aarch64.c @@ -0,0 +1,592 @@ +/* + * Taken from NetBSD and stripped of the relocations not needed on RTEMS. + */ + +/* $NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $ */ + +/*- + * Copyright (c) 2014 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +/*- + * Copyright (c) 2014-2015 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by Andrew Turner + * under sponsorship from the FreeBSD Foundation. + * + * 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. + */ + +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $"); +#endif /* not lint */ + +#include <sys/types.h> +#include <string.h> +#include <errno.h> +#include <inttypes.h> +#include <sys/stat.h> +#include <sys/endian.h> + +#include <rtems/rtl/rtl.h> +#include "rtl-elf.h" +#include "rtl-error.h" +#include <rtems/rtl/rtl-trace.h> +#include <rtems/score/tls.h> + +#include "rtl-unwind.h" +#include "rtl-unwind-dw2.h" + +struct tls_data { + size_t td_tlsindex; + Elf_Addr td_tlsoffs; +}; + +rtems_rtl_elf_rel_status +rtems_rtl_elf_reloc_rela ( + rtems_rtl_obj* obj, + const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue, + const bool parsing +); + +#define __BITS(hi,lo) ((~((~(Elf_Addr)0)<<((hi)+1)))&((~(Elf_Addr)0)<<(lo))) +#define WIDTHMASK(w) (0xffffffffffffffffUL >> (64 - (w))) + +static inline bool +checkoverflow(Elf_Addr addr, int bitwidth, Elf_Addr targetaddr, + const char *bitscale, void *where, Elf64_Addr off) +{ + const Elf_Addr mask = ~__BITS(bitwidth - 1, 0); + + if (((addr & mask) != 0) && ((addr & mask) != mask)) { + printf("kobj_reloc: Relocation 0x%" PRIxPTR " too far from %p" + " (base+0x%jx) for %dbit%s\n", + (uintptr_t)targetaddr, where, off, bitwidth, bitscale); + return true; + } + + return false; +} + +static inline bool +checkalign(Elf_Addr addr, int alignbyte, void *where, Elf64_Addr off) +{ + if ((addr & (alignbyte - 1)) != 0) { + printf("kobj_reloc: Relocation 0x%" PRIxPTR " unaligned at %p" + " (base+0x%jx). must be aligned %d\n", + (uintptr_t)addr, where, off, alignbyte); + return true; + } + return false; +} + +/* + * Set to 1 to allow untested relocations. If you tested one and it + * works or you fixed the relocation please remove the guard. + */ +#define ALLOW_UNTESTED_RELOCS 1 + +static void* +set_veneer(void* tramopline, Elf_Addr target) +{ + /* + * http://shell-storm.org/online/Online-Assembler-and-Disassembler/ + * + * ldr x9, #8 + * br x9 + * + */ + uint64_t* tramp = (uint64_t*) tramopline; +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + *tramp++ = 0xd61f012058000049; +#else + *tramp++ = 0xd61f012058000049; /* not tested */ +#endif + *tramp++ = (uint64_t) target; + return tramp; +} + +static size_t +get_veneer_size(int type) +{ + (void) type; + return 16; +} + +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint64_t); +} + +size_t +rtems_rtl_elf_relocate_tramp_max_size (void) +{ + return 16; +} + +uint32_t +rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj, + const Elf_Shdr* shdr) +{ + return 0; +} + +uint32_t +rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj, + int section, + const char* name, + const Elf_Shdr* shdr, + const uint32_t flags) +{ + (void) obj; + (void) section; + (void) name; + (void) shdr; + return flags; +} + +bool +rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect) +{ + (void) obj; + (void) sect; + return false; +} + +bool +rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect) +{ + (void) obj; + (void) sect; + return false; +} + +bool +rtems_rtl_elf_rel_resolve_sym (Elf_Word type) +{ + return true; +} + +rtems_rtl_elf_rel_status +rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj, + const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue, + const bool parsing) +{ + Elf64_Addr *where; + Elf32_Addr *where32; + Elf_Addr off = rela->r_offset; + Elf_Addr target; + Elf_Addr raddr; + uint32_t *insn, immhi, immlo, shift; + + where = (Elf_Addr *)(sect->base + rela->r_offset); + where32 = (void *)where; + + insn = (uint32_t *)where; + + /* + * S - the address of the symbol + * A - the addend of the reolcation + * P - the address of the place being relocated (derived from r_offset) + * Page(expr) - the page address of the expression expr, defined as (expr & ~0xFFF). + * TPREL(expr) - the thread pointer offset of the expression expr + */ + switch (ELF_R_TYPE(rela->r_info)) { + case R_TYPE(NONE): + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { + printf ("rtl: NONE %p in %s\n", where, rtems_rtl_obj_oname (obj)); + } + break; + + case R_TYPE(ABS64): /* word S + A */ + case R_TYPE(GLOB_DAT): /* word S + A */ + if (!parsing) { + target = (Elf_Addr)symvalue + rela->r_addend; + + if (*where != target) + *where = target; + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf ("rtl: reloc 64/GLOB_DAT in %s --> %p in %s\n", + sect->name, (void *)(uintptr_t)*where, + rtems_rtl_obj_oname (obj)); + } + break; + + /* + * If S is a normal symbol, resolves to the difference between the static + * link address of S and the execution address of S. If S is the null symbol + * (ELF symbol index 0), resolves to the difference between the static link + * address of P and the execution address of P. + */ + case R_TYPE(RELATIVE): /* Delta(S) + A */ + if (!parsing) { + *where = (Elf_Addr)(uintptr_t)(sect->base + rela->r_addend); + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf ("rtl: reloc RELATIVE in %s --> %p in %s\n", + sect->name, (void *)(uintptr_t)*where, + rtems_rtl_obj_oname (obj)); + } + break; + + case R_TYPE(COPY): + /* + * These are deferred until all other relocations have + * been done. All we do here is make sure that the + * COPY relocation is not in a shared library. They + * are allowed only in executable files. + */ + printf("rtl: reloc COPY (please report)\n"); + break; + + case R_AARCH64_ADD_TPREL_HI12: /* TPREL(S + A) */ + case R_AARCH64_ADD_TPREL_LO12: + case R_AARCH64_ADD_TPREL_LO12_NC: + uint32_t of_check = 0; + switch (ELF_R_TYPE(rela->r_info)) { + case R_AARCH64_ADD_TPREL_LO12: + of_check = 212; + /* fallthrough */ + case R_AARCH64_ADD_TPREL_LO12_NC: + shift = 0; + break; + case R_AARCH64_ADD_TPREL_HI12: + of_check = 224; + shift = 12; + break; + default: + printf("illegal rtype: %" PRIu64 "\n", ELF_R_TYPE(rela->r_info)); + break; + } + + if (!parsing) { + target = (Elf_Addr)symvalue; + target >>= shift; + target &= WIDTHMASK(12); + if (of_check && target >= of_check) { + return rtems_rtl_elf_rel_failure; + } + *insn = htole32( + (le32toh(*insn) & ~__BITS(21,10)) | (target << 10)); + } + break; + + case R_AARCH64_ADD_ABS_LO12_NC: /* S + A */ + case R_AARCH64_LDST8_ABS_LO12_NC: + case R_AARCH_LDST16_ABS_LO12_NC: + case R_AARCH_LDST32_ABS_LO12_NC: + case R_AARCH_LDST64_ABS_LO12_NC: + case R_AARCH64_LDST128_ABS_LO12_NC: + switch (ELF_R_TYPE(rela->r_info)) { + case R_AARCH64_ADD_ABS_LO12_NC: + case R_AARCH64_LDST8_ABS_LO12_NC: + shift = 0; + break; + case R_AARCH_LDST16_ABS_LO12_NC: + shift = 1; + break; + case R_AARCH_LDST32_ABS_LO12_NC: + shift = 2; + break; + case R_AARCH_LDST64_ABS_LO12_NC: + shift = 3; + break; + case R_AARCH64_LDST128_ABS_LO12_NC: + shift = 4; + break; + default: + printf("illegal rtype: %" PRIu64 "\n", ELF_R_TYPE(rela->r_info)); + break; + } + + /* + * S + A + * e.g.) add x0,x0,#:lo12:<sym>+<addend> + * ldrb w0,[x0,#:lo12:<sym>+<addend>] + * ldrh w0,[x0,#:lo12:<sym>+<addend>] + * ldr w0,[x0,#:lo12:<sym>+<addend>] + * ldr x0,[x0,#:lo12:<sym>+<addend>] + */ + if (!parsing) { + target = (Elf_Addr)symvalue + rela->r_addend; + if (checkalign(target, 1 << shift, where, off)) { + printf ("rtl: reloc checkalign failed in %s --> %p in %s\n", + sect->name, (void *)(uintptr_t)*where, + rtems_rtl_obj_oname (obj)); + printf("ELF_R_TYPE is : %" PRIu64 "\n", ELF_R_TYPE(rela->r_info)); + break; + } + target &= WIDTHMASK(12); + target >>= shift; + *insn = htole32( + (le32toh(*insn) & ~__BITS(21,10)) | (target << 10)); + } + break; + + case R_AARCH64_ADR_PREL_PG_HI21: + /* + * Page(S + A) - Page(P) + * e.g.) adrp x0,<sym>+<addend> + */ + if (!parsing) { + target = (Elf_Addr)symvalue + rela->r_addend; + target = target >> 12; + raddr = target << 12; + target -= (uintptr_t)where >> 12; + + if (checkoverflow(target, 21, raddr, " x 4k", where, off)) { + printf("]] %d\n", __LINE__); + return rtems_rtl_elf_rel_failure; + } + + immlo = target & WIDTHMASK(2); + immhi = (target >> 2) & WIDTHMASK(19); + *insn = htole32((le32toh(*insn) & + ~(__BITS(30,29) | __BITS(23,5))) | + (immlo << 29) | (immhi << 5)); + } + break; + + case R_AARCH_JUMP26: + case R_AARCH_CALL26: + /* + * S + A - P + * e.g.) b <sym>+<addend> + * bl <sym>+<addend> + */ + if (parsing && sect->base == 0) { + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf ("rtl: JUMP26/PC26/CALL tramp cache\n"); + return rtems_rtl_elf_rel_tramp_cache; + } + + raddr = (Elf_Addr)symvalue + rela->r_addend; + target = raddr - (uintptr_t)where; + if (checkalign(target, 4, where, off)) { + return rtems_rtl_elf_rel_failure; + } + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf ( + "rtl: JUMP26/PC26/CALL: insn=%p where=%p target=%p raddr=%p parsing=%d\n", + insn, (void*) where, (void*)(uintptr_t) target, (void*)(uintptr_t) raddr, + parsing + ); + + target = (intptr_t)target >> 2; + + if (((Elf_Sword)target > 0x1FFFFFF) || ((Elf_Sword)target < -0x2000000)) { + Elf_Word tramp_addr; + size_t tramp_size = get_veneer_size(ELF_R_TYPE(rela->r_info)); + + if (parsing) { + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf ("rtl: JUMP26/PC26/CALL tramp add\n"); + return rtems_rtl_elf_rel_tramp_add; + } + + if (!rtems_rtl_obj_has_tramp_space (obj, tramp_size)) { + rtems_rtl_set_error (EINVAL, + "%s: CALL/JUMP26: overflow: no tramp memory", + sect->name); + return rtems_rtl_elf_rel_failure; + } + + tramp_addr = ((Elf_Addr)(uintptr_t) obj->tramp_brk) | (symvalue & 1); + obj->tramp_brk = set_veneer(obj->tramp_brk, symvalue); + target = tramp_addr + rela->r_addend - (uintptr_t)where; + target = (uintptr_t)target >> 2; + } + + if (checkoverflow(target, 26, raddr, " word", where, off)) { + return rtems_rtl_elf_rel_failure; + } + + if (!parsing) { + target &= WIDTHMASK(26); + *insn = htole32((le32toh(*insn) & ~__BITS(25,0)) | target); + } + + break; + + case R_AARCH64_PREL32: + /* + * S + A - P + * e.g.) 1: .word <sym>+<addend>-1b + */ + if (!parsing) { + raddr = (Elf_Addr)symvalue + rela->r_addend; + target = raddr - (uintptr_t)where; + if (checkoverflow(target, 32, raddr, "", where, off)) { + printf("]] %d\n", __LINE__); + return rtems_rtl_elf_rel_failure; + } + *where32 = target; + } + break; + + case R_TYPE(TLSDESC): + printf ("rtl: reloc TLSDESC in %s --> %p in %s\n", + sect->name, (void *)(uintptr_t)*where, + rtems_rtl_obj_oname (obj)); + break; + + case R_TLS_TYPE(TLS_DTPREL): + printf ("rtl: reloc TLS_DTPREL in %s --> %p in %s\n", + sect->name, (void *)(uintptr_t)*where, + rtems_rtl_obj_oname (obj)); + break; + case R_TLS_TYPE(TLS_DTPMOD): + printf ("rtl: reloc TLS_DTPMOD in %s --> %p in %s\n", + sect->name, (void *)(uintptr_t)*where, + rtems_rtl_obj_oname (obj)); + break; + + case R_TLS_TYPE(TLS_TPREL): + printf ("rtl: reloc TLS_TPREL in %s --> %p in %s\n", + sect->name, (void *)(uintptr_t)*where, + rtems_rtl_obj_oname (obj)); + break; + + default: + printf ("rtl: Unsupported relocation type (%" PRIu64 + ") in %s --> %p in %s\n", + ELF_R_TYPE(rela->r_info), sect->name, (void *)where, + rtems_rtl_obj_oname (obj)); + return rtems_rtl_elf_rel_failure; + } + + return rtems_rtl_elf_rel_no_error; +} + +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj* obj, + const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) +{ + return rtems_rtl_elf_reloc_rela (obj, + rela, + sect, + symname, + syminfo, + symvalue, + true); +} + +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj, + const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) +{ + return rtems_rtl_elf_reloc_rela (obj, + rela, + sect, + symname, + syminfo, + symvalue, + false); +} + +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj* obj, + const Elf_Rel* rel, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) +{ + rtems_rtl_set_error (EINVAL, "rela type record not supported"); + return rtems_rtl_elf_rel_failure; +} + +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rel (rtems_rtl_obj* obj, + const Elf_Rel* rel, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) +{ + rtems_rtl_set_error (EINVAL, "rela type record not supported"); + return rtems_rtl_elf_rel_failure; +} + +bool +rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, + const char* name, + uint32_t flags) { + return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags); +} + +bool +rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj) { + return rtems_rtl_elf_unwind_dw2_register (obj); +} + +bool +rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj) { + return rtems_rtl_elf_unwind_dw2_deregister (obj); +} diff --git a/cpukit/libdl/rtl-mdreloc-arm.c b/cpukit/libdl/rtl-mdreloc-arm.c index 4950dcdab1..16efbe79da 100644 --- a/cpukit/libdl/rtl-mdreloc-arm.c +++ b/cpukit/libdl/rtl-mdreloc-arm.c @@ -12,14 +12,12 @@ #include <string.h> #include <sys/types.h> #include <sys/stat.h> -#include <unwind.h> -#include <unwind-arm-common.h> #include <rtems/rtl/rtl.h> #include "rtl-elf.h" #include "rtl-error.h" #include <rtems/rtl/rtl-trace.h> -#include "rtl-unwind.h" +#include "rtl-unwind-arm.h" /* * Set to 1 to allow untested relocations. If you tested one and it @@ -110,6 +108,12 @@ get_veneer_size(int type) return 8; } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { @@ -528,7 +532,6 @@ rtems_rtl_elf_reloc_rel (rtems_rtl_obj* obj, break; case R_TYPE(TLS_LE32): -#if ALLOW_UNTESTED_RELOCS if (!parsing) { addend = *where; *where = symvalue + addend; @@ -537,7 +540,7 @@ rtems_rtl_elf_reloc_rel (rtems_rtl_obj* obj, (void *)*where, where, rtems_rtl_obj_oname (obj)); } break; -#endif + case R_TYPE(TLS_GD32): case R_TYPE(TLS_LDM32): case R_TYPE(TLS_LDO32): @@ -597,78 +600,3 @@ rtems_rtl_elf_relocate_rel (rtems_rtl_obj* obj, symvalue, false); } - -bool -rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, - const char* name, - uint32_t flags) -{ - /* - * We location the EH sections in section flags. - */ - return false; -} - -bool -rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj) -{ - return true; -} - -bool -rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj) -{ - obj->loader = NULL; - return true; -} - -/* An exception index table entry. */ -typedef struct __EIT_entry -{ - _uw fnoffset; - _uw content; -} __EIT_entry; - -/* The exception index table location in the base module */ -extern __EIT_entry __exidx_start; -extern __EIT_entry __exidx_end; - -/* - * A weak reference is in libgcc, provide a real version and provide a way to - * manage loaded modules. - * - * Passed in the return address and a reference to the number of records - * found. We set the start of the exidx data and the number of records. - */ -_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, - int* nrec) __attribute__ ((__noinline__, - __used__, - __noclone__)); - -_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, - int* nrec) -{ - rtems_rtl_data* rtl; - rtems_chain_node* node; - __EIT_entry* exidx_start = &__exidx_start; - __EIT_entry* exidx_end = &__exidx_end; - - rtl = rtems_rtl_lock (); - - node = rtems_chain_first (&rtl->objects); - while (!rtems_chain_is_tail (&rtl->objects, node)) { - rtems_rtl_obj* obj = (rtems_rtl_obj*) node; - if (rtems_rtl_obj_text_inside (obj, (void*) return_address)) { - exidx_start = (__EIT_entry*) obj->eh_base; - exidx_end = (__EIT_entry*) (obj->eh_base + obj->eh_size); - break; - } - node = rtems_chain_next (node); - } - - rtems_rtl_unlock (); - - *nrec = exidx_end - exidx_start; - - return (_Unwind_Ptr) exidx_start; -} diff --git a/cpukit/libdl/rtl-mdreloc-bfin.c b/cpukit/libdl/rtl-mdreloc-bfin.c index 27f865e5a5..cf3f3f88c0 100644 --- a/cpukit/libdl/rtl-mdreloc-bfin.c +++ b/cpukit/libdl/rtl-mdreloc-bfin.c @@ -1,3 +1,38 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup + * + * @brief + */ + +/* + * Copyright (C) 2014 Chris Johns <chrisj@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. + */ + #include <sys/cdefs.h> #include <stdio.h> @@ -64,6 +99,12 @@ load_ptr(void *where) return (res); } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { diff --git a/cpukit/libdl/rtl-mdreloc-i386.c b/cpukit/libdl/rtl-mdreloc-i386.c index 40b09d4be2..09cbe4f42f 100644 --- a/cpukit/libdl/rtl-mdreloc-i386.c +++ b/cpukit/libdl/rtl-mdreloc-i386.c @@ -64,6 +64,12 @@ rtems_rtl_elf_rel_resolve_sym (Elf_Word type) return true; } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { diff --git a/cpukit/libdl/rtl-mdreloc-lm32.c b/cpukit/libdl/rtl-mdreloc-lm32.c index 4d47592e12..af904cd126 100644 --- a/cpukit/libdl/rtl-mdreloc-lm32.c +++ b/cpukit/libdl/rtl-mdreloc-lm32.c @@ -1,3 +1,38 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup + * + * @brief + */ + +/* + * Copyright (C) 2014 Chris Johns <chrisj@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. + */ + #include <sys/cdefs.h> #include <errno.h> @@ -57,6 +92,12 @@ rtems_rtl_elf_rel_resolve_sym (Elf_Word type) return true; } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { diff --git a/cpukit/libdl/rtl-mdreloc-m68k.c b/cpukit/libdl/rtl-mdreloc-m68k.c index 873574ef7c..a88d612c28 100644 --- a/cpukit/libdl/rtl-mdreloc-m68k.c +++ b/cpukit/libdl/rtl-mdreloc-m68k.c @@ -77,6 +77,12 @@ rtems_rtl_elf_rel_resolve_sym (Elf_Word type) return true; } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { diff --git a/cpukit/libdl/rtl-mdreloc-microblaze.c b/cpukit/libdl/rtl-mdreloc-microblaze.c new file mode 100644 index 0000000000..0956e22bc7 --- /dev/null +++ b/cpukit/libdl/rtl-mdreloc-microblaze.c @@ -0,0 +1,298 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (C) 2023 On-Line Applications Research Corporation (OAR) + * + * 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 <sys/cdefs.h> + +#include <errno.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include <rtems/rtl/rtl.h> +#include "rtl-elf.h" +#include "rtl-error.h" +#include <rtems/rtl/rtl-trace.h> +#include "rtl-unwind.h" +#include "rtl-unwind-dw2.h" + +uint32_t +rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj, + const Elf_Shdr* shdr) { + (void) obj; + (void) shdr; + return 0; +} + +uint32_t +rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj, + int section, + const char* name, + const Elf_Shdr* shdr, + const uint32_t flags) { + (void) obj; + (void) section; + (void) name; + (void) shdr; + return flags; +} + +bool +rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect) { + (void) obj; + (void) sect; + return false; +} + +bool +rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect) { + (void) obj; + (void) sect; + return false; +} + +bool +rtems_rtl_elf_rel_resolve_sym (Elf_Word type) { + return type != 0; +} + +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + +size_t +rtems_rtl_elf_relocate_tramp_max_size (void) { + /* + * Disable by returning 0. + */ + return 0; +} + +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj* obj, + const Elf_Rel* rel, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) { + (void) obj; + (void) rel; + (void) sect; + (void) symname; + (void) syminfo; + (void) symvalue; + return rtems_rtl_elf_rel_no_error; +} + +static void write16le(void *loc, uint16_t val) { + *((uint16_t *) loc) = val; +} + +static void write32le(void *loc, uint32_t val) { + *((uint32_t *) loc) = val; +} + +static uint16_t read16le(void *loc) { + return *((uint16_t *) loc); +} + +static uint32_t read32le(void *loc) { + return *((uint32_t *) loc); +} + +static rtems_rtl_elf_rel_status +rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj, + const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue, + const bool parsing) { + Elf_Word *where; + Elf_Word addend = (Elf_Word)rela->r_addend; + Elf_Addr target; + + where = (Elf_Addr *)(sect->base + rela->r_offset); + + /* Target value */ + target = (Elf_Addr)symvalue + addend; + /* Final PCREL value */ + Elf_Word pcrel_val = target - ((Elf_Word)where); + + if (parsing) { + return rtems_rtl_elf_rel_no_error; + } + + switch (ELF_R_TYPE(rela->r_info)) { + case R_TYPE(NONE): + break; + + case R_TYPE(64): + /* Set the lower 16 bits of where to the upper 16 bits of target */ + write16le(where, + (read16le(where) & 0xFFFF0000) | (target >> 16)); + /* Set the lower 16 bits of where + 4 to the lower 16 bits of target */ + write16le(where + 1, + (read16le(where + 1) & 0xFFFF0000) | (target & 0xFFFF)); + break; + + case R_TYPE(32): + { + uintptr_t addr = (uintptr_t)where; + if ((uintptr_t)where & 3) { + /* `where` is not aligned to a 4-byte boundary. */ + uintptr_t addr_down = addr & ~3; + uintptr_t addr_up = (addr + 3) & ~3; + + uint32_t value_down = read32le((void*)addr_down); + uint32_t value_up = read32le((void*)addr_up); + + /* + * Calculate how many bytes `where` is offset from the previous 4-byte + * boundary. + */ + unsigned offset = addr & 3; + + /* + * Combine `target` with `value_down` and `value_up` to form the new + * values to write. + */ + uint32_t new_value_down = (value_down & ((1 << (offset * 8)) - 1)) | + (target << (offset * 8)); + uint32_t new_value_up = (value_up & ~((1 << (offset * 8)) - 1)) | + (target >> ((4 - offset) * 8)); + + write32le((void*)addr_down, new_value_down); + write32le((void*)addr_up, new_value_up); + } else { + write32le(where, target); + } + } + break; + + case R_TYPE(32_PCREL): + write32le(where, pcrel_val); + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf ("rtl: R_MICROBLAZE_32_PCREL %p @ %p in %s\n", + (void *) * (where), where, rtems_rtl_obj_oname (obj)); + break; + + case R_TYPE(64_PCREL): + /* + * Compensate for the fact that the PC is 4 bytes ahead of the instruction + */ + pcrel_val -= 4; + /* Set the lower 16 bits of where to the upper 16 bits of target */ + write16le(where, + (read16le(where) & 0xFFFF0000) | (pcrel_val >> 16)); + /* Set the lower 16 bits of where + 4 to the lower 16 bits of target */ + write16le(where + 1, + (read16le(where + 1) & 0xFFFF0000) | (pcrel_val & 0xFFFF)); + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf ("rtl: R_MICROBLAZE_64_PCREL %p @ %p in %s\n", + (void *) * (where), where, rtems_rtl_obj_oname (obj)); + break; + + case R_TYPE(32_PCREL_LO): + write16le(where, (read16le(where) & 0xFFFF0000) | (pcrel_val & 0xFFFF)); + break; + + default: + rtems_rtl_set_error (EINVAL, + "%s: Unsupported relocation type %d " + "in non-PLT relocations", + sect->name, (uint32_t) ELF_R_TYPE(rela->r_info)); + return rtems_rtl_elf_rel_failure; + } + + return rtems_rtl_elf_rel_no_error; +} + +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj, + const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) { + return rtems_rtl_elf_reloc_rela (obj, + rela, + sect, + symname, + syminfo, + symvalue, + false); +} + +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj* obj, + const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) { + return rtems_rtl_elf_reloc_rela (obj, + rela, + sect, + symname, + syminfo, + symvalue, + true); +} + +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rel (rtems_rtl_obj* obj, + const Elf_Rel* rel, + const rtems_rtl_obj_sect* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) { + rtems_rtl_set_error (EINVAL, "rel type record not supported"); + return rtems_rtl_elf_rel_failure; +} + +bool +rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, + const char* name, + uint32_t flags) { + return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags); +} + +bool +rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj) { + return rtems_rtl_elf_unwind_dw2_register (obj); +} + +bool +rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj) { + return rtems_rtl_elf_unwind_dw2_deregister (obj); +} diff --git a/cpukit/libdl/rtl-mdreloc-mips.c b/cpukit/libdl/rtl-mdreloc-mips.c index d96f1503e6..91d88c9986 100644 --- a/cpukit/libdl/rtl-mdreloc-mips.c +++ b/cpukit/libdl/rtl-mdreloc-mips.c @@ -1,3 +1,38 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup + * + * @brief + */ + +/* + * Copyright (C) 2014 Chris Johns <chrisj@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. + */ + #include <sys/cdefs.h> #include <errno.h> @@ -58,6 +93,12 @@ rtems_rtl_elf_rel_resolve_sym (Elf_Word type) return true; } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { diff --git a/cpukit/libdl/rtl-mdreloc-moxie.c b/cpukit/libdl/rtl-mdreloc-moxie.c index 8c7169e532..a3cfe63b6a 100644 --- a/cpukit/libdl/rtl-mdreloc-moxie.c +++ b/cpukit/libdl/rtl-mdreloc-moxie.c @@ -1,3 +1,38 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup + * + * @brief + */ + +/* + * Copyright (C) 2014 Chris Johns <chrisj@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. + */ + #include <sys/cdefs.h> @@ -58,6 +93,12 @@ rtems_rtl_elf_rel_resolve_sym (Elf_Word type) return true; } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { diff --git a/cpukit/libdl/rtl-mdreloc-powerpc.c b/cpukit/libdl/rtl-mdreloc-powerpc.c index 48ecee58e5..09c2ab1512 100644 --- a/cpukit/libdl/rtl-mdreloc-powerpc.c +++ b/cpukit/libdl/rtl-mdreloc-powerpc.c @@ -1,3 +1,38 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup + * + * @brief + */ + +/* + * Copyright (C) 2014 Chris Johns <chrisj@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. + */ + /* * Taken from NetBSD and stripped of the relocations not needed on RTEMS. */ @@ -172,6 +207,12 @@ rtems_rtl_elf_rel_resolve_sym (Elf_Word type) return true; } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { @@ -313,37 +354,47 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj, break; case R_TYPE(16_HA): + case R_TYPE(TPREL16_HA): /* * value:6; Field:half16; Expression: #ha(S+A) + * value:72; Field:half16; Expression: #ha(S+A) */ if (!parsing) { tmp = symvalue + rela->r_addend; *(uint16_t *)where = (((tmp >> 16) + ((tmp & 0x8000) ? 1: 0)) & 0xffff); if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: 16_HA %p @ %p in %s\n", + printf ("rtl: %s16_HA %p @ %p in %s\n", + ELF_R_TYPE(rela->r_info) == R_TYPE(TPREL16_HA) ? "TPREL" : "", (void *)*(where), where, rtems_rtl_obj_oname (obj)); } break; case R_TYPE(16_HI): + case R_TYPE(TPREL16_HI): /* * value:5; Field:half16; Expression: #hi(S+A) + * value:71; Field:half16; Expression: #hi(S+A) */ if (!parsing) { *(uint16_t *)where = ((symvalue + rela->r_addend) >> 16) & 0xffff; if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: 16_HI %p @ %p in %s\n", + printf ("rtl: %s16_HI %p @ %p in %s\n", + ELF_R_TYPE(rela->r_info) == R_TYPE(TPREL16_HI) ? "TPREL" : "", (void *)*where, where, rtems_rtl_obj_oname (obj)); } break; + case R_TYPE(16_LO): + case R_TYPE(TPREL16_LO): /* * value:4; Field:half16; Expression: #lo(S+A) + * value:71; Field:half16; Expression: #lo(S+A) */ if (!parsing) { *(uint16_t *)where = (symvalue + (rela->r_addend)) & 0xffff; if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: 16_LO %p @ %p in %s\n", + printf ("rtl: %s16_LO %p @ %p in %s\n", + ELF_R_TYPE(rela->r_info) == R_TYPE(TPREL16_LO) ? "TPREL" : "", (void *)*where, where, rtems_rtl_obj_oname (obj)); } break; @@ -449,7 +500,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj, (void *)rela->r_offset, (void *)*where); rtems_rtl_set_error (EINVAL, "%s: Unsupported relocation type %" PRId32 - "in non-PLT relocations", + " in non-PLT relocations", sect->name, (uint32_t) ELF_R_TYPE(rela->r_info)); return rtems_rtl_elf_rel_failure; } diff --git a/cpukit/libdl/rtl-mdreloc-riscv.c b/cpukit/libdl/rtl-mdreloc-riscv.c index e6778dcc90..c0b7556366 100644 --- a/cpukit/libdl/rtl-mdreloc-riscv.c +++ b/cpukit/libdl/rtl-mdreloc-riscv.c @@ -89,6 +89,12 @@ rtems_rtl_elf_rel_resolve_sym (Elf_Word type) { return true; } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { /* diff --git a/cpukit/libdl/rtl-mdreloc-sparc.c b/cpukit/libdl/rtl-mdreloc-sparc.c index f8a4312a8a..9810de988e 100644 --- a/cpukit/libdl/rtl-mdreloc-sparc.c +++ b/cpukit/libdl/rtl-mdreloc-sparc.c @@ -87,46 +87,66 @@ static const uint32_t reloc_target_flags[] = { _RF_G| _RF_SZ(32) | _RF_RS(10), /* GOT22 */ _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PC10 */ _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PC22 */ - _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WPLT30 */ - _RF_SZ(32) | _RF_RS(0), /* COPY */ + _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WPLT30 */ + _RF_SZ(32) | _RF_RS(0), /* COPY */ _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* GLOB_DAT */ - _RF_SZ(32) | _RF_RS(0), /* JMP_SLOT */ - _RF_A| _RF_B|_RF_SZ(32) | _RF_RS(0), /* RELATIVE */ - _RF_S|_RF_A| _RF_U|_RF_SZ(32) | _RF_RS(0), /* UA_32 */ + _RF_SZ(32) | _RF_RS(0), /* JMP_SLOT */ + _RF_A| _RF_B| _RF_SZ(32) | _RF_RS(0), /* RELATIVE */ + _RF_S|_RF_A|_RF_U| _RF_SZ(32) | _RF_RS(0), /* UA_32 */ + + /* TLS and 64 bit relocs not listed here... */ }; +#define RELOC_TARGET_FLAGS_SIZE \ + (sizeof(reloc_target_flags) / sizeof(reloc_target_flags[0])) -#define NOT_CURRENTLY_USED_BUT_MAYBE_USEFUL -#ifdef NOT_CURRENTLY_USED_BUT_MAYBE_USEFUL +#define RTLD_DEBUG_RELOC +#ifdef RTLD_DEBUG_RELOC static const char *reloc_names[] = { "NONE", "RELOC_8", "RELOC_16", "RELOC_32", "DISP_8", "DISP_16", "DISP_32", "WDISP_30", "WDISP_22", "HI22", "22", "13", "LO10", "GOT10", "GOT13", "GOT22", "PC10", "PC22", "WPLT30", "COPY", - "GLOB_DAT", "JMP_SLOT", "RELATIVE", "UA_32" + "GLOB_DAT", "JMP_SLOT", "RELATIVE", "UA_32", + + /* not used with 32bit userland, besides a few of the TLS ones */ + "PLT32", + "HIPLT22", "LOPLT10", "LOPLT10", "PCPLT22", "PCPLT32", + "10", "11", "64", "OLO10", "HH22", + "HM10", "LM22", "PC_HH22", "PC_HM10", "PC_LM22", + "WDISP16", "WDISP19", "GLOB_JMP", "7", "5", "6", + "DISP64", "PLT64", "HIX22", "LOX10", "H44", "M44", + "L44", "REGISTER", "UA64", "UA16", + "TLS_GD_HI22", "TLS_GD_LO10", "TLS_GD_ADD", "TLS_GD_CALL", + "TLS_LDM_HI22", "TLS_LDM_LO10", "TLS_LDM_ADD", "TLS_LDM_CALL", + "TLS_LDO_HIX22", "TLS_LDO_LOX10", "TLS_LDO_ADD", "TLS_IE_HI22", + "TLS_IE_LO10", "TLS_IE_LD", "TLS_IE_LDX", "TLS_IE_ADD", "TLS_LE_HIX22", + "TLS_LE_LOX10", "TLS_DTPMOD32", "TLS_DTPMOD64", "TLS_DTPOFF32", + "TLS_DTPOFF64", "TLS_TPOFF32", "TLS_TPOFF64", }; #endif -#define RELOC_RESOLVE_SYMBOL(t) ((reloc_target_flags[t] & _RF_S) != 0) -#define RELOC_PC_RELATIVE(t) ((reloc_target_flags[t] & _RF_P) != 0) -#define RELOC_BASE_RELATIVE(t) ((reloc_target_flags[t] & _RF_B) != 0) -#define RELOC_UNALIGNED(t) ((reloc_target_flags[t] & _RF_U) != 0) -#define RELOC_USE_ADDEND(t) ((reloc_target_flags[t] & _RF_A) != 0) -#define RELOC_TARGET_SIZE(t) ((reloc_target_flags[t] >> 8) & 0xff) -#define RELOC_VALUE_RIGHTSHIFT(t) (reloc_target_flags[t] & 0xff) +#define RELOC_RESOLVE_SYMBOL(t) ((reloc_target_flags[t] & _RF_S) != 0) +#define RELOC_PC_RELATIVE(t) ((reloc_target_flags[t] & _RF_P) != 0) +#define RELOC_BASE_RELATIVE(t) ((reloc_target_flags[t] & _RF_B) != 0) +#define RELOC_UNALIGNED(t) ((reloc_target_flags[t] & _RF_U) != 0) +#define RELOC_USE_ADDEND(t) ((reloc_target_flags[t] & _RF_A) != 0) +#define RELOC_TARGET_SIZE(t) ((reloc_target_flags[t] >> 8) & 0xff) +#define RELOC_VALUE_RIGHTSHIFT(t) (reloc_target_flags[t] & 0xff) +#define RELOC_TLS(t) (t >= R_TYPE(TLS_GD_HI22)) static const int reloc_target_bitmask[] = { #define _BM(x) (~(-(1ULL << (x)))) - 0, /* NONE */ - _BM(8), _BM(16), _BM(32), /* RELOC_8, _16, _32 */ - _BM(8), _BM(16), _BM(32), /* DISP8, DISP16, DISP32 */ - _BM(30), _BM(22), /* WDISP30, WDISP22 */ - _BM(22), _BM(22), /* HI22, _22 */ - _BM(13), _BM(10), /* RELOC_13, _LO10 */ - _BM(10), _BM(13), _BM(22), /* GOT10, GOT13, GOT22 */ - _BM(10), _BM(22), /* _PC10, _PC22 */ - _BM(30), 0, /* _WPLT30, _COPY */ - -1, -1, -1, /* _GLOB_DAT, JMP_SLOT, _RELATIVE */ - _BM(32) /* _UA32 */ + 0, /* NONE */ + _BM(8), _BM(16), _BM(32), /* RELOC_8, _16, _32 */ + _BM(8), _BM(16), _BM(32), /* DISP8, DISP16, DISP32 */ + _BM(30), _BM(22), /* WDISP30, WDISP22 */ + _BM(22), _BM(22), /* HI22, _22 */ + _BM(13), _BM(10), /* RELOC_13, _LO10 */ + _BM(10), _BM(13), _BM(22), /* GOT10, GOT13, GOT22 */ + _BM(10), _BM(22), /* _PC10, _PC22 */ + _BM(30), 0, /* _WPLT30, _COPY */ + -1, -1, -1, /* _GLOB_DAT, JMP_SLOT, _RELATIVE */ + _BM(32) /* _UA32 */ #undef _BM }; #define RELOC_VALUE_BITMASK(t) (reloc_target_bitmask[t]) @@ -173,7 +193,26 @@ rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj, bool rtems_rtl_elf_rel_resolve_sym (Elf_Word type) { - return RELOC_RESOLVE_SYMBOL (type) ? true : false; + bool r = false; + if (type < RELOC_TARGET_FLAGS_SIZE) { + r = RELOC_RESOLVE_SYMBOL (type) ? true : false; + } + switch (type) { + case R_TYPE(TLS_DTPOFF32): + case R_TYPE(TLS_LE_HIX22): + case R_TYPE(TLS_LE_LOX10): + r = true; + break; + default: + break; + } + return r; +} + +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); } size_t @@ -241,6 +280,73 @@ rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj, value = rela->r_addend; /* + * Handle TLS relocations here, they are different. + */ + if (RELOC_TLS(type)) { + switch (type) { + case R_TYPE(TLS_DTPMOD32): + #if NETBSD_CODE__NOT_USED + *where = (Elf_Addr)defobj->tlsindex; + #endif + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf("rtl: reloc: TLS_DTPMOD32 %s in %s --> %p\n", + symname, rtems_rtl_obj_oname (obj), (void *)*where); + break; + + case R_TYPE(TLS_DTPOFF32): + *where = (Elf_Addr)(symvalue + rela->r_addend); + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf("rtl: reloc: TLS_DTPOFF32 %s in %s --> %p\n", + symname, rtems_rtl_obj_oname (obj), (void *)*where); + break; + + case R_TYPE(TLS_TPOFF32): + #if NETBSD_CODE__NOT_USED + if (!defobj->tls_static && + _rtld_tls_offset_allocate(__UNCONST(defobj))) + return ; + + *where = (Elf_Addr)(def->st_value - + defobj->tlsoffset + rela->r_addend); + #endif + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf("rtl: reloc: TLS_TPOFF32 %s in %s --> %p\n", + symname, rtems_rtl_obj_oname (obj), (void *)*where); + return rtems_rtl_elf_rel_failure; + + case R_TYPE(TLS_LE_HIX22): + *where |= ((symvalue + rela->r_addend) ^ 0xffffffff) >> 10; + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf("rtl: reloc: R_SPARC_TLS_LE_HIX22 %s in %s --> %p\n", + symname, rtems_rtl_obj_oname (obj), (void *)*where); + break; + + case R_TYPE(TLS_LE_LOX10): + *where |= ((symvalue + rela->r_addend) & 0x3ff) | 0x1c00; + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf("rtl: reloc: R_SPARC_TLS_LE_LOX10 %s in %s --> %p\n", + symname, rtems_rtl_obj_oname (obj), (void *)*where); + break; + + default: + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) + printf("rtl: reloc: unknown TLS relo: %d for %s in %s --> %p\n", + type, symname, rtems_rtl_obj_oname (obj), (void *)*where); + return rtems_rtl_elf_rel_failure; + } + return rtems_rtl_elf_rel_no_error; + } + + /* + * If it is no TLS relocation (handled above), we can not + * deal with it if it is beyond R_SPARC_6. + */ + if (type > R_TYPE(6)) + return rtems_rtl_elf_rel_failure; + + /* * Handle relative relocs here, as an optimization. */ if (type == R_TYPE (RELATIVE)) { diff --git a/cpukit/libdl/rtl-mdreloc-v850.c b/cpukit/libdl/rtl-mdreloc-v850.c index 859225ca6f..826763a2b5 100644 --- a/cpukit/libdl/rtl-mdreloc-v850.c +++ b/cpukit/libdl/rtl-mdreloc-v850.c @@ -1,3 +1,38 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup + * + * @brief + */ + +/* + * Copyright (C) 2014 Chris Johns <chrisj@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. + */ + #include <sys/cdefs.h> @@ -58,6 +93,12 @@ rtems_rtl_elf_rel_resolve_sym (Elf_Word type) return true; } +uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) +{ + (void) obj; + return sizeof(uint32_t); +} + size_t rtems_rtl_elf_relocate_tramp_max_size (void) { diff --git a/cpukit/libdl/rtl-obj-cache.c b/cpukit/libdl/rtl-obj-cache.c index 8791e2b1d5..837fd330eb 100644 --- a/cpukit/libdl/rtl-obj-cache.c +++ b/cpukit/libdl/rtl-obj-cache.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -14,6 +9,31 @@ * object file in a buffer to localise read performance. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rtl-obj-comp.c b/cpukit/libdl/rtl-obj-comp.c index 4608a41bf4..001d416e80 100644 --- a/cpukit/libdl/rtl-obj-comp.c +++ b/cpukit/libdl/rtl-obj-comp.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -14,6 +9,31 @@ * stream of data. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -95,7 +115,7 @@ rtems_rtl_obj_comp_read (rtems_rtl_obj_comp* comp, } if (rtems_rtl_trace (RTEMS_RTL_TRACE_COMP)) - printf ("rtl: comp: %2d: fd=%d length=%zu level=%u offset=%" PRIdoff_t " area=[%" + printf ("rtl: comp: %2d: fd=%d length=%zu level=%zu offset=%" PRIdoff_t " area=[%" PRIdoff_t ",%" PRIdoff_t "] read=%" PRIu32 " size=%zu\n", comp->fd, comp->cache->fd, length, comp->level, comp->offset, comp->offset, comp->offset + length, @@ -123,7 +143,7 @@ rtems_rtl_obj_comp_read (rtems_rtl_obj_comp* comp, if ((comp->level - buffer_level) != 0) { if (rtems_rtl_trace (RTEMS_RTL_TRACE_COMP)) - printf ("rtl: comp: copy-down: level=%u length=%zu\n", + printf ("rtl: comp: copy-down: level=%zu length=%zu\n", comp->level, comp->level - buffer_level); memmove (comp->buffer, @@ -201,7 +221,7 @@ rtems_rtl_obj_comp_read (rtems_rtl_obj_comp* comp, if (rtems_rtl_trace (RTEMS_RTL_TRACE_COMP)) printf ("rtl: comp: expand: offset=%" PRIdoff_t \ - " level=%u read=%" PRIu32 "\n", + " level=%zu read=%" PRIu32 "\n", comp->offset, comp->level, comp->read); } } diff --git a/cpukit/libdl/rtl-obj.c b/cpukit/libdl/rtl-obj.c index a7dd740549..c99e9f703f 100644 --- a/cpukit/libdl/rtl-obj.c +++ b/cpukit/libdl/rtl-obj.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Error */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -117,7 +137,6 @@ rtems_rtl_obj_free (rtems_rtl_obj* obj) rtems_rtl_obj_erase_sections (obj); rtems_rtl_obj_erase_dependents (obj); rtems_rtl_symbol_obj_erase (obj); - rtems_rtl_obj_erase_trampoline (obj); rtems_rtl_obj_free_names (obj); if (obj->sec_num != NULL) free (obj->sec_num); @@ -580,26 +599,6 @@ rtems_rtl_obj_find_section_by_mask (const rtems_rtl_obj* obj, } bool -rtems_rtl_obj_alloc_trampoline (rtems_rtl_obj* obj) -{ - if (obj->tramps_size == 0) - return true; - obj->trampoline = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, - obj->tramps_size, - true); - if (obj->trampoline == NULL) - rtems_rtl_set_error (ENOMEM, "no memory for the trampoline"); - obj->tramp_brk = obj->trampoline; - return obj->trampoline != NULL; -} - -void -rtems_rtl_obj_erase_trampoline (rtems_rtl_obj* obj) -{ - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, obj->trampoline); -} - -bool rtems_rtl_obj_alloc_dependents (rtems_rtl_obj* obj, size_t dependents) { rtems_rtl_obj_depends* depends; @@ -808,6 +807,12 @@ rtems_rtl_obj_bss_size (const rtems_rtl_obj* obj) return rtems_rtl_obj_section_size (obj, RTEMS_RTL_OBJ_SECT_BSS); } +size_t +rtems_rtl_obj_tramp_size (const rtems_rtl_obj* obj) +{ + return obj->tramp_slots * obj->tramp_slot_size; +} + uint32_t rtems_rtl_obj_bss_alignment (const rtems_rtl_obj* obj) { @@ -899,10 +904,10 @@ rtems_rtl_obj_synchronize_cache (rtems_rtl_obj* obj) size); } - if (obj->trampoline != NULL) + if (obj->tramp_base != NULL) { - rtems_cache_instruction_sync_after_code_change(obj->trampoline, - obj->tramps_size); + rtems_cache_instruction_sync_after_code_change(obj->tramp_base, + obj->tramp_size); } } @@ -1027,6 +1032,7 @@ rtems_rtl_obj_sections_locate (uint32_t mask, { base_offset = rtems_rtl_obj_align (base_offset, sect->alignment); sect->base = base + base_offset; + base_offset += sect->size; } if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD_SECT)) @@ -1035,9 +1041,6 @@ rtems_rtl_obj_sections_locate (uint32_t mask, order, sect->name, sect->base, sect->size, sect->flags, sect->alignment, sect->link); - if (sect->base) - base_offset += sect->size; - ++order; node = rtems_chain_first (sections); @@ -1049,34 +1052,95 @@ rtems_rtl_obj_sections_locate (uint32_t mask, } } -bool -rtems_rtl_obj_alloc_sections (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect_handler handler, - void* data) +static void +rtems_rtl_obj_set_sizes (rtems_rtl_obj* obj) { size_t text_size; + size_t tramp_size; size_t const_size; size_t eh_size; size_t data_size; size_t bss_size; - text_size = rtems_rtl_obj_text_size (obj) + rtems_rtl_obj_const_alignment (obj); - const_size = rtems_rtl_obj_const_size (obj) + rtems_rtl_obj_eh_alignment (obj); - eh_size = rtems_rtl_obj_eh_size (obj) + rtems_rtl_obj_data_alignment (obj); - data_size = rtems_rtl_obj_data_size (obj) + rtems_rtl_obj_bss_alignment (obj); - bss_size = rtems_rtl_obj_bss_size (obj); + /* + * The allocator may not align memory to the required boundary. Add + * the alignment size to the size allocated. + */ + text_size = rtems_rtl_obj_text_size (obj) + rtems_rtl_obj_text_alignment (obj); + tramp_size = rtems_rtl_obj_tramp_size (obj); + if (tramp_size != 0) + tramp_size += rtems_rtl_obj_tramp_alignment (obj); + const_size = rtems_rtl_obj_const_size (obj) + rtems_rtl_obj_const_alignment (obj); + eh_size = rtems_rtl_obj_eh_size (obj) + rtems_rtl_obj_eh_alignment (obj); + data_size = rtems_rtl_obj_data_size (obj) + rtems_rtl_obj_data_alignment (obj); + bss_size = rtems_rtl_obj_bss_size (obj) + rtems_rtl_obj_bss_alignment (obj); /* * Set the sizes held in the object data. We need this for a fast reference. */ - obj->text_size = text_size; + obj->text_size = text_size + tramp_size; + obj->tramp_size = tramp_size; obj->const_size = const_size; obj->data_size = data_size; obj->eh_size = eh_size; obj->bss_size = bss_size; + obj->exec_size = text_size + const_size + eh_size + data_size + bss_size; +} + +static void +rtems_rtl_obj_print_sizes (rtems_rtl_obj* obj, const char* label) +{ + if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD_SECT)) + { + printf ("rtl: %s sect: text - b:%p s:%zi a:%" PRIu32 "\n", + label, obj->text_base, obj->text_size, rtems_rtl_obj_text_alignment (obj)); + printf ("rtl: %s sect: tramp - b:%p s:%zi a:%" PRIu32 "\n", + label, obj->tramp_base, obj->tramp_size, rtems_rtl_obj_tramp_alignment (obj)); + printf ("rtl: %s sect: const - b:%p s:%zi a:%" PRIu32 "\n", + label, obj->const_base, obj->const_size, rtems_rtl_obj_const_alignment (obj)); + printf ("rtl: %s sect: eh - b:%p s:%zi a:%" PRIu32 "\n", + label, obj->eh_base, obj->eh_size, rtems_rtl_obj_eh_alignment (obj)); + printf ("rtl: %s sect: data - b:%p s:%zi a:%" PRIu32 "\n", + label, obj->data_base, obj->data_size, rtems_rtl_obj_data_alignment (obj)); + printf ("rtl: %s sect: bss - b:%p s:%zi a:%" PRIu32 "\n", + label, obj->bss_base, obj->bss_size, rtems_rtl_obj_bss_alignment (obj)); + } +} + +static void +rtems_rtl_obj_locate (rtems_rtl_obj* obj) +{ /* + * Locate all text, data and bss sections in seperate operations so each type of + * section is grouped together. + */ + rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_TEXT, + rtems_rtl_alloc_text_tag (), + obj, obj->text_base); + rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_CONST, + rtems_rtl_alloc_const_tag (), + obj, obj->const_base); + rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_EH, + rtems_rtl_alloc_eh_tag (), + obj, obj->eh_base); + rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_DATA, + rtems_rtl_alloc_data_tag (), + obj, obj->data_base); + rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_BSS, + rtems_rtl_alloc_bss_tag (), + obj, obj->bss_base); +} + +bool +rtems_rtl_obj_alloc_sections (rtems_rtl_obj* obj, + int fd, + rtems_rtl_obj_sect_handler handler, + void* data) +{ + rtems_rtl_obj_set_sizes (obj); + + /* * Perform any specific allocations for sections. */ if (handler != NULL) @@ -1096,33 +1160,28 @@ rtems_rtl_obj_alloc_sections (rtems_rtl_obj* obj, * Let the allocator manage the actual allocation. The user can use the * standard heap or provide a specific allocator with memory protection. */ - if (!rtems_rtl_alloc_module_new (&obj->text_base, text_size, - &obj->const_base, const_size, - &obj->eh_base, eh_size, - &obj->data_base, data_size, - &obj->bss_base, bss_size)) + if (!rtems_rtl_alloc_module_new (&obj->text_base, obj->text_size, + &obj->const_base, obj->const_size, + &obj->eh_base, obj->eh_size, + &obj->data_base, obj->data_size, + &obj->bss_base, obj->bss_size)) { obj->exec_size = 0; rtems_rtl_set_error (ENOMEM, "no memory to load obj"); return false; } - obj->exec_size = text_size + const_size + eh_size + data_size + bss_size; - - if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD_SECT)) + /* + * Set the trampoline base if there are trampolines + */ + if (obj->tramp_size != 0) { - printf ("rtl: load sect: text - b:%p s:%zi a:%" PRIu32 "\n", - obj->text_base, text_size, rtems_rtl_obj_text_alignment (obj)); - printf ("rtl: load sect: const - b:%p s:%zi a:%" PRIu32 "\n", - obj->const_base, const_size, rtems_rtl_obj_const_alignment (obj)); - printf ("rtl: load sect: eh - b:%p s:%zi a:%" PRIu32 "\n", - obj->eh_base, eh_size, rtems_rtl_obj_eh_alignment (obj)); - printf ("rtl: load sect: data - b:%p s:%zi a:%" PRIu32 "\n", - obj->data_base, data_size, rtems_rtl_obj_data_alignment (obj)); - printf ("rtl: load sect: bss - b:%p s:%zi a:%" PRIu32 "\n", - obj->bss_base, bss_size, rtems_rtl_obj_bss_alignment (obj)); + obj->tramp_base = obj->tramp_brk = + obj->text_base + obj->text_size - obj->tramp_size; } + rtems_rtl_obj_print_sizes (obj, "alloc"); + /* * Determine the load order. */ @@ -1133,24 +1192,48 @@ rtems_rtl_obj_alloc_sections (rtems_rtl_obj* obj, rtems_rtl_obj_sections_link_order (RTEMS_RTL_OBJ_SECT_BSS, obj); /* - * Locate all text, data and bss sections in seperate operations so each type of - * section is grouped together. + * Locate the sections to the allocated section bases */ - rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_TEXT, - rtems_rtl_alloc_text_tag (), - obj, obj->text_base); - rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_CONST, - rtems_rtl_alloc_const_tag (), - obj, obj->const_base); - rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_EH, - rtems_rtl_alloc_eh_tag (), - obj, obj->eh_base); - rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_DATA, - rtems_rtl_alloc_data_tag (), - obj, obj->data_base); - rtems_rtl_obj_sections_locate (RTEMS_RTL_OBJ_SECT_BSS, - rtems_rtl_alloc_bss_tag (), - obj, obj->bss_base); + rtems_rtl_obj_locate (obj); + + return true; +} + +bool +rtems_rtl_obj_resize_sections (rtems_rtl_obj* obj) +{ + rtems_rtl_obj_set_sizes (obj); + + /* + * Let the allocator manage the resizing. + */ + if (!rtems_rtl_alloc_module_resize (&obj->text_base, obj->text_size, + &obj->const_base, obj->const_size, + &obj->eh_base, obj->eh_size, + &obj->data_base, obj->data_size, + &obj->bss_base, obj->bss_size)) + { + rtems_rtl_obj_free (obj); + obj->exec_size = 0; + rtems_rtl_set_error (ENOMEM, "no memory resize obj"); + return false; + } + + /* + * Set the trampoline base if there are trampolines + */ + if (obj->tramp_size != 0) + { + obj->tramp_base = obj->tramp_brk = + obj->text_base + obj->text_size - obj->tramp_size; + } + + rtems_rtl_obj_print_sizes (obj, "resize"); + + /* + * Locate the sections to the allocated section bases + */ + rtems_rtl_obj_locate (obj); return true; } diff --git a/cpukit/libdl/rtl-rap.c b/cpukit/libdl/rtl-rap.c index 32f4bd6ff5..3fd1428bf2 100644 --- a/cpukit/libdl/rtl-rap.c +++ b/cpukit/libdl/rtl-rap.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012-2013, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * This is the RAP format loader support.. */ +/* + * COPYRIGHT (c) 2012-2013, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -316,7 +336,7 @@ rtems_rtl_rap_relocate (rtems_rtl_rap* rap, rtems_rtl_obj* obj) " addend=%" PRIu32 "\n", r, info, offset, addend); - type = info & 0xff; + type = ELF_R_TYPE(info); if ((info & (1 << 31)) == 0) { @@ -330,7 +350,7 @@ rtems_rtl_rap_relocate (rtems_rtl_rap* rap, rtems_rtl_obj* obj) return false; } - symvalue = (Elf_Addr) symsect->base + addend; + symvalue = (Elf_Addr)(uintptr_t) symsect->base + addend; } else if (rtems_rtl_elf_rel_resolve_sym (type)) { @@ -370,7 +390,7 @@ rtems_rtl_rap_relocate (rtems_rtl_rap* rap, rtems_rtl_obj* obj) return false; } - symvalue = (Elf_Addr) symbol->value; + symvalue = (Elf_Addr)(uintptr_t) symbol->value; } if (is_rela) diff --git a/cpukit/libdl/rtl-rap.h b/cpukit/libdl/rtl-rap.h index ae656c25ca..49d83a872f 100644 --- a/cpukit/libdl/rtl-rap.h +++ b/cpukit/libdl/rtl-rap.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker ELF Headers */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_RAP_H_) #define _RTEMS_RTL_RAP_H_ diff --git a/cpukit/libdl/rtl-shell.c b/cpukit/libdl/rtl-shell.c index 9f8a1364a8..18f1e08901 100644 --- a/cpukit/libdl/rtl-shell.c +++ b/cpukit/libdl/rtl-shell.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * A simple RTL command to aid using the RTL. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -386,7 +406,7 @@ typedef struct const rtems_rtl_obj_print* print; /**< The print data. */ bool first; /**< Is this the first line printed. */ bool show_name; /**< Show the object name. */ - size_t indent; /**< The indent. */ + int indent; /**< The indent. */ } rtems_rtl_dep_data; static bool @@ -552,7 +572,7 @@ rtems_rtl_obj_printer (rtems_rtl_obj_print* print, rtems_rtl_obj* obj) rtems_printf (print->printer, "%-*cslots : %zu\n", indent + 4, ' ', slots); rtems_printf (print->printer, "%-*csize : %zu\n", indent + 4, ' ', - obj->tramps_size); + obj->tramp_size); rtems_printf (print->printer, "%-*cslot size : %zu\n", indent + 4, ' ', obj->tramp_size); rtems_printf (print->printer, "%-*cused : %zu\n", indent + 4, ' ', @@ -829,7 +849,7 @@ rtems_rtl_shell_archive (const rtems_printer* printer, int argc, char* argv[]) while (!rtems_chain_is_tail (&rtl->archives.archives, node)) { - #define SYM_DUPLICATE (1 << ((8 * sizeof (size_t)) - 1)) + #define SYM_DUPLICATE (((size_t) 1) << ((8 * sizeof (size_t)) - 1)) rtems_rtl_archive* archive = (rtems_rtl_archive*) node; diff --git a/cpukit/libdl/rtl-string.c b/cpukit/libdl/rtl-string.c index 61ab4925d5..dc2f6be526 100644 --- a/cpukit/libdl/rtl-string.c +++ b/cpukit/libdl/rtl-string.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker String managment. */ +/* + * COPYRIGHT (c) 2012 Chris Johns <chrisj@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. + */ + #include <string.h> #include <rtems/rtl/rtl-allocator.h> diff --git a/cpukit/libdl/rtl-string.h b/cpukit/libdl/rtl-string.h index 1aa2624fdf..fe4c50d2ed 100644 --- a/cpukit/libdl/rtl-string.h +++ b/cpukit/libdl/rtl-string.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker String managment. */ +/* + * COPYRIGHT (c) 2012 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_STRING_H_) #define _RTEMS_RTL_STRING_H_ diff --git a/cpukit/libdl/rtl-sym.c b/cpukit/libdl/rtl-sym.c index 593069fba0..bd203fd158 100644 --- a/cpukit/libdl/rtl-sym.c +++ b/cpukit/libdl/rtl-sym.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012-2014, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Object File Symbol Table. */ +/* + * COPYRIGHT (c) 2012-2014, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -57,6 +77,22 @@ rtems_rtl_symbol_global_insert (rtems_rtl_symbols* symbols, &symbol->node); } +static rtems_rtl_tls_offset* +rtems_rtl_symbol_find_tls_offset (size_t index, + rtems_rtl_tls_offset* tls_offsets, + size_t tls_size) +{ + size_t entry; + for (entry = 0; entry < tls_size; ++entry) + { + if (tls_offsets[entry].index == index) + { + return &tls_offsets[entry]; + } + } + return NULL; +} + bool rtems_rtl_symbol_table_open (rtems_rtl_symbols* symbols, size_t buckets) @@ -83,9 +119,11 @@ rtems_rtl_symbol_table_close (rtems_rtl_symbols* symbols) } bool -rtems_rtl_symbol_global_add (rtems_rtl_obj* obj, - const unsigned char* esyms, - unsigned int size) +rtems_rtl_symbol_global_add (rtems_rtl_obj* obj, + const unsigned char* esyms, + unsigned int size, + rtems_rtl_tls_offset* tls_offsets, + unsigned int tls_size) { rtems_rtl_symbols* symbols; rtems_rtl_obj_sym* sym; @@ -104,7 +142,7 @@ rtems_rtl_symbol_global_add (rtems_rtl_obj* obj, return false; } ++count; - s += l + sizeof (unsigned long) + 1; + s += l + sizeof (void *) + 1; } /* @@ -139,6 +177,9 @@ rtems_rtl_symbol_global_add (rtems_rtl_obj* obj, symbols = rtems_rtl_global_symbols (); + obj->global_syms = count; + + count = 0; s = 0; sym = obj->global_table; @@ -151,24 +192,29 @@ rtems_rtl_symbol_global_add (rtems_rtl_obj* obj, */ union { uint8_t data[sizeof (void*)]; - void* value; + void* voidp; } copy_voidp; + rtems_rtl_tls_offset* tls_off; int b; sym->name = (const char*) &esyms[s]; s += strlen (sym->name) + 1; for (b = 0; b < sizeof (void*); ++b, ++s) copy_voidp.data[b] = esyms[s]; - sym->value = copy_voidp.value; + tls_off = rtems_rtl_symbol_find_tls_offset (count, tls_offsets, tls_size); + if (tls_off == NULL) { + sym->value = copy_voidp.voidp; + } else { + sym->value = (void*) tls_off->offset(); + } if (rtems_rtl_trace (RTEMS_RTL_TRACE_GLOBAL_SYM)) printf ("rtl: esyms: %s -> %8p\n", sym->name, sym->value); if (rtems_rtl_symbol_global_find (sym->name) == NULL) rtems_rtl_symbol_global_insert (symbols, sym); + ++count; ++sym; } - obj->global_syms = count; - return true; } diff --git a/cpukit/libdl/rtl-tls.c b/cpukit/libdl/rtl-tls.c new file mode 100644 index 0000000000..7eb12831eb --- /dev/null +++ b/cpukit/libdl/rtl-tls.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup rtems_rtld + * + * @brief RTEMS Run-Time Link Editor Thread Local Storage + * + * TLS support the RTL. + */ + +/* + * COPYRIGHT (c) 2023 Chris Johns <chrisj@rtems.org> + * + * Copyright (C) 2023 embedded brains GmbH & Co. KG + * + * 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 "rtl-tls.h" + +#include <rtems/score/cpuimpl.h> +#include <rtems/score/percpu.h> +#include <rtems/score/thread.h> + +void* rtems_rtl_tls_get_base (void) +{ + return _CPU_Get_TLS_thread_pointer (&_Thread_Get_executing()->Registers); +} diff --git a/cpukit/libdl/rtl-tls.h b/cpukit/libdl/rtl-tls.h new file mode 100644 index 0000000000..78dc738dd4 --- /dev/null +++ b/cpukit/libdl/rtl-tls.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup rtems_rtld + * + * @brief RTEMS Run-Time Link Editor Thread Local Storage + * + * TLS support the RTL. + */ + +/* + * COPYRIGHT (c) 2023 Chris Johns <chrisj@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. + */ + +#if !defined (_RTEMS_RTL_TLS_H_) +#define _RTEMS_RTL_TLS_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void* rtems_rtl_tls_get_base (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/cpukit/libdl/rtl-trace.c b/cpukit/libdl/rtl-trace.c index 15d195ffad..f3f86902cd 100644 --- a/cpukit/libdl/rtl-trace.c +++ b/cpukit/libdl/rtl-trace.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -16,6 +11,31 @@ * disable. */ +/* + * COPYRIGHT (c) 2012 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rtl-trampoline.h b/cpukit/libdl/rtl-trampoline.h index e04c20863b..d3f5a5ae39 100644 --- a/cpukit/libdl/rtl-trampoline.h +++ b/cpukit/libdl/rtl-trampoline.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2019 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -54,6 +49,31 @@ * used as the instructions cannot be loaded. */ +/* + * COPYRIGHT (c) 2019 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_TRAMPOLINE_H_) #define _RTEMS_RTL_TRAMPOLINE_H_ diff --git a/cpukit/libdl/rtl-unresolved.c b/cpukit/libdl/rtl-unresolved.c index 8e1c2abc90..43a05e9887 100644 --- a/cpukit/libdl/rtl-unresolved.c +++ b/cpukit/libdl/rtl-unresolved.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Object File Unresolved Relocations Table. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -790,8 +810,8 @@ rtems_rtl_unresolved_dump_iterator (rtems_rtl_unresolv_rec* rec, case rtems_rtl_trampoline_reloc: if (dd->show_relocs) printf (" %3zu: 2:reloc%c: obj:%s name:%2d: sect:%d\n", - rec->type == rtems_rtl_unresolved_reloc ? 'R' : 'T', dd->rec, + rec->type == rtems_rtl_unresolved_reloc ? 'R' : 'T', rec->rec.reloc.obj == NULL ? "resolved" : rec->rec.reloc.obj->oname, rec->rec.reloc.name, rec->rec.reloc.sect); diff --git a/cpukit/libdl/rtl-unwind-arm.c b/cpukit/libdl/rtl-unwind-arm.c new file mode 100644 index 0000000000..35361fe8d5 --- /dev/null +++ b/cpukit/libdl/rtl-unwind-arm.c @@ -0,0 +1,65 @@ +#include "rtl-unwind-arm.h" + +bool +rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, + const char* name, + uint32_t flags) +{ + /* + * We location the EH sections in section flags. + */ + return false; +} + +bool +rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj) +{ + return true; +} + +bool +rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj) +{ + obj->loader = NULL; + return true; +} + +/* + * A weak reference is in libgcc, provide a real version and provide a way to + * manage loaded modules. + * + * Passed in the return address and a reference to the number of records + * found. We set the start of the exidx data and the number of records. + */ +_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, + int* nrec) __attribute__ ((__noinline__, + __used__, + __noclone__)); + +_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, + int* nrec) +{ + rtems_rtl_data* rtl; + rtems_chain_node* node; + __EIT_entry* exidx_start = &__exidx_start; + __EIT_entry* exidx_end = &__exidx_end; + + rtl = rtems_rtl_lock (); + + node = rtems_chain_first (&rtl->objects); + while (!rtems_chain_is_tail (&rtl->objects, node)) { + rtems_rtl_obj* obj = (rtems_rtl_obj*) node; + if (rtems_rtl_obj_text_inside (obj, (void*) return_address)) { + exidx_start = (__EIT_entry*) obj->eh_base; + exidx_end = (__EIT_entry*) (obj->eh_base + obj->eh_size); + break; + } + node = rtems_chain_next (node); + } + + rtems_rtl_unlock (); + + *nrec = exidx_end - exidx_start; + + return (_Unwind_Ptr) exidx_start; +} diff --git a/cpukit/libdl/rtl-unwind-arm.h b/cpukit/libdl/rtl-unwind-arm.h new file mode 100644 index 0000000000..08a2660560 --- /dev/null +++ b/cpukit/libdl/rtl-unwind-arm.h @@ -0,0 +1,46 @@ +#include <unwind.h> + +#include <rtems/rtl/rtl.h> +#include "rtl-unwind.h" + +typedef unsigned _Unwind_Word __attribute__((__mode__(__word__))); +typedef _Unwind_Word _uw; + +bool +rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, + const char* name, + uint32_t flags); + +bool +rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj); + +bool +rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj); + +/* An exception index table entry. */ +typedef struct __EIT_entry +{ + _uw fnoffset; + _uw content; +} __EIT_entry; + +/* The exception index table location in the base module */ +extern __EIT_entry __exidx_start; +extern __EIT_entry __exidx_end; + +/* + * A weak reference is in libgcc, provide a real version and provide a way to + * manage loaded modules. + * + * Passed in the return address and a reference to the number of records + * found. We set the start of the exidx data and the number of records. + */ +_Unwind_Ptr +__gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, + int* nrec) __attribute__ ((__noinline__, + __used__, + __noclone__)); + +_Unwind_Ptr +__gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, + int* nrec); diff --git a/cpukit/libdl/rtl-unwind-dw2.c b/cpukit/libdl/rtl-unwind-dw2.c index 0526fa5e5b..4198092baa 100644 --- a/cpukit/libdl/rtl-unwind-dw2.c +++ b/cpukit/libdl/rtl-unwind-dw2.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012-2016, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * This is the RTL implementation. */ +/* + * COPYRIGHT (c) 2012-2016, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/cpukit/libdl/rtl-unwind-dw2.h b/cpukit/libdl/rtl-unwind-dw2.h index ef76a3771b..44f79fb057 100644 --- a/cpukit/libdl/rtl-unwind-dw2.h +++ b/cpukit/libdl/rtl-unwind-dw2.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2016, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Unwind DWARF Support. */ +/* + * COPYRIGHT (c) 2016, 2018 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_UNWIND_DW2_H_) #define _RTEMS_RTL_UNWIND_DW2_H_ diff --git a/cpukit/libdl/rtl-unwind.h b/cpukit/libdl/rtl-unwind.h index 36ec5c4a11..0eed49381e 100644 --- a/cpukit/libdl/rtl-unwind.h +++ b/cpukit/libdl/rtl-unwind.h @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2016, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -13,6 +8,31 @@ * @brief RTEMS Run-Time Linker Unwind Support. */ +/* + * COPYRIGHT (c) 2016, 2018 Chris Johns <chrisj@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. + */ + #if !defined (_RTEMS_RTL_UNWIND_H_) #define _RTEMS_RTL_UNWIND_H_ diff --git a/cpukit/libdl/rtl.c b/cpukit/libdl/rtl.c index b86f7cc850..8250af24c9 100644 --- a/cpukit/libdl/rtl.c +++ b/cpukit/libdl/rtl.c @@ -1,10 +1,5 @@ -/* - * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -15,6 +10,31 @@ * This is the RTL implementation. */ +/* + * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@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. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -837,8 +857,10 @@ rtems_rtl_path_prepend (const char* path) } void -rtems_rtl_base_sym_global_add (const unsigned char* esyms, - unsigned int size) +rtems_rtl_base_sym_global_add (const unsigned char* esyms, + unsigned int size, + rtems_rtl_tls_offset* tls_offsets, + unsigned int tls_size) { if (rtems_rtl_trace (RTEMS_RTL_TRACE_GLOBAL_SYM)) printf ("rtl: adding global symbols, table size %u\n", size); @@ -849,7 +871,7 @@ rtems_rtl_base_sym_global_add (const unsigned char* esyms, return; } - rtems_rtl_symbol_global_add (rtl->base, esyms, size); + rtems_rtl_symbol_global_add (rtl->base, esyms, size, tls_offsets, tls_size); rtems_rtl_unlock (); } |