Blame src/util/mdso_create_implib_objects.c

3e55ee
/****************************************************************/
3e55ee
/*  mdso: midipix dso scavenger                                 */
473806
/*  Copyright (C) 2015--2024  SysDeer Technologies, LLC         */
3e55ee
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
3e55ee
/****************************************************************/
3e55ee
3e55ee
#include <stdint.h>
3e55ee
#include <stdio.h>
3e55ee
#include <string.h>
3e55ee
3e55ee
#include <mdso/mdso.h>
3f97b6
#include "mdso_hexfmt_impl.h"
3e55ee
#include "mdso_errinfo_impl.h"
3e55ee
3f97b6
static void mdso_init_symentry(char * ch, const char * str)
3e55ee
{
3f97b6
	uint64_t crc64;
3f97b6
	unsigned slen = 11;
3f97b6
3f97b6
	ch[0] = '.';
3f97b6
	ch++;
3f97b6
3f97b6
	if (strlen(str) > (PATH_MAX - slen - 1)) {
3f97b6
		crc64 = mdso_crc64_mbstr((unsigned char *)str,0);
3f97b6
		mdso_write_hex_64(ch,crc64);
3f97b6
		ch = &ch[16];
3f97b6
	} else {
3f97b6
		for (; *str; )
3f97b6
			*ch++ = *str++;
3f97b6
	}
3f97b6
3f97b6
	memcpy(ch,"_symentry.o",slen);
3f97b6
	ch[slen] = '\0';
3f97b6
}
3f97b6
3f97b6
static void mdso_init_dsometa(char * ch, const char * str)
3f97b6
{
3f97b6
	uint64_t crc64;
3f97b6
	unsigned slen = 9;
3f97b6
3f97b6
	memcpy(ch,".dsometa_",slen);
3f97b6
	ch = &ch[slen];
3f97b6
3f97b6
	if (strlen(str) > (PATH_MAX - slen - 1)) {
3f97b6
		crc64 = mdso_crc64_mbstr((unsigned char *)str,0);
3f97b6
		mdso_write_hex_64(ch,crc64);
3f97b6
		ch = &ch[16];
3f97b6
	} else {
3f97b6
		for (; *str; )
3f97b6
			*ch++ = *str++;
3f97b6
	}
3f97b6
3f97b6
	ch[0] = '.';
3f97b6
	ch[1] = 'o';
3f97b6
	ch[2] = '\0';
3e55ee
}
3e55ee
a3e2cf
static void mdso_init_object(struct mdso_object * obj, const char * objname)
a3e2cf
{
a3e2cf
	memset(obj,0,sizeof(*obj));
a3e2cf
	obj->name = objname;
a3e2cf
}
a3e2cf
a3e2cf
int  mdso_create_implib_objects(const struct mdso_driver_ctx * dctx)
3e55ee
{
3e55ee
	const char **		unit;
a3e2cf
	struct mdso_unit_ctx *	uctx;
a3e2cf
	struct mdso_object	obj;
3e55ee
	const char * const *	sym;
a3e2cf
	char			objname[PATH_MAX];
3e55ee
8535b6
	/* symentry */
3e55ee
	for (unit=dctx->units; *unit; unit++) {
3e55ee
		if (mdso_get_unit_ctx(dctx,*unit,&uctx))
3e55ee
			return MDSO_NESTED_ERROR(dctx);
3e55ee
3e55ee
		for (sym=uctx->syms; *sym; sym++) {
3f97b6
			mdso_init_symentry(objname,*sym);
a3e2cf
			mdso_init_object(&obj,objname);
3e55ee
a3e2cf
			if (mdso_objgen_symentry(dctx,*sym,&obj) < 0)
3e55ee
				return MDSO_NESTED_ERROR(dctx);
3e55ee
		}
3e55ee
3e55ee
		mdso_free_unit_ctx(uctx);
3e55ee
	}
3e55ee
1c23fb
	/* dsometa */
3f97b6
	mdso_init_dsometa(objname,dctx->cctx->libname);
a3e2cf
	mdso_init_object(&obj,objname);
1c23fb
a3e2cf
	if (mdso_objgen_dsometa(dctx,&obj) < 0)
1c23fb
		return MDSO_NESTED_ERROR(dctx);
1c23fb
a3e2cf
	return 0;
3e55ee
}