commit c63c6229624807c6248faa5e396a65cb0bdff70f
parent b72ae1daa29675c82e45d85776a40257a56241ff
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 22 Mar 2024 08:16:56 +0100
as: Initial function to write object files
This is the first version of the function that writes an actual object
file instead of a dump of the different sections of the object.
Diffstat:
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/cmd/as/symbol.c b/src/cmd/as/symbol.c
@@ -468,6 +468,31 @@ dumpsec(FILE *src, FILE *dst)
}
void
+writecoff(char *fname)
+{
+ FILE *fp;
+
+ if ((fp = fopen(fname, "wb")) == NULL)
+ goto error;
+
+ if (writeobj(obj, map, fp) < 0) {
+ fputs("as: corrupted object type\n", stderr);
+ goto error;
+ }
+
+ if (fclose(fp) == EOF)
+ goto error;
+ outfile = NULL;
+ return;
+
+error:
+ fprintf(stderr, "as: %s: error writing output file\n", fname);
+ if (errno)
+ perror("as");
+ exit(EXIT_FAILURE);
+}
+
+void
writeout(char *fname)
{
FILE *fp;
diff --git a/src/libmach/coff32/coff32loadmap.c b/src/libmach/coff32/coff32loadmap.c
@@ -11,6 +11,7 @@ coff32loadmap(Obj *obj, FILE *fp)
long i;
Map *map;
long nsec;
+ FILE *src;
SCNHDR *scn;
struct coff32 *coff = obj->data;
FILHDR *hdr = &coff->hdr;
@@ -20,11 +21,19 @@ coff32loadmap(Obj *obj, FILE *fp)
return NULL;
for (scn = coff->scns; nsec--; ++scn) {
- unsigned long o = obj->pos + scn->s_scnptr;
+ unsigned long o;
unsigned long long b = scn->s_paddr;
unsigned long long e = b + scn->s_size;
- setmap(map, scn->s_name, fp, b, e, o);
+ if (scn->s_scnptr != 0) {
+ o = obj->pos + scn->s_scnptr;
+ src = fp;
+ } else {
+ o = 0;
+ src = NULL;
+ }
+
+ setmap(map, scn->s_name, src, b, e, o);
}
return map;