summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-08-03 23:16:42 +0000
committermidipix <writeonce@midipix.org>2018-08-03 21:13:31 -0400
commit2f4c03923b250a3bbf96188ceb91979841a95e91 (patch)
tree0b0a3fe3c47081345b72e9d7caa25b834c1cfbe9 /src
parent1c93c26f73c2e8746defed21d22d83d08ac16eaf (diff)
downloadmdso-2f4c03923b250a3bbf96188ceb91979841a95e91.tar.bz2
mdso-2f4c03923b250a3bbf96188ceb91979841a95e91.tar.xz
library interfaces: archive generation: simplify, re-implement with mmap.
Diffstat (limited to 'src')
-rw-r--r--src/archive/mdso_argen_common.c46
-rw-r--r--src/helper/mdso_create_output.c33
-rw-r--r--src/util/mdso_create_implib_archive.c27
3 files changed, 41 insertions, 65 deletions
diff --git a/src/archive/mdso_argen_common.c b/src/archive/mdso_argen_common.c
index 62cca47..9cd80d6 100644
--- a/src/archive/mdso_argen_common.c
+++ b/src/archive/mdso_argen_common.c
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/mman.h>
#include <mdso/mdso.h>
#include "mdso_errinfo_impl.h"
@@ -50,7 +51,6 @@ int mdso_argen_common(
const struct mdso_driver_ctx * dctx,
const char ** symv,
const int * stype,
- FILE * fout,
struct mdso_object * vobj)
{
int ret;
@@ -63,6 +63,7 @@ int mdso_argen_common(
uint32_t mapstrsnum;
uint32_t mapstrslen;
uint32_t symidx;
+ void * addr;
unsigned char * ar;
unsigned char * mark;
unsigned char * idx;
@@ -154,26 +155,26 @@ int mdso_argen_common(
objlen |= 15;
objlen ^= 15;
- if (vobj && vobj->addr && (vobj->size < objlen))
+ if (vobj->addr && (vobj->size < objlen))
return MDSO_BUFFER_ERROR(dctx);
- if (vobj && !vobj->addr) {
- vobj->size = objlen;
+ if ((addr = vobj->addr)) {
+ (void)0;
+
+ } else {
+ vobj->size = objlen;
vobj->mapstrslen = mapstrslen;
vobj->mapstrsnum = mapstrsnum;
- return 0;
- }
-
- if (vobj)
- ar = (unsigned char *)vobj->addr;
- else if (!(ar = calloc(1,objlen))) {
- if (aobj != sobj)
- free(aobj);
+ if (!vobj->name)
+ return 0;
- return MDSO_SYSTEM_ERROR(dctx);
+ else if (mdso_create_archive(dctx,vobj) < 0)
+ return MDSO_NESTED_ERROR(dctx);
}
+ ar = (unsigned char *)vobj->addr;
+
/* archive signature */
memcpy(ar,"!<arch>\n",8);
mark = &ar[8];
@@ -274,23 +275,18 @@ int mdso_argen_common(
if (aobj != sobj)
free(aobj);
- if (!vobj)
- free(ar);
-
return ret;
}
- /* tada */
- if (fout)
- ret = fwrite(ar,objlen,1,fout);
-
+ /* aobj */
if (aobj != sobj)
free(aobj);
- if (!vobj)
- free(ar);
+ /* fs object unmap */
+ if (!addr)
+ munmap(vobj->addr,vobj->size);
+
+ /* tada */
+ return 0;
- return (ret == 0)
- ? MDSO_FILE_ERROR(dctx)
- : 0;
}
diff --git a/src/helper/mdso_create_output.c b/src/helper/mdso_create_output.c
index 3b9fe5d..d508cc3 100644
--- a/src/helper/mdso_create_output.c
+++ b/src/helper/mdso_create_output.c
@@ -60,25 +60,6 @@ static int mdso_map_output(
return 0;
}
-static FILE * mdso_create_output_stream(
- const struct mdso_driver_ctx * dctx,
- const char * name)
-{
- int fdout;
- FILE * fout;
-
- if ((fdout = mdso_create_output(dctx,name)) < 0)
- return 0;
-
- if (!(fout = fdopen(fdout,"w"))) {
- close(fdout);
- MDSO_SYSTEM_ERROR(dctx);
- return 0;
- }
-
- return fout;
-}
-
static int mdso_create_mapped_output(
const struct mdso_driver_ctx * dctx,
struct mdso_object * obj)
@@ -94,13 +75,6 @@ static int mdso_create_mapped_output(
return 0;
}
-FILE * mdso_create_archive(
- const struct mdso_driver_ctx * dctx,
- const char * arname)
-{
- return mdso_create_output_stream(dctx,arname);
-}
-
int mdso_create_asmsrc(
const struct mdso_driver_ctx * dctx,
const char * asmname)
@@ -121,3 +95,10 @@ int mdso_create_object(
{
return mdso_create_mapped_output(dctx,obj);
}
+
+int mdso_create_archive(
+ const struct mdso_driver_ctx * dctx,
+ struct mdso_object * obj)
+{
+ return mdso_create_mapped_output(dctx,obj);
+}
diff --git a/src/util/mdso_create_implib_archive.c b/src/util/mdso_create_implib_archive.c
index e5e5d01..11373b4 100644
--- a/src/util/mdso_create_implib_archive.c
+++ b/src/util/mdso_create_implib_archive.c
@@ -15,8 +15,7 @@
static void mdso_free_uctx_vector(
struct mdso_unit_ctx ** uctxv,
const char ** symv,
- int * stype,
- FILE * fout)
+ int * stype)
{
struct mdso_unit_ctx ** puctx;
@@ -30,16 +29,14 @@ static void mdso_free_uctx_vector(
mdso_free_unit_ctx(*puctx);
free(uctxv);
- fclose(fout);
}
int mdso_create_implib_archive(const struct mdso_driver_ctx * dctx)
{
- int ret;
- FILE * fout;
size_t nsym;
struct mdso_unit_ctx ** uctxv;
struct mdso_unit_ctx ** puctx;
+ struct mdso_object obj;
const char * const * dsym;
const char ** unit;
const char ** psym;
@@ -55,12 +52,9 @@ int mdso_create_implib_archive(const struct mdso_driver_ctx * dctx)
if (!(uctxv = calloc(++unit - dctx->units,sizeof(*uctxv))))
return MDSO_SYSTEM_ERROR(dctx);
- if (!(fout = mdso_create_archive(dctx,dctx->cctx->implib)))
- return MDSO_NESTED_ERROR(dctx);
-
for (puctx=uctxv,unit=dctx->units; *unit; unit++) {
if (mdso_get_unit_ctx(dctx,*unit,puctx++)) {
- mdso_free_uctx_vector(uctxv,0,0,fout);
+ mdso_free_uctx_vector(uctxv,0,0);
return MDSO_NESTED_ERROR(dctx);
}
}
@@ -70,12 +64,12 @@ int mdso_create_implib_archive(const struct mdso_driver_ctx * dctx)
nsym++;
if (!(symv = calloc(nsym+1,sizeof(const char *)))) {
- mdso_free_uctx_vector(uctxv,0,0,fout);
+ mdso_free_uctx_vector(uctxv,0,0);
return MDSO_SYSTEM_ERROR(dctx);
}
if (!(stype = calloc(nsym+1,sizeof(int)))) {
- mdso_free_uctx_vector(uctxv,symv,0,fout);
+ mdso_free_uctx_vector(uctxv,symv,0);
return MDSO_SYSTEM_ERROR(dctx);
}
@@ -86,8 +80,13 @@ int mdso_create_implib_archive(const struct mdso_driver_ctx * dctx)
}
}
- ret = mdso_argen_common(dctx,symv,stype,fout,0);
- mdso_free_uctx_vector(uctxv,symv,stype,fout);
+ memset(&obj,0,sizeof(obj));
+ obj.name = dctx->cctx->implib;
+
+ if (mdso_argen_common(dctx,symv,stype,&obj) < 0) {
+ mdso_free_uctx_vector(uctxv,symv,stype);
+ return MDSO_NESTED_ERROR(dctx);
+ }
- return ret ? MDSO_NESTED_ERROR(dctx) : 0;
+ return 0;
}