[PATCH 1/2] cpukit/libdl: Correctly account for section alignments
chrisj at rtems.org
chrisj at rtems.org
Mon Aug 28 04:04:20 UTC 2023
From: Chris Johns <chrisj at rtems.org>
- Add the section alignment to the size as the allocator may not
provide correctly aligned memory
- Only include symbols in the section when locating symbols. The
powerpc was incorrectly adding SDATA BSS symbols to the BSS offset
overrunning the section
Closes #4950
---
cpukit/libdl/rtl-obj.c | 31 ++++++++++++------------------
testsuites/libtests/dl07/dl-load.c | 1 +
2 files changed, 13 insertions(+), 19 deletions(-)
diff --git a/cpukit/libdl/rtl-obj.c b/cpukit/libdl/rtl-obj.c
index a35fbf9e8d..c99e9f703f 100644
--- a/cpukit/libdl/rtl-obj.c
+++ b/cpukit/libdl/rtl-obj.c
@@ -1032,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))
@@ -1040,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);
@@ -1064,23 +1062,18 @@ rtems_rtl_obj_set_sizes (rtems_rtl_obj* obj)
size_t data_size;
size_t bss_size;
- text_size = rtems_rtl_obj_text_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)
- {
- text_size += rtems_rtl_obj_tramp_alignment (obj);
- tramp_size += rtems_rtl_obj_const_alignment (obj);
- }
- else
- {
- text_size += 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);
+ 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.
@@ -1098,7 +1091,7 @@ rtems_rtl_obj_set_sizes (rtems_rtl_obj* obj)
static void
rtems_rtl_obj_print_sizes (rtems_rtl_obj* obj, const char* label)
{
-if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD_SECT))
+ 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));
diff --git a/testsuites/libtests/dl07/dl-load.c b/testsuites/libtests/dl07/dl-load.c
index 58e3e06f78..2946120ca6 100644
--- a/testsuites/libtests/dl07/dl-load.c
+++ b/testsuites/libtests/dl07/dl-load.c
@@ -32,6 +32,7 @@
RTEMS_RTL_TRACE_WARNING | \
RTEMS_RTL_TRACE_LOAD | \
RTEMS_RTL_TRACE_UNLOAD | \
+ RTEMS_RTL_TRACE_LOAD_SECT | \
RTEMS_RTL_TRACE_SYMBOL | \
RTEMS_RTL_TRACE_RELOC | \
RTEMS_RTL_TRACE_ALLOCATOR | \
--
2.37.1
More information about the devel
mailing list