shithub: scc

Download patch

ref: 26e92fcaa069bac388b1d0571e14957e012fdc4d
parent: 1ff5de058cdce8d0c471124369dca23e9fa6a9a7
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Aug 29 17:46:08 EDT 2019

[libmach] Use int as index in symbols and sections

It is very unlikely that we will be able to link
a program with more than 30000 symbols in a machine
where int is 16 bits.

--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -65,12 +65,11 @@
 
 extern int strip(Obj *obj);
 extern int pc2line(Obj *obj, unsigned long long pc, char *fname, int *ln);
-extern int rebase(Obj *obj, long index, unsigned long offset);
+extern int rebase(Obj *obj, int index, unsigned long long offset);
 extern int mapsec(Obj *obj, int idx, FILE *fp);
 
-/* TODO: Change index to int */
-extern Symbol *getsym(Obj *obj, long *index, Symbol *sym);
-extern Section *getsec(Obj *obj, long *index, Section *sec);
+extern Symbol *getsym(Obj *obj, int *index, Symbol *sym);
+extern Section *getsec(Obj *obj, int *index, Section *sec);
 
 extern int setindex(int, long, char **, long *, FILE *);
 extern int getindex(int, long *, char ***, long **, FILE *);
--- a/src/cmd/ld/pass1.c
+++ b/src/cmd/ld/pass1.c
@@ -21,7 +21,7 @@
 static int
 is_needed(Obj *obj)
 {
-	long i;
+	int i;
 	Symbol sym;
 
 	for (i = 0; getsym(obj, &i, &sym); i++) {
@@ -65,7 +65,7 @@
 static void
 newsym(Symbol *sym, Obj *obj)
 {
-	long id;
+	int id;
 	Section sec;
 
 	if (sym->type == 'U' || islower(sym->type))
@@ -80,8 +80,7 @@
 static void
 load(FILE *fp, int inlib)
 {
-	int t;
-	long i;
+	int t, i;
 	Obj *obj;
 	Section sec;
 	Symbol sym;
--- a/src/cmd/nm.c
+++ b/src/cmd/nm.c
@@ -152,8 +152,7 @@
 static void
 nmobj(FILE *fp, int type)
 {
-	int err = 1;
-	long i;
+	int i, err = 1;
 	Obj *obj;
 	Symbol sym;
 	struct symtbl tbl = {NULL, 0};
--- a/src/cmd/ranlib.c
+++ b/src/cmd/ranlib.c
@@ -137,8 +137,7 @@
 static int
 newmember(FILE *fp)
 {
-	int t, ret = 0;
-	long i;
+	int i,t, ret = 0;
 	Obj *obj;
 	Symbol sym;
 
--- a/src/cmd/size.c
+++ b/src/cmd/size.c
@@ -40,7 +40,7 @@
 static void
 sizeobj(FILE *fp, int type)
 {
-	long i;
+	int i;
 	Obj *obj;
 	unsigned long long total, *p;
 	struct sizes siz;
--- a/src/libmach/coff32/coff32.h
+++ b/src/libmach/coff32/coff32.h
@@ -39,5 +39,5 @@
 extern int coff32xgetidx(int order,
                          long *nsyms, char ***namep, long **offsp, FILE *fp);
 
-extern Symbol *coff32getsym(Obj *obj, long *idx, Symbol *sym);
-extern Section *coff32getsec(Obj *obj, long *idx, Section *sec);
+extern Symbol *coff32getsym(Obj *obj, int *idx, Symbol *sym);
+extern Section *coff32getsec(Obj *obj, int *idx, Section *sec);
--- a/src/libmach/coff32/coff32getsec.c
+++ b/src/libmach/coff32/coff32getsec.c
@@ -6,7 +6,7 @@
 #include "coff32.h"
 
 Section *
-coff32getsec(Obj *obj, long *idx, Section *sec)
+coff32getsec(Obj *obj, int *idx, Section *sec)
 {
 	long n = *idx;
 	int type;
--- a/src/libmach/coff32/coff32getsym.c
+++ b/src/libmach/coff32/coff32getsym.c
@@ -54,7 +54,7 @@
 }
 
 Symbol *
-coff32getsym(Obj *obj, long *idx, Symbol *sym)
+coff32getsym(Obj *obj, int *idx, Symbol *sym)
 {
 	long n = *idx;
 	SYMENT *ent;
--- a/src/libmach/getsec.c
+++ b/src/libmach/getsec.c
@@ -5,7 +5,7 @@
 #include "libmach.h"
 
 Section *
-getsec(Obj *obj, long *idx, Section *sec)
+getsec(Obj *obj, int *idx, Section *sec)
 {
 	return (*obj->ops->getsec)(obj, idx, sec);
 }
--- a/src/libmach/getsym.c
+++ b/src/libmach/getsym.c
@@ -5,7 +5,7 @@
 #include "libmach.h"
 
 Symbol *
-getsym(Obj *obj, long *index, Symbol *sym)
+getsym(Obj *obj, int *index, Symbol *sym)
 {
 	return (*obj->ops->getsym)(obj, index, sym);
 }
--- a/src/libmach/libmach.h
+++ b/src/libmach/libmach.h
@@ -36,8 +36,8 @@
 	int (*strip)(Obj *obj);
 	int (*pc2line)(Obj *, unsigned long long , char *, int *);
 
-	Symbol *(*getsym)(Obj *obj, long *index, Symbol *sym);
-	Section *(*getsec)(Obj *obj, long *index, Section *sec);
+	Symbol *(*getsym)(Obj *obj, int *index, Symbol *sym);
+	Section *(*getsec)(Obj *obj, int *index, Section *sec);
 
 	int (*setidx)(long nsyms, char *names[], long offset[], FILE *fp);
 	int (*getidx)(long *nsyms, char ***names, long **offset, FILE *fp);
--- a/src/libmach/rebase.c
+++ b/src/libmach/rebase.c
@@ -5,7 +5,7 @@
 #include "libmach.h"
 
 int
-rebase(Obj *obj, long idx, unsigned long base)
+rebase(Obj *obj, int idx, unsigned long long base)
 {
 	return 0;
 }