|
|
81f462 |
/****************************************************************/
|
|
|
81f462 |
/* mdso: midipix dso scavenger */
|
|
|
3e816c |
/* Copyright (C) 2015--2016 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>
|
|
|
27f67f |
|
|
|
81f462 |
#include <mdso/mdso.h>
|
|
|
27f67f |
#include "mdso_errinfo_impl.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 |
|
|
|
b183d1 |
if (!(fout = mdso_create_asm_source(dctx,asmname)))
|
|
|
27f67f |
return MDSO_NESTED_ERROR(dctx);
|
|
|
81f462 |
|
|
|
6e477a |
ret = mdso_generate_dsometa(dctx,fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (fout != stdout)
|
|
|
81f462 |
fclose(fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (ret < 0)
|
|
|
27f67f |
return MDSO_NESTED_ERROR(dctx);
|
|
|
81f462 |
|
|
|
81f462 |
for (unit=dctx->units; *unit; unit++) {
|
|
|
81f462 |
if (mdso_get_unit_ctx(dctx,*unit,&uctx))
|
|
|
27f67f |
return MDSO_NESTED_ERROR(dctx);
|
|
|
81f462 |
|
|
|
81f462 |
for (sym=uctx->syms; *sym; sym++) {
|
|
|
81f462 |
mdso_init_asmname(asmname,"__%s_sym_entry.s",*sym);
|
|
|
81f462 |
|
|
|
b183d1 |
if (!(fout = mdso_create_asm_source(dctx,asmname)))
|
|
|
27f67f |
return MDSO_NESTED_ERROR(dctx);
|
|
|
81f462 |
|
|
|
7f20b2 |
ret = mdso_generate_symentry(dctx,*sym,fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (fout != stdout)
|
|
|
81f462 |
fclose(fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (ret < 0)
|
|
|
27f67f |
return MDSO_NESTED_ERROR(dctx);
|
|
|
81f462 |
|
|
|
81f462 |
mdso_init_asmname(asmname,"__%s_sym_fn.s",*sym);
|
|
|
81f462 |
|
|
|
b183d1 |
if (!(fout = mdso_create_asm_source(dctx,asmname)))
|
|
|
27f67f |
return MDSO_NESTED_ERROR(dctx);
|
|
|
81f462 |
|
|
|
62fec7 |
ret = mdso_generate_symfn(dctx,*sym,fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (fout != stdout)
|
|
|
81f462 |
fclose(fout);
|
|
|
81f462 |
|
|
|
81f462 |
if (ret < 0)
|
|
|
27f67f |
return MDSO_NESTED_ERROR(dctx);
|
|
|
81f462 |
}
|
|
|
81f462 |
|
|
|
81f462 |
mdso_free_unit_ctx(uctx);
|
|
|
81f462 |
}
|
|
|
81f462 |
|
|
|
81f462 |
return 0;
|
|
|
81f462 |
}
|