From 63cd760776dd9cfc14525acfe7f1af02e9aa2fb8 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 13 Feb 2017 00:50:48 -0500 Subject: unit context: added symbol characteristics and DATA support. --- include/mdso/mdso.h | 5 +++++ src/driver/mdso_unit_ctx.c | 24 ++++++++++++++++++++++-- src/internal/mdso_driver_impl.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/mdso/mdso.h b/include/mdso/mdso.h index 62ec354..8c76720 100644 --- a/include/mdso/mdso.h +++ b/include/mdso/mdso.h @@ -40,6 +40,10 @@ extern "C" { #define MDSO_DRIVER_ANNOTATE_NEVER 0x2000 #define MDSO_DRIVER_ANNOTATE_FULL 0x4000 +/* symbol characteristics */ +#define MDSO_SYMBOL_TYPE_CODE 0x0001 +#define MDSO_SYMBOL_TYPE_DATA 0x0002 + /* error flags */ #define MDSO_ERROR_TOP_LEVEL 0x0001 #define MDSO_ERROR_NESTED 0x0002 @@ -120,6 +124,7 @@ struct mdso_unit_ctx { const struct mdso_input * map; const struct mdso_common_ctx * cctx; const char * const * syms; + const int const * stype; void * any; }; diff --git a/src/driver/mdso_unit_ctx.c b/src/driver/mdso_unit_ctx.c index 4d068bf..01ef303 100644 --- a/src/driver/mdso_unit_ctx.c +++ b/src/driver/mdso_unit_ctx.c @@ -22,6 +22,9 @@ static int mdso_free_unit_ctx_impl(struct mdso_unit_ctx_impl * ctx, int status) if (ctx->expsyms && ctx->expsyms->buffer) free(ctx->expsyms->buffer); + if (ctx->expsyms && ctx->expsyms->stype) + free(ctx->expsyms->stype); + if (ctx->expsyms) free(ctx->expsyms); @@ -90,8 +93,10 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) size_t nbytes; size_t size; char * dst; + const char * base; const char * ch; const char ** sym; + int stype; const char exphdr[] = "EXPORTS\n"; const char imphdr[] = "IMPORTS\n"; @@ -103,7 +108,7 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) nsyms += (*ch == '\n'); size = offsetof(struct mdso_unit_ctx_impl,expsyms); - size += (nsyms+1)*sizeof(const char *); + size += (++nsyms)*sizeof(const char *); if (!(ctx->expsyms = calloc(1,size))) return -1; @@ -111,6 +116,10 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) if (!(ctx->expsyms->buffer = calloc(1,ctx->map.size))) return -1; + if (!(ctx->expsyms->stype = calloc(nsyms,sizeof(int)))) + return -1; + + base = ctx->map.addr; ch = ctx->map.addr; nbytes = ctx->map.size; sym = ctx->expsyms->syms; @@ -135,7 +144,7 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) while (nbytes && ((nbytes < size) || (strncmp(ch,imphdr,size)))) { /* vector */ - *sym++ = dst; + *sym = dst; /* symbol */ for (; nbytes && ((*ch!=' ') @@ -150,6 +159,16 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) for (; nbytes && (*ch!='\n'); nbytes--) ch++; + /* stype */ + stype = ((*ch=='\n') + && ((ch-base) >= 6) + && !strncmp(&ch[-5]," DATA\n",6)) + ? MDSO_SYMBOL_TYPE_DATA + : MDSO_SYMBOL_TYPE_CODE; + + ctx->expsyms->stype[sym - ctx->expsyms->syms] = stype; + sym++; + /* advance to next symbol */ for (; nbytes && ((*ch==' ') || (*ch=='\t') @@ -213,6 +232,7 @@ int mdso_get_unit_ctx( ctx->uctx.map = &ctx->map; ctx->uctx.cctx = &ctx->cctx; ctx->uctx.syms = ctx->expsyms->syms; + ctx->uctx.stype = ctx->expsyms->stype; *pctx = &ctx->uctx; return 0; diff --git a/src/internal/mdso_driver_impl.h b/src/internal/mdso_driver_impl.h index 6b092dc..dc658af 100644 --- a/src/internal/mdso_driver_impl.h +++ b/src/internal/mdso_driver_impl.h @@ -28,6 +28,7 @@ enum app_tags { struct mdso_expsyms { char * buffer; + int * stype; const char * syms[]; }; -- cgit v1.2.3