Blame src/logic/mdso_asmgen_dsometa.c

f45584
/****************************************************************/
f45584
/*  mdso: midipix dso scavenger                                 */
78ab3c
/*  Copyright (C) 2015--2017  Z. Gilboa                         */
f45584
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
f45584
/****************************************************************/
f45584
f45584
#include <stdint.h>
f45584
#include <stdio.h>
6e477a
f45584
#include <mdso/mdso.h>
f45584
#include <mdso/mdso_specs.h>
6e477a
#include "mdso_errinfo_impl.h"
f45584
f45584
static const char * const asm_hdr_lines[] = {
22e75c
	"\t.file     \".dsometa_%s.s\"\n",
f45584
f45584
	"\t.section  " MDSO_META_SECTION ",\"r\"\n",
ea45e3
	"\t.globl    .dsometa_%s\n",
f45584
	0
f45584
};
f45584
f45584
static const char * const asm_meta_lines[] = {
f45584
	"\t.long\t0	# priority\n",
f45584
	"\t.long\t0	# nsyms\n",
f45584
	"\t.long\t0	# padding\n",
f45584
	"\t%s\t0	# hashtbl\n",
f45584
	"\t%s\t0	# symtbl\n",
f45584
	"\t%s\t0	# fncarg\n",
f45584
	"\t%s\t0	# fncargarr\n",
f45584
	"\t%s\t0	# fnr1\n",
f45584
	"\t%s\t0	# fnr2\n",
f45584
	0
f45584
};
f45584
99263f
static const char * const asm_libname_fmt =
99263f
	"\n\n"
6d5860
	"\t.section  " MDSO_STRS_SECTION ",\"r0\"\n\n"
ea45e3
	".name:\n"
99263f
	"\t.ascii\t\"%s\\0\"\n\n";
99263f
2c190d
int mdso_asmgen_dsometa(
6e477a
	const struct mdso_driver_ctx *	dctx,
f45584
	FILE *				fout)
f45584
{
f45584
	const char * const *	line;
f45584
	const char *		alignstr;
f45584
	const char *		ptrsize;
f45584
6e477a
	if (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) {
f45584
		alignstr = "\t.balign   16\n\n";
f45584
		ptrsize  = ".quad";
f45584
	} else {
f45584
		alignstr = "\t.balign   8\n\n";
f45584
		ptrsize  = ".long";
f45584
	}
f45584
f45584
	for (line=asm_hdr_lines; *line; line++)
6e477a
		if ((fprintf(fout,*line,dctx->cctx->libname)) < 0)
6e477a
			return MDSO_FILE_ERROR(dctx);
f45584
f45584
	if ((fputs(alignstr,fout)) < 0)
6e477a
		return MDSO_FILE_ERROR(dctx);
f45584
ea45e3
	if ((fprintf(fout,".dsometa_%s:\n",dctx->cctx->libname)) < 0)
643252
		return MDSO_FILE_ERROR(dctx);
643252
f45584
	if ((fprintf(fout,"\t%s\t%d\t# base\n",ptrsize,0)) < 0)
6e477a
		return MDSO_FILE_ERROR(dctx);
f45584
ea45e3
	if ((fprintf(fout,"\t%s\t%s\t# name\n",ptrsize,".name")) < 0)
99263f
		return MDSO_FILE_ERROR(dctx);
99263f
6e477a
	if ((fprintf(fout,"\t%s\t%u\t# flags\n",".long",dctx->cctx->dsoflags)) < 0)
6e477a
		return MDSO_FILE_ERROR(dctx);
f45584
f45584
	for (line=asm_meta_lines; *line; line++)
f45584
		if ((fprintf(fout,*line,ptrsize)) < 0)
6e477a
			return MDSO_FILE_ERROR(dctx);
f45584
99263f
	if (fprintf(fout,asm_libname_fmt,dctx->cctx->libname) < 0)
99263f
		return MDSO_FILE_ERROR(dctx);
99263f
f45584
	return 0;
f45584
}