summaryrefslogtreecommitdiffstats
path: root/cpukit/libdl/rtl-sym.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libdl/rtl-sym.c')
-rw-r--r--cpukit/libdl/rtl-sym.c76
1 files changed, 61 insertions, 15 deletions
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;
}