scc

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

commit 1f617a389401a5a3f7d5a6a93e0d497ade6dde0d
parent 465cee819edcff18b3bab228975e4a42d739a164
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 28 Aug 2019 15:28:46 +0100

[libmach] Add forgotten files

These files were forgotten in different commits.

Diffstat:
Asrc/libmach/coff32/coff32getsec.c | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/libmach/delobj.c | 14++++++++++++++
Asrc/libmach/getindex.c | 21+++++++++++++++++++++
Asrc/libmach/getsec.c | 11+++++++++++
Asrc/libmach/setindex.c | 21+++++++++++++++++++++
Asrc/libmach/strip.c | 11+++++++++++
Asrc/libmach/writeobj.c | 12++++++++++++
7 files changed, 157 insertions(+), 0 deletions(-)

diff --git a/src/libmach/coff32/coff32getsec.c b/src/libmach/coff32/coff32getsec.c @@ -0,0 +1,67 @@ +#include <stdio.h> + +#include <scc/mach.h> + +#include "../libmach.h" +#include "coff32.h" + +Section * +coff32getsec(Obj *obj, long *idx, Section *sec) +{ + long n = *idx; + int type; + unsigned sflags; + unsigned long flags; + SCNHDR *scn; + Coff32 *coff = obj->data; + FILHDR *hdr = &coff->hdr; + + if (n >= hdr->f_nscns) + return NULL; + + scn = &coff->scns[n]; + flags = scn->s_flags; + + if (flags & STYP_TEXT) { + type = 'T'; + sflags = SALLOC | SRELOC | SLOAD | SEXEC | SREAD; + if (flags & STYP_NOLOAD) + sflags |= SSHARED; + } else if (flags & STYP_DATA) { + type = 'D'; + sflags = SALLOC | SRELOC | SLOAD | SWRITE | SREAD; + if (flags & STYP_NOLOAD) + sflags |= SSHARED; + } else if (flags & STYP_BSS) { + type = 'B'; + sflags = SALLOC | SREAD | SWRITE; + } else if (flags & STYP_INFO) { + type = 'N'; + sflags = 0; + } else if (flags & STYP_LIB) { + type = 'T'; + sflags = SRELOC; + } else if (flags & STYP_DSECT) { + type = 'D'; + sflags = SRELOC; + } else if (flags & STYP_PAD) { + type = 'D'; + sflags = SLOAD; + } else { + type = 'D'; /* We assume that STYP_REG is data */ + sflags = SALLOC | SRELOC | SLOAD | SWRITE | SREAD; + } + + if (flags & STYP_NOLOAD) + sflags &= ~SLOAD; + + sec->name = scn->s_name; + sec->index = n; + sec->size = scn->s_size; + sec->base = 0; /* TODO: Check what is the actual value */ + sec->type = type; + sec->flags = sflags; + sec->align = 4; /* TODO: Check how align is defined in coff */ + + return sec; +} diff --git a/src/libmach/delobj.c b/src/libmach/delobj.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <scc/mach.h> + +#include "libmach.h" + +void +delobj(Obj *obj) +{ + (*obj->ops->del)(obj); + free(obj); +}+ \ No newline at end of file diff --git a/src/libmach/getindex.c b/src/libmach/getindex.c @@ -0,0 +1,21 @@ +#include <errno.h> +#include <stdio.h> + +#include <scc/mach.h> + +#include "libmach.h" + +int +getindex(int type, long *nsyms, char ***names, long **offs, FILE *fp) +{ + int fmt; + + fmt = FORMAT(type); + if (fmt >= NFORMATS) { + errno = ERANGE; + return -1; + } + + return (*objops[fmt]->getidx)(nsyms, names, offs, fp); +} + diff --git a/src/libmach/getsec.c b/src/libmach/getsec.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +#include <scc/mach.h> + +#include "libmach.h" + +Section * +getsec(Obj *obj, long *idx, Section *sec) +{ + return (*obj->ops->getsec)(obj, idx, sec); +} diff --git a/src/libmach/setindex.c b/src/libmach/setindex.c @@ -0,0 +1,21 @@ +#include <errno.h> +#include <stdio.h> + +#include <scc/mach.h> + +#include "libmach.h" + +int +setindex(int type, long nsyms, char **names, long *offs, FILE *fp) +{ + int fmt; + + fmt = FORMAT(type); + if (fmt >= NFORMATS) { + errno = ERANGE; + return -1; + } + + return (*objops[fmt]->setidx)(nsyms, names, offs, fp); +} + diff --git a/src/libmach/strip.c b/src/libmach/strip.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +#include <scc/mach.h> + +#include "libmach.h" + +int +strip(Obj *obj) +{ + return (*obj->ops->strip)(obj); +} diff --git a/src/libmach/writeobj.c b/src/libmach/writeobj.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +#include <scc/mach.h> + +#include "libmach.h" + +int +writeobj(Obj *obj, FILE *fp) +{ + return (obj->ops->write)(obj, fp); +}+ \ No newline at end of file