From b7a06f3f7f4c48c76cde480e9dd253f1836f0e12 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Mon, 19 May 2025 14:14:17 -0700 Subject: [PATCH] sort on section index too --- src/linker/lnk.c | 8 +++++++- src/linker/lnk_section_table.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/linker/lnk.c b/src/linker/lnk.c index d70dc380..c2ac24d9 100644 --- a/src/linker/lnk.c +++ b/src/linker/lnk.c @@ -1034,7 +1034,12 @@ lnk_section_contrib_ptr_is_before(void *raw_a, void *raw_b) // sort on obj position on command line if (cmp == 0) { - cmp = u64_compar(&a->u.obj_idx, &b->u.obj_idx); + cmp = u32_compar(&a->u.obj_idx, &b->u.obj_idx); + + // sort on section index + if (cmp == 0) { + cmp = u32_compar(&a->u.obj_sect_idx, &b->u.obj_sect_idx); + } } } @@ -2256,6 +2261,7 @@ lnk_build_win32_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_S sc->align = sc_align; sc->data_list = data_n; sc->u.obj_idx = obj_idx; + sc->u.obj_sect_idx = sect_idx; sc->u.sort_idx_size = (U16)sect_sort_idx.size; sc->u.sort_idx = sect_sort_idx.str; diff --git a/src/linker/lnk_section_table.h b/src/linker/lnk_section_table.h index 2cdbf041..9d3280e9 100644 --- a/src/linker/lnk_section_table.h +++ b/src/linker/lnk_section_table.h @@ -14,6 +14,7 @@ typedef struct LNK_SectionContrib struct { U16 sort_idx_size; U32 obj_idx; + U32 obj_sect_idx; U8 *sort_idx; }; struct {