scc

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

commit 893983575da0f76075ffd8f3d60cb23d6c3475e6
parent 5ee2e8b13124750a58dc720afbc16d4d0a6f71f4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 30 Oct 2021 11:19:30 +0200

libmach: Add elf64str()

Elf64str() deals with all the cases to obtain a string related to
a section or to a symbol.

Diffstat:
Msrc/libmach/elf64/elf64.c | 17+++++++++++++++++
Msrc/libmach/elf64/elf64.h | 2++
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/libmach/elf64/elf64.c b/src/libmach/elf64/elf64.c @@ -19,3 +19,20 @@ struct objops elf64 = { .getsec = NULL, .loadmap = NULL, }; + +char * +elf64str(Obj *obj, int n, long stroff) +{ + char *tbl; + size_t siz; + struct elf64 *elf; + + elf = obj->data; + + tbl = elf->strtbl[n]; + siz = elf->strsiz[n]; + + if (!tbl || siz < stroff) + return ""; + return &tbl[stroff]; +} diff --git a/src/libmach/elf64/elf64.h b/src/libmach/elf64/elf64.h @@ -51,3 +51,5 @@ extern int elf64xgetidx(int, long *, char ***, long **, FILE *); extern Symbol *elf64getsym(Obj *, int *, Symbol *); extern Section *elf64getsec(Obj *, int *, Section *); extern Map *elf64loadmap(Obj *, FILE *); + +extern char *elf64str(Obj *, int n, long);