|
|
81f462 |
/****************************************************************/
|
|
|
81f462 |
/* mdso: midipix dso scavenger */
|
|
|
81f462 |
/* Copyright (C) 2015 Z. Gilboa */
|
|
|
81f462 |
/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
|
|
|
81f462 |
/****************************************************************/
|
|
|
81f462 |
|
|
|
81f462 |
#include <stdint.h>
|
|
|
81f462 |
#include <stdio.h>
|
|
|
81f462 |
#include <string.h>
|
|
|
81f462 |
#include <mdso/mdso.h>
|
|
|
81f462 |
|
|
|
81f462 |
static void mdso_init_asmname(char * buf, const char * fmt, const char * str)
|
|
|
81f462 |
{
|
|
|
81f462 |
char hexstr[24];
|
|
|
81f462 |
long long unsigned int crc64;
|
|
|
81f462 |
|
|
|
81f462 |
if (strlen(str) + strlen(fmt) > (PATH_MAX - 1)) {
|
|
|
81f462 |
crc64 = mdso_crc64_mbstr((const unsigned char *)str,0);
|
|
|
81f462 |
sprintf(hexstr,"%llx",crc64);
|
|
|
81f462 |
sprintf(buf,fmt,hexstr);
|
|
|
81f462 |
} else
|
|
|
81f462 |
sprintf(buf,fmt,str);
|
|
|
81f462 |
}
|
|
|
81f462 |
|
|
|
81f462 |
mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx)
|
|
|
81f462 |
{
|
|
|
81f462 |
struct mdso_unit_ctx * uctx;
|
|
|
81f462 |
const char ** unit;
|
|
|
81f462 |
FILE * fout;
|
|
|
81f462 |
char asmname[PATH_MAX];
|
|
|
81f462 |
const char * const * sym;
|
|
|
81f462 |
int ret;
|
|
|
81f462 |
|
|
|
81f462 |
mdso_init_asmname(asmname,"__%s_dso_meta.s",dctx->cctx->libname);
|
|
|
81f462 |
|
|
|
81f462 |
if (!(fout = mdso_create_output(dctx,asmname)))
|
|
|
81f462 |
return -1;
|
|
|
81f462 |
|
|
|
81f462 |
ret = mdso_generate_dsometa(dctx->cctx,fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (fout != stdout)
|
|
|
81f462 |
fclose(fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (ret < 0)
|
|
|
81f462 |
return -1;
|
|
|
81f462 |
|
|
|
81f462 |
for (unit=dctx->units; *unit; unit++) {
|
|
|
81f462 |
if (mdso_get_unit_ctx(dctx,*unit,&uctx))
|
|
|
81f462 |
return -1;
|
|
|
81f462 |
|
|
|
81f462 |
for (sym=uctx->syms; *sym; sym++) {
|
|
|
81f462 |
mdso_init_asmname(asmname,"__%s_sym_entry.s",*sym);
|
|
|
81f462 |
|
|
|
81f462 |
if (!(fout = mdso_create_output(dctx,asmname)))
|
|
|
81f462 |
return -1;
|
|
|
81f462 |
|
|
|
81f462 |
ret = mdso_generate_symentry(dctx->cctx,*sym,fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (fout != stdout)
|
|
|
81f462 |
fclose(fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (ret < 0)
|
|
|
81f462 |
return -1;
|
|
|
81f462 |
|
|
|
81f462 |
mdso_init_asmname(asmname,"__%s_sym_fn.s",*sym);
|
|
|
81f462 |
|
|
|
81f462 |
if (!(fout = mdso_create_output(dctx,asmname)))
|
|
|
81f462 |
return -1;
|
|
|
81f462 |
|
|
|
81f462 |
ret = mdso_generate_symfn(*sym,fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (fout != stdout)
|
|
|
81f462 |
fclose(fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (ret < 0)
|
|
|
81f462 |
return -1;
|
|
|
81f462 |
}
|
|
|
81f462 |
|
|
|
81f462 |
mdso_free_unit_ctx(uctx);
|
|
|
81f462 |
}
|
|
|
81f462 |
|
|
|
81f462 |
return 0;
|
|
|
81f462 |
}
|