Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:16

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup rtems_rtl
0007  *
0008  * @brief RTEMS Run-Time Linker Object File Trampoline Relocations Table.
0009  *
0010  * Cache relocation records that could result in a trampoline. The unresolved
0011  * symbol table holds variable the symbol name (length string) and the object
0012  * file's relocation records that reference the unresolved symbol. The
0013  * trampoline cache is an extension to this table to reuse the code and memory
0014  * and support trampolines.
0015  *
0016  * Some architectures require trampolines or veneers to extend the range of
0017  * some instructions. The compiler generates small optimized instructions
0018  * assuming most destinations are within the range of the instruction. The
0019  * instructions are smaller in size and can have a number of encodings with
0020  * different ranges. If a relocation record points to a symbol that is out of
0021  * range for the instruction a trampoline is used to extend the instruction's
0022  * range. A trampoline is a small fragment of architecture specific
0023  * instructions located within the range of the relocation record instruction
0024  * that can reach the entire address range. The trampoline's execution is
0025  * transparent to the execution of the object file.
0026  *
0027  * An object file that needs a trampoline has a table allocated close to the
0028  * text section. It has to be close to ensure the largest possible object file
0029  * can be spported. The number of slots in a table depends on:
0030  *
0031  *  # Location of the code
0032  *  # The type of relocation records in the object file
0033  *  # The instruction encoding the relocation record points too
0034  *  # The landing address of the instruction
0035  *
0036  * The allocation of the text segment and the trampoline table have to happen
0037  * with the allocator lock being locked and held to make sure no other
0038  * allocations happen inbetween the text section allocation and the trampoline
0039  * table. Holding an allocator lock limits what the link editor can do when
0040  * when the default heap allocator is being used. If calls any operating
0041  * system services including the file system use the same allocator a deadlock
0042  * will occur. This creates a conflict between performing the allocations
0043  * together and reading the instructions while holding the allocator lock.
0044  *
0045  * The trampoline cache holds the parsed relocation records that could result
0046  * in a trampoline. These records can be exaimined after the allocation of the
0047  * text segment to determine how many relocation record target's are out of
0048  * range. The minimum range for a specific type of relocation record has to be
0049  * used as the instructions cannot be loaded.
0050  */
0051 
0052 /*
0053  *  COPYRIGHT (c) 2019 Chris Johns <chrisj@rtems.org>
0054  *
0055  * Redistribution and use in source and binary forms, with or without
0056  * modification, are permitted provided that the following conditions
0057  * are met:
0058  * 1. Redistributions of source code must retain the above copyright
0059  *    notice, this list of conditions and the following disclaimer.
0060  * 2. Redistributions in binary form must reproduce the above copyright
0061  *    notice, this list of conditions and the following disclaimer in the
0062  *    documentation and/or other materials provided with the distribution.
0063  *
0064  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0065  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0066  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0067  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0068  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0069  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0070  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0071  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0072  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0073  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0074  * POSSIBILITY OF SUCH DAMAGE.
0075  */
0076 
0077 #if !defined (_RTEMS_RTL_TRAMPOLINE_H_)
0078 #define _RTEMS_RTL_TRAMPOLINE_H_
0079 
0080 #include <rtems/rtl/rtl-unresolved.h>
0081 
0082 #ifdef __cplusplus
0083 extern "C" {
0084 #endif /* __cplusplus */
0085 
0086 /**
0087  * Add a relocation to the list of trampolinr relocations.
0088  *
0089  * @param obj The object table the relocation record is for.
0090  * @param flags Format specific flags.
0091  * @param sect The target section number the relocation references.
0092  * @param symvalue The symbol's value.
0093  * @param rel The format specific relocation data.
0094  * @retval true The relocation has been added.
0095  * @retval false The relocation could not be added.
0096  */
0097 bool rtems_rtl_trampoline_add (rtems_rtl_obj*        obj,
0098                                const uint16_t        flags,
0099                                const uint16_t        sect,
0100                                const rtems_rtl_word  symvalue,
0101                                const rtems_rtl_word* rel);
0102 
0103 /**
0104  * Remove the relocation records for an object file.
0105  *
0106  * @param obj The object table the symbols are for.
0107  */
0108 void rtems_rtl_trampoline_remove (rtems_rtl_obj* obj);
0109 
0110 #ifdef __cplusplus
0111 }
0112 #endif /* __cplusplus */
0113 
0114 #endif