scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 73b42fa96c7f6580d0cc18a4611c620e3ec28e44
parent 87395a88f21b0102683b3d1ce8754a5f6fa6cf5a
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Fri,  8 May 2026 14:03:50 +0200

libmach: Make coff32csetidx generic

The function coff32csetidx() can be used for elf too because they
share the index file format. A.out had a different layout, but as
we don't support it yet, we can just use the name setidx32().

Diffstat:
Msrc/libmach/Makefile | 1+
Msrc/libmach/coff32/Makefile | 1-
Msrc/libmach/coff32/coff32setidx.c | 2+-
Dsrc/libmach/coff32/coff32xsetidx.c | 33---------------------------------
Msrc/libmach/coff32/fun.h | 1-
Msrc/libmach/libmach.h | 2++
Asrc/libmach/setidx32.c | 32++++++++++++++++++++++++++++++++
7 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/src/libmach/Makefile b/src/libmach/Makefile @@ -31,6 +31,7 @@ OBJS =\ readobj.o\ rebase.o\ setindex.o\ + setidx32.o\ mapsec.o\ mapseg.o\ setsec.o\ diff --git a/src/libmach/coff32/Makefile b/src/libmach/coff32/Makefile @@ -22,7 +22,6 @@ OBJS =\ coff32type.o\ coff32write.o\ coff32xgetidx.o\ - coff32xsetidx.o\ COFFHDRS =\ $(INCDIR)/bits/scc/coff32/aouthdr.h\ diff --git a/src/libmach/coff32/coff32setidx.c b/src/libmach/coff32/coff32setidx.c @@ -9,5 +9,5 @@ int coff32setidx(long nsymbols, char *names[], long offs[], FILE *fp) { - return coff32xsetidx(BIG_ENDIAN, nsymbols, names, offs, fp); + return setidx32(BIG_ENDIAN, nsymbols, names, offs, fp); } diff --git a/src/libmach/coff32/coff32xsetidx.c b/src/libmach/coff32/coff32xsetidx.c @@ -1,33 +0,0 @@ -#include <stdio.h> -#include <string.h> - -#include <scc/mach.h> - -#include "../libmach.h" -#include "fun.h" - -int -coff32xsetidx(int order, long nsyms, char *names[], long offs[], FILE *fp) -{ - long i, n; - size_t len; - unsigned char buff[4]; - - pack(order, buff, "l", nsyms); - fwrite(buff, 4, 1, fp); - n = 4; - - for (i = 0; i < nsyms; i++) { - pack(order, buff, "l", offs[i]); - fwrite(buff, 4, 1, fp); - n += 4; - } - - for (i = 0; i < nsyms; i++) { - len = strlen(names[i]) + 1; - fwrite(names[i], len, 1, fp); - n += len; - } - - return fflush(fp) == EOF ? -1 : 0; -} diff --git a/src/libmach/coff32/fun.h b/src/libmach/coff32/fun.h @@ -9,7 +9,6 @@ int coff32write(Obj *, Map *, FILE *); int coff32probe(unsigned char *, char **); int coff32type(char *); -int coff32xsetidx(int, long , char *[], long[], FILE *); int coff32xgetidx(int, long *, char ***, long **, FILE *); Symbol *coff32getsym(Obj *, int *, Symbol *); diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h @@ -1,5 +1,7 @@ #ifdef stdin int copysec(Mapsec *, FILE *); +int setidx32(int, long, char *[], long [], FILE *); + #endif /* common functions */ diff --git a/src/libmach/setidx32.c b/src/libmach/setidx32.c @@ -0,0 +1,32 @@ +#include <stdio.h> +#include <string.h> + +#include <scc/mach.h> + +#include "libmach.h" + +int +setidx32(int order, long nsyms, char *names[], long offs[], FILE *fp) +{ + long i, n; + size_t len; + unsigned char buff[4]; + + pack(order, buff, "l", nsyms); + fwrite(buff, 4, 1, fp); + n = 4; + + for (i = 0; i < nsyms; i++) { + pack(order, buff, "l", offs[i]); + fwrite(buff, 4, 1, fp); + n += 4; + } + + for (i = 0; i < nsyms; i++) { + len = strlen(names[i]) + 1; + fwrite(names[i], len, 1, fp); + n += len; + } + + return fflush(fp) == EOF ? -1 : 0; +}