summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mach_amd64.h1
-rw-r--r--src/cmd/nm/nm.c7
-rw-r--r--src/libmach_amd64/obj.c3
3 files changed, 8 insertions, 3 deletions
diff --git a/include/mach_amd64.h b/include/mach_amd64.h
index 3ad0efcbb..30cd4dcd0 100644
--- a/include/mach_amd64.h
+++ b/include/mach_amd64.h
@@ -85,6 +85,7 @@ struct Sym
char type;
char *name;
char *gotype;
+ int sequence; // order in file
};
/*
* End of Plan 9 a.out.h
diff --git a/src/cmd/nm/nm.c b/src/cmd/nm/nm.c
index 63c77bd92..66748eef7 100644
--- a/src/cmd/nm/nm.c
+++ b/src/cmd/nm/nm.c
@@ -185,11 +185,13 @@ cmp(void *vs, void *vt)
s = vs;
t = vt;
- if(nflag)
+ if(nflag) // sort on address (numeric) order
if((*s)->value < (*t)->value)
return -1;
else
return (*s)->value > (*t)->value;
+ if(sflag) // sort on file order (sequence)
+ return (*s)->sequence - (*t)->sequence;
return strcmp((*s)->name, (*t)->name);
}
/*
@@ -298,8 +300,7 @@ printsyms(Sym **symptr, long nsym)
char *cp;
char path[512];
- if(!sflag)
- qsort(symptr, nsym, sizeof(*symptr), (void*)cmp);
+ qsort(symptr, nsym, sizeof(*symptr), (void*)cmp);
wid = 0;
for (i=0; i<nsym; i++) {
diff --git a/src/libmach_amd64/obj.c b/src/libmach_amd64/obj.c
index 7a6e20451..8bd138421 100644
--- a/src/libmach_amd64/obj.c
+++ b/src/libmach_amd64/obj.c
@@ -108,6 +108,8 @@ static void objreset(void);
static void objlookup(int, char *, int, uint);
static void objupdate(int, int);
+static int sequence;
+
int
objtype(Biobuf *bp, char **name)
{
@@ -295,6 +297,7 @@ objlookup(int id, char *name, int type, uint sig)
sp->s.type = type;
sp->s.sig = sig;
sp->s.value = islocal(type) ? MAXOFF : 0;
+ sp->s.sequence = sequence++;
names[id] = &sp->s;
sp->next = hash[h];
hash[h] = sp;