guard against circular section merges

This commit is contained in:
Nikita Smith
2025-05-20 13:34:16 -07:00
committed by Ryan Fleury
parent 2e531cd70a
commit c2b3634e7a
2 changed files with 14 additions and 0 deletions
+1
View File
@@ -36,6 +36,7 @@ typedef enum
LNK_Error_SectRefsDiscardedMemory,
LNK_Error_IllegalSectionMerge,
LNK_Error_IllegalRelocation,
LNK_Error_CircularMerge,
LNK_Error_StopLast,
LNK_Error_First,
+13
View File
@@ -275,6 +275,19 @@ lnk_section_table_merge(LNK_SectionTable *sectab, LNK_MergeDirectiveList merge_l
}
}
}
// guard against circular merges
{
if (str8_match(merge_node->data.dst, merge_node->data.src, 0)) {
lnk_error(LNK_Error_CircularMerge, "detected circular /MERGE:%S=%S", merge_node->data.src, merge_node->data.dst);
}
for (LNK_SectionNode *sect_n = sectab->merge_list.first; sect_n != 0; sect_n = sect_n->next) {
if (str8_match(sect_n->data.name, merge_node->data.dst, 0) ||
str8_match(sect_n->data.name, merge_node->data.src, 0)) {
lnk_error(LNK_Error_CircularMerge, "detected circular /MERGE:%S=%S", merge_node->data.src, merge_node->data.dst);
}
}
}
// are we trying to merge section that was already merged?
LNK_Section *merge_sect = 0;