summaryrefslogtreecommitdiff
path: root/cpukit
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2023-08-28 13:21:48 +1000
committerChris Johns <chrisj@rtems.org>2023-08-28 13:21:48 +1000
commitac6de5a3e91e05f068f8ed2e548056357024b944 (patch)
treeb272bb5a4f573bd7661f1481bbec0f5ef4814023 /cpukit
parentb9f11607b1731bc5f2391653cd8f4ebe48ba278e (diff)
cpukit/libdl: Correctly account for section alignments
- 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
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/libdl/rtl-obj.c31
1 files changed, 12 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));