From 47ef37ed8ec14742e2d687f9eddb7b1568922fcc Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Mon, 2 Jun 2025 00:08:12 -0700 Subject: [PATCH] fix section order --- src/linker/lnk.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/linker/lnk.c b/src/linker/lnk.c index 95c259d6..f0f9d7d4 100644 --- a/src/linker/lnk.c +++ b/src/linker/lnk.c @@ -1082,11 +1082,16 @@ lnk_section_contrib_ptr_is_before(void *raw_a, void *raw_b) int cmp; - // place sections without sort postfix first - if (a->u.sort_idx_size == 0 && b->u.sort_idx_size > 0) { - cmp = -1; - } else if (a->u.sort_idx_size > 0 && b->u.sort_idx_size == 0) { - cmp = +1; + if (a->u.sort_idx_size <= 1 && b->u.sort_idx_size <= 1) { + if (a->u.sort_idx_size == b->u.sort_idx_size) { + cmp = cmp = u32_compar(&a->u.obj_idx, &b->u.obj_idx); + if (cmp == 0) { + cmp = u32_compar(&a->u.obj_sect_idx, &b->u.obj_sect_idx); + } + } else { + // place sections without sort postfix first + cmp = a->u.sort_idx_size < b->u.sort_idx_size; + } } else { // sort on section postfix String8 a_sort_idx = str8(a->u.sort_idx, a->u.sort_idx_size);