summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-08-03 07:53:34 +0000
committermidipix <writeonce@midipix.org>2018-08-03 21:13:30 -0400
commit18a091990a2de49fb0c9d85b0ae8e86825f2104f (patch)
treebd01adba7687618857a1866790c3ed4f9346f319 /src
parent3d38ce6b746e9d6f4e0b7dc251d88dba78fb0a47 (diff)
downloadmdso-18a091990a2de49fb0c9d85b0ae8e86825f2104f.tar.bz2
mdso-18a091990a2de49fb0c9d85b0ae8e86825f2104f.tar.xz
library interfaces: asm source generation: re-implement w. pure fdio and fdctx.
Diffstat (limited to 'src')
-rw-r--r--src/helper/mdso_create_output.c6
-rw-r--r--src/logic/mdso_asmgen_dsometa.c19
-rw-r--r--src/logic/mdso_asmgen_symentry.c17
-rw-r--r--src/logic/mdso_asmgen_symfn.c7
-rw-r--r--src/util/mdso_create_implib_sources.c29
5 files changed, 41 insertions, 37 deletions
diff --git a/src/helper/mdso_create_output.c b/src/helper/mdso_create_output.c
index f94524b..24ed757 100644
--- a/src/helper/mdso_create_output.c
+++ b/src/helper/mdso_create_output.c
@@ -58,13 +58,13 @@ FILE * mdso_create_archive(
return mdso_create_output_stream(dctx,arname);
}
-FILE * mdso_create_asmsrc(
+int mdso_create_asmsrc(
const struct mdso_driver_ctx * dctx,
const char * asmname)
{
return dctx->cctx->dstdir
- ? mdso_create_output_stream(dctx,asmname)
- : stdout;
+ ? mdso_create_output(dctx,asmname)
+ : mdso_driver_fdout(dctx);
}
FILE * mdso_create_object(
diff --git a/src/logic/mdso_asmgen_dsometa.c b/src/logic/mdso_asmgen_dsometa.c
index 4643e98..7c0b5ba 100644
--- a/src/logic/mdso_asmgen_dsometa.c
+++ b/src/logic/mdso_asmgen_dsometa.c
@@ -9,6 +9,7 @@
#include <mdso/mdso.h>
#include <mdso/mdso_specs.h>
+#include "mdso_dprintf_impl.h"
#include "mdso_errinfo_impl.h"
static const char * const asm_hdr_lines[] = {
@@ -40,7 +41,7 @@ static const char * const asm_libname_fmt =
int mdso_asmgen_dsometa(
const struct mdso_driver_ctx * dctx,
- FILE * fout)
+ int fdout)
{
const char * const * line;
const char * alignstr;
@@ -55,29 +56,29 @@ int mdso_asmgen_dsometa(
}
for (line=asm_hdr_lines; *line; line++)
- if ((fprintf(fout,*line,dctx->cctx->libname)) < 0)
+ if ((mdso_dprintf(fdout,*line,dctx->cctx->libname)) < 0)
return MDSO_FILE_ERROR(dctx);
- if ((fputs(alignstr,fout)) < 0)
+ if (mdso_dprintf(fdout,alignstr) < 0)
return MDSO_FILE_ERROR(dctx);
- if ((fprintf(fout,".dsometa_%s:\n",dctx->cctx->libname)) < 0)
+ if ((mdso_dprintf(fdout,".dsometa_%s:\n",dctx->cctx->libname)) < 0)
return MDSO_FILE_ERROR(dctx);
- if ((fprintf(fout,"\t%s\t%d\t\t# base\n",ptrsize,0)) < 0)
+ if ((mdso_dprintf(fdout,"\t%s\t%d\t\t# base\n",ptrsize,0)) < 0)
return MDSO_FILE_ERROR(dctx);
- if ((fprintf(fout,"\t%s\t%s\t# name\n",ptrsize,".libname")) < 0)
+ if ((mdso_dprintf(fdout,"\t%s\t%s\t# name\n",ptrsize,".libname")) < 0)
return MDSO_FILE_ERROR(dctx);
- if ((fprintf(fout,"\t%s\t%u\t\t# flags\n",".long",dctx->cctx->dsoflags)) < 0)
+ if ((mdso_dprintf(fdout,"\t%s\t%u\t\t# flags\n",".long",dctx->cctx->dsoflags)) < 0)
return MDSO_FILE_ERROR(dctx);
for (line=asm_meta_lines; *line; line++)
- if ((fprintf(fout,*line,ptrsize)) < 0)
+ if ((mdso_dprintf(fdout,*line,ptrsize)) < 0)
return MDSO_FILE_ERROR(dctx);
- if (fprintf(fout,asm_libname_fmt,dctx->cctx->libname) < 0)
+ if (mdso_dprintf(fdout,asm_libname_fmt,dctx->cctx->libname) < 0)
return MDSO_FILE_ERROR(dctx);
return 0;
diff --git a/src/logic/mdso_asmgen_symentry.c b/src/logic/mdso_asmgen_symentry.c
index 2b1541f..67ea686 100644
--- a/src/logic/mdso_asmgen_symentry.c
+++ b/src/logic/mdso_asmgen_symentry.c
@@ -9,6 +9,7 @@
#include <mdso/mdso.h>
#include <mdso/mdso_specs.h>
+#include "mdso_dprintf_impl.h"
#include "mdso_errinfo_impl.h"
static const char * const asm_lines[] = {
@@ -22,14 +23,14 @@ static const char * const asm_lines[] = {
int mdso_asmgen_symentry(
const struct mdso_driver_ctx * dctx,
const char * sym,
- FILE * fout)
+ int fdout)
{
const char * const * line;
const char * alignstr;
const char * ptrsize;
const char * uscore;
- if (fprintf(fout,"\t.file \".%s_symentry.s\"\n",sym) < 0)
+ if (mdso_dprintf(fdout,"\t.file \".%s_symentry.s\"\n",sym) < 0)
return MDSO_FILE_ERROR(dctx);
if (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) {
@@ -43,22 +44,22 @@ int mdso_asmgen_symentry(
}
for (line=asm_lines; *line; line++)
- if ((fprintf(fout,*line,sym)) < 0)
+ if ((mdso_dprintf(fdout,*line,sym)) < 0)
return MDSO_FILE_ERROR(dctx);
- if (fprintf(fout,"\t.globl __imp_%s%s\n",uscore,sym) < 0)
+ if (mdso_dprintf(fdout,"\t.globl __imp_%s%s\n",uscore,sym) < 0)
return MDSO_FILE_ERROR(dctx);
- if ((fputs(alignstr,fout)) < 0)
+ if (mdso_dprintf(fdout,alignstr) < 0)
return MDSO_FILE_ERROR(dctx);
- if ((fprintf(fout,"__imp_%s%s:\n",uscore,sym)) < 0)
+ if ((mdso_dprintf(fdout,"__imp_%s%s:\n",uscore,sym)) < 0)
return MDSO_FILE_ERROR(dctx);
- if ((fprintf(fout,"\t%s\t.symstr\n",ptrsize)) < 0)
+ if ((mdso_dprintf(fdout,"\t%s\t.symstr\n",ptrsize)) < 0)
return MDSO_FILE_ERROR(dctx);
- if ((fprintf(fout,"\t%s\t.dsometa_%s\n",ptrsize,dctx->cctx->libname)) < 0)
+ if ((mdso_dprintf(fdout,"\t%s\t.dsometa_%s\n",ptrsize,dctx->cctx->libname)) < 0)
return MDSO_FILE_ERROR(dctx);
return 0;
diff --git a/src/logic/mdso_asmgen_symfn.c b/src/logic/mdso_asmgen_symfn.c
index e9484af..e63ec5d 100644
--- a/src/logic/mdso_asmgen_symfn.c
+++ b/src/logic/mdso_asmgen_symfn.c
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <mdso/mdso.h>
+#include "mdso_dprintf_impl.h"
#include "mdso_errinfo_impl.h"
static const char * const asm_lines[] = {
@@ -23,19 +24,19 @@ static const char * const asm_lines[] = {
int mdso_asmgen_symfn(
const struct mdso_driver_ctx * dctx,
const char * sym,
- FILE * fout)
+ int fdout)
{
const char * const * line;
const char * uscore;
- if (fprintf(fout,"\t.file \".%s_symfn.s\"\n",sym) < 0)
+ if (mdso_dprintf(fdout,"\t.file \".%s_symfn.s\"\n",sym) < 0)
return MDSO_FILE_ERROR(dctx);
uscore = (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR)
? "" : "_";
for (line=asm_lines; *line; line++)
- if (fprintf(fout,*line,uscore,sym) < 0)
+ if (mdso_dprintf(fdout,*line,uscore,sym) < 0)
return MDSO_FILE_ERROR(dctx);
return 0;
diff --git a/src/util/mdso_create_implib_sources.c b/src/util/mdso_create_implib_sources.c
index 5c320eb..1ee647d 100644
--- a/src/util/mdso_create_implib_sources.c
+++ b/src/util/mdso_create_implib_sources.c
@@ -9,6 +9,7 @@
#include <string.h>
#include <mdso/mdso.h>
+#include "mdso_driver_impl.h"
#include "mdso_errinfo_impl.h"
static void mdso_init_asmname(char * buf, const char * fmt, const char * str)
@@ -24,11 +25,11 @@ static void mdso_init_asmname(char * buf, const char * fmt, const char * str)
sprintf(buf,fmt,str);
}
-mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx)
+int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx)
{
struct mdso_unit_ctx * uctx;
const char ** unit;
- FILE * fout;
+ int fdout;
char asmname[PATH_MAX];
const char * const * sym;
int ret;
@@ -42,13 +43,13 @@ mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx)
for (sym=uctx->syms; *sym; sym++) {
mdso_init_asmname(asmname,".%s_symentry.s",*sym);
- if (!(fout = mdso_create_asmsrc(dctx,asmname)))
+ if ((fdout = mdso_create_asmsrc(dctx,asmname)) < 0)
return MDSO_NESTED_ERROR(dctx);
- ret = mdso_asmgen_symentry(dctx,*sym,fout);
+ ret = mdso_asmgen_symentry(dctx,*sym,fdout);
- if (fout != stdout)
- fclose(fout);
+ if (fdout != mdso_driver_fdout(dctx))
+ close(fdout);
if (ret < 0)
return MDSO_NESTED_ERROR(dctx);
@@ -56,13 +57,13 @@ mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx)
if (uctx->stype[sym-uctx->syms] == MDSO_SYMBOL_TYPE_CODE) {
mdso_init_asmname(asmname,".%s_symfn.s",*sym);
- if (!(fout = mdso_create_asmsrc(dctx,asmname)))
+ if ((fdout = mdso_create_asmsrc(dctx,asmname)) < 0)
return MDSO_NESTED_ERROR(dctx);
- ret = mdso_asmgen_symfn(dctx,*sym,fout);
+ ret = mdso_asmgen_symfn(dctx,*sym,fdout);
- if (fout != stdout)
- fclose(fout);
+ if (fdout != mdso_driver_fdout(dctx))
+ close(fdout);
if (ret < 0)
return MDSO_NESTED_ERROR(dctx);
@@ -75,13 +76,13 @@ mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx)
/* dsometa */
mdso_init_asmname(asmname,".dsometa_%s.s",dctx->cctx->libname);
- if (!(fout = mdso_create_asmsrc(dctx,asmname)))
+ if ((fdout = mdso_create_asmsrc(dctx,asmname)) < 0)
return MDSO_NESTED_ERROR(dctx);
- ret = mdso_asmgen_dsometa(dctx,fout);
+ ret = mdso_asmgen_dsometa(dctx,fdout);
- if (fout != stdout)
- fclose(fout);
+ if (fdout != mdso_driver_fdout(dctx))
+ close(fdout);
return (ret < 0) ? MDSO_NESTED_ERROR(dctx) : 0;
}