|
|
81f462 |
/****************************************************************/
|
|
|
81f462 |
/* mdso: midipix dso scavenger */
|
|
|
473806 |
/* Copyright (C) 2015--2024 SysDeer Technologies, LLC */
|
|
|
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>
|
|
|
18a091 |
#include "mdso_driver_impl.h"
|
|
|
932769 |
#include "mdso_hexfmt_impl.h"
|
|
|
27f67f |
#include "mdso_errinfo_impl.h"
|
|
|
81f462 |
|
|
|
932769 |
static void mdso_init_symentry(char * ch, const char * str)
|
|
|
81f462 |
{
|
|
|
932769 |
uint64_t crc64;
|
|
|
932769 |
unsigned slen = 11;
|
|
|
932769 |
|
|
|
932769 |
ch[0] = '.';
|
|
|
932769 |
ch++;
|
|
|
932769 |
|
|
|
932769 |
if (strlen(str) > (PATH_MAX - slen - 1)) {
|
|
|
932769 |
crc64 = mdso_crc64_mbstr((unsigned char *)str,0);
|
|
|
932769 |
mdso_write_hex_64(ch,crc64);
|
|
|
932769 |
ch = &ch[16];
|
|
|
932769 |
} else {
|
|
|
932769 |
for (; *str; )
|
|
|
932769 |
*ch++ = *str++;
|
|
|
932769 |
}
|
|
|
932769 |
|
|
|
932769 |
memcpy(ch,"_symentry.s",slen);
|
|
|
932769 |
ch[slen] = '\0';
|
|
|
81f462 |
}
|
|
|
81f462 |
|
|
|
932769 |
static void mdso_init_dsometa(char * ch, const char * str)
|
|
|
932769 |
{
|
|
|
932769 |
uint64_t crc64;
|
|
|
932769 |
unsigned slen = 9;
|
|
|
932769 |
|
|
|
932769 |
memcpy(ch,".dsometa_",slen);
|
|
|
932769 |
ch = &ch[slen];
|
|
|
932769 |
|
|
|
932769 |
if (strlen(str) > (PATH_MAX - slen - 1)) {
|
|
|
932769 |
crc64 = mdso_crc64_mbstr((unsigned char *)str,0);
|
|
|
932769 |
mdso_write_hex_64(ch,crc64);
|
|
|
932769 |
ch = &ch[16];
|
|
|
932769 |
} else {
|
|
|
932769 |
for (; *str; )
|
|
|
932769 |
*ch++ = *str++;
|
|
|
932769 |
}
|
|
|
932769 |
|
|
|
932769 |
ch[0] = '.';
|
|
|
932769 |
ch[1] = 's';
|
|
|
932769 |
ch[2] = '\0';
|
|
|
932769 |
}
|
|
|
18a091 |
int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx)
|
|
|
81f462 |
{
|
|
|
81f462 |
struct mdso_unit_ctx * uctx;
|
|
|
81f462 |
const char ** unit;
|
|
|
18a091 |
int fdout;
|
|
|
81f462 |
char asmname[PATH_MAX];
|
|
|
81f462 |
const char * const * sym;
|
|
|
81f462 |
int ret;
|
|
|
81f462 |
|
|
|
81f462 |
|
|
|
8535b6 |
/* symentry */
|
|
|
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++) {
|
|
|
932769 |
mdso_init_symentry(asmname,*sym);
|
|
|
81f462 |
|
|
|
18a091 |
if ((fdout = mdso_create_asmsrc(dctx,asmname)) < 0)
|
|
|
27f67f |
return MDSO_NESTED_ERROR(dctx);
|
|
|
81f462 |
|
|
|
18a091 |
ret = mdso_asmgen_symentry(dctx,*sym,fdout);
|
|
|
81f462 |
|
|
|
18a091 |
if (fdout != mdso_driver_fdout(dctx))
|
|
|
18a091 |
close(fdout);
|
|
|
81f462 |
|
|
|
81f462 |
if (ret < 0)
|
|
|
27f67f |
return MDSO_NESTED_ERROR(dctx);
|
|
|
81f462 |
}
|
|
|
81f462 |
|
|
|
81f462 |
mdso_free_unit_ctx(uctx);
|
|
|
81f462 |
}
|
|
|
81f462 |
|
|
|
4cffdc |
/* dsometa */
|
|
|
932769 |
mdso_init_dsometa(asmname,dctx->cctx->libname);
|
|
|
4cffdc |
|
|
|
18a091 |
if ((fdout = mdso_create_asmsrc(dctx,asmname)) < 0)
|
|
|
4cffdc |
return MDSO_NESTED_ERROR(dctx);
|
|
|
4cffdc |
|
|
|
18a091 |
ret = mdso_asmgen_dsometa(dctx,fdout);
|
|
|
4cffdc |
|
|
|
18a091 |
if (fdout != mdso_driver_fdout(dctx))
|
|
|
18a091 |
close(fdout);
|
|
|
4cffdc |
|
|
|
4cffdc |
return (ret < 0) ? MDSO_NESTED_ERROR(dctx) : 0;
|
|
|
81f462 |
}
|