changeset 116:5f4141ee175b

tiobjd: retain the original symtab order for symbols at the same position
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 03 Apr 2014 07:00:08 +0000
parents 2f23301d2f86
children f9fde7f36ae3
files ticoff/intstruct.h ticoff/symtab.c ticoff/tables.c
diffstat 3 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ticoff/intstruct.h	Thu Apr 03 06:50:07 2014 +0000
+++ b/ticoff/intstruct.h	Thu Apr 03 07:00:08 2014 +0000
@@ -18,6 +18,7 @@
 };
 
 struct internal_syment {
+	unsigned	number;
 	char		*name;
 	unsigned	value;
 	int		scnum;
--- a/ticoff/symtab.c	Thu Apr 03 06:50:07 2014 +0000
+++ b/ticoff/symtab.c	Thu Apr 03 07:00:08 2014 +0000
@@ -164,10 +164,16 @@
 compare_for_sort(p1, p2)
 	struct internal_syment **p1, **p2;
 {
+	/* sort by value first */
 	if ((*p1)->value < (*p2)->value)
 		return(-1);
 	if ((*p1)->value > (*p2)->value)
 		return(1);
+	/* if same value, retain the original symtab order */
+	if ((*p1)->number < (*p2)->number)
+		return(-1);
+	if ((*p1)->number > (*p2)->number)
+		return(1);
 	else
 		return(0);
 }
--- a/ticoff/tables.c	Thu Apr 03 06:50:07 2014 +0000
+++ b/ticoff/tables.c	Thu Apr 03 07:00:08 2014 +0000
@@ -98,6 +98,7 @@
 			exit(1);
 		}
 		symtab[n] = in;
+		in->number = n;
 		in->name = get_secorsym_name(symtab_raw[n].e_name);
 		in->value = get_u32(symtab_raw[n].e_value);
 		in->scnum = get_s16(symtab_raw[n].e_scnum);