ref: a32972000ab291dd3cefeceb5a62864b0e01a371
parent: 5b919477354727041f8a522f0f91273e623fa58d
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 23 15:26:02 EDT 2019
[libmach] Stop using Objsymdef in setidx This type is not needed and it is creating confusion. This is the first step to remove the type.
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -59,7 +59,7 @@
int (*addseg)(Obj *obj, void *seg);
int (*strip)(Obj *obj);
int (*addr2line)(Obj *, unsigned long long , char *, int *);
- int (*setidx)(long nsyms, Objsymdef *def, FILE *fp);
+ int (*setidx)(long nsyms, char *names[], long offset[], FILE *fp);
int (*getidx)(long *nsyms, Objsymdef **def, FILE *fp);
};
--- a/src/cmd/ranlib.c
+++ b/src/cmd/ranlib.c
@@ -265,11 +265,14 @@
return ret;
}
+
static void
ranlib(char *fname)
{
- int c;
+ long *offs, i;
+ char **names;
FILE *fp, *idx, *out;
+ Objsymdef *dp;
struct fprop prop;
errno = 0;
@@ -276,6 +279,8 @@
nolib = 0;
artype = -1;
nsymbols = 0;
+ offs = NULL;
+ names = NULL;
filename = fname;
freehash();
@@ -288,10 +293,18 @@
if (!readsyms(fp))
goto error;
- if (nolib)
+ if (nolib || nsymbols == 0)
goto error;
- if ((*ops->setidx)(nsymbols, head, idx) < 0)
+ offs = malloc(sizeof(long) * nsymbols);
+ names = malloc(sizeof(*names) * nsymbols);
+
+ for (dp = head, i = 0; i < nsymbols; dp = dp->next, i++) {
+ offs[i] = dp->offset;
+ names[i] = dp->name;
+ }
+
+ if ((*ops->setidx)(nsymbols, names, offs, idx) < 0)
goto error;
if (getstat(fname, &prop) < 0)
@@ -302,18 +315,25 @@
if (!merge(out, &prop, fp, idx))
goto error;
+ free(offs);
+ free(names);
fclose(fp);
fclose(idx);
+ offs = NULL;
+ names = NULL;
fp = idx = NULL;
if (!copy(out, fname))
goto error;
-
fclose(out);
return;
error:
+ if (offs)
+ free(offs);
+ if (names)
+ free(names);
if (errno)
error(errstr());
if (idx)
--- a/src/libmach/coff32/coff32.h
+++ b/src/libmach/coff32/coff32.h
@@ -26,7 +26,7 @@
extern int coff32new(Obj *obj);
extern int coff32read(Obj *obj, FILE *fp);
-extern int coff32setidx(long nsymbols, Objsymdef *head, FILE *fp);
+extern int coff32setidx(long nsymbols, char *names[], long offs[], FILE *fp);
extern int coff32getidx(long *nsyms, Objsymdef **def, FILE *fp);
extern int coff32addr2line(Obj *, unsigned long long , char *, int *);
extern int coff32strip(Obj *obj);
@@ -34,5 +34,6 @@
extern int coff32write(Obj *obj, FILE *fp);
extern int coff32probe(unsigned char *buf, char **name);
-extern int coff32xsetidx(int order, long nsyms, Objsymdef *head, FILE *fp);
+extern int coff32xsetidx(int order,
+ long nsymbols, char *names[], long offs[], FILE *fp);
extern int coff32xgetidx(int order, long *nsyms, Objsymdef **def, FILE *fp);
--- a/src/libmach/coff32/coff32setidx.c
+++ b/src/libmach/coff32/coff32setidx.c
@@ -6,7 +6,7 @@
#include "coff32.h"
int
-coff32setidx(long nsymbols, Objsymdef *head, FILE *fp)
+coff32setidx(long nsymbols, char *names[], long offs[], FILE *fp)
{
- return coff32xsetidx(BIG_ENDIAN, nsymbols, head, fp);
+ return coff32xsetidx(BIG_ENDIAN, nsymbols, names, offs, fp);
}
--- a/src/libmach/coff32/coff32xsetidx.c
+++ b/src/libmach/coff32/coff32xsetidx.c
@@ -6,7 +6,7 @@
#include "../libmach.h"
int
-coff32xsetidx(int order, long nsyms, Objsymdef *head, FILE *fp)
+coff32xsetidx(int order, long nsyms, char *names[], long offs[], FILE *fp)
{
long i, n;
size_t len;
@@ -17,15 +17,15 @@
fwrite(buff, 4, 1, fp);
n = 4;
- for (def = head; def; def = def->next) {
- pack(order, buff, "l", (long) def->offset);
+ for (i = 0; i < nsyms; i++) {
+ pack(order, buff, "l", offs[i]);
fwrite(buff, 4, 1, fp);
n += 4;
}
- for (def = head; def; def = def->next) {
- len = strlen(def->name) + 1;
- fwrite(def->name, len, 1, fp);
+ for (i = 0; i < nsyms; i++) {
+ len = strlen(names[i]) + 1;
+ fwrite(names[i], len, 1, fp);
n += len;
}