diff options
author | midipix <writeonce@midipix.org> | 2017-02-08 00:41:56 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2017-02-08 01:19:08 -0500 |
commit | 3e55ee4c865e68c28daf9fe0a90346fa5c3446f2 (patch) | |
tree | 0f9a805b6497bb828dc7da4fb5ef27a6a0ef862e /src/object | |
parent | c12a925ddba06fc1d11298fc26c10f2d5ffb91db (diff) | |
download | mdso-3e55ee4c865e68c28daf9fe0a90346fa5c3446f2.tar.bz2 mdso-3e55ee4c865e68c28daf9fe0a90346fa5c3446f2.tar.xz |
driver: utility api: added mdso_create_implib_objects().
Diffstat (limited to 'src/object')
-rw-r--r-- | src/object/mdso_create_implib_objects.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/object/mdso_create_implib_objects.c b/src/object/mdso_create_implib_objects.c new file mode 100644 index 0000000..dd681e0 --- /dev/null +++ b/src/object/mdso_create_implib_objects.c @@ -0,0 +1,79 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +#include <mdso/mdso.h> +#include "mdso_errinfo_impl.h" + +static void mdso_init_objname(char * buf, const char * fmt, const char * str) +{ + char hexstr[24]; + long long unsigned int crc64; + + if (strlen(str) + strlen(fmt) > (PATH_MAX - 1)) { + crc64 = mdso_crc64_mbstr((const unsigned char *)str,0); + sprintf(hexstr,"%llx",crc64); + sprintf(buf,fmt,hexstr); + } else + sprintf(buf,fmt,str); +} + +mdso_api int mdso_create_implib_objects(const struct mdso_driver_ctx * dctx) +{ + struct mdso_unit_ctx * uctx; + const char ** unit; + FILE * fout; + char objname[PATH_MAX]; + const char * const * sym; + int ret; + + mdso_init_objname(objname,".dsometa_%s.o",dctx->cctx->libname); + + if (!(fout = mdso_create_object(dctx,objname))) + return MDSO_NESTED_ERROR(dctx); + + ret = mdso_objgen_dsometa(dctx,fout,0); + fclose(fout); + + if (ret < 0) + return MDSO_NESTED_ERROR(dctx); + + for (unit=dctx->units; *unit; unit++) { + if (mdso_get_unit_ctx(dctx,*unit,&uctx)) + return MDSO_NESTED_ERROR(dctx); + + for (sym=uctx->syms; *sym; sym++) { + mdso_init_objname(objname,".%s_symentry.o",*sym); + + if (!(fout = mdso_create_object(dctx,objname))) + return MDSO_NESTED_ERROR(dctx); + + ret = mdso_objgen_symentry(dctx,*sym,fout,0); + fclose(fout); + + if (ret < 0) + return MDSO_NESTED_ERROR(dctx); + + mdso_init_objname(objname,".%s_symfn.o",*sym); + + if (!(fout = mdso_create_object(dctx,objname))) + return MDSO_NESTED_ERROR(dctx); + + ret = mdso_objgen_symfn(dctx,*sym,fout,0); + fclose(fout); + + if (ret < 0) + return MDSO_NESTED_ERROR(dctx); + } + + mdso_free_unit_ctx(uctx); + } + + return 0; +} |