|
|
089c8b |
/*******************************************************************/
|
|
|
089c8b |
/* slibtool: a skinny libtool implementation, written in C */
|
|
|
bb281c |
/* Copyright (C) 2016--2021 SysDeer Technologies, LLC */
|
|
|
089c8b |
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
|
|
|
089c8b |
/*******************************************************************/
|
|
|
089c8b |
|
|
|
582d19 |
#ifndef SLIBTOOL_DRIVER_IMPL_H
|
|
|
582d19 |
#define SLIBTOOL_DRIVER_IMPL_H
|
|
|
9ca8c4 |
|
|
|
9ca8c4 |
#include <stdint.h>
|
|
|
9ca8c4 |
#include <stdio.h>
|
|
|
a126a7 |
#include <sys/stat.h>
|
|
|
9ca8c4 |
#include <sys/types.h>
|
|
|
9ca8c4 |
|
|
|
9ca8c4 |
#include <slibtool/slibtool.h>
|
|
|
608847 |
#include "slibtool_dprintf_impl.h"
|
|
|
9ca8c4 |
#include "argv/argv.h"
|
|
|
9ca8c4 |
|
|
|
5e0269 |
#define SLBT_OPTV_ELEMENTS 128
|
|
|
d58d2f |
|
|
|
9ca8c4 |
extern const struct argv_option slbt_default_options[];
|
|
|
9ca8c4 |
|
|
|
9ca8c4 |
enum app_tags {
|
|
|
9ca8c4 |
TAG_HELP,
|
|
|
efd47f |
TAG_HELP_ALL,
|
|
|
9ca8c4 |
TAG_VERSION,
|
|
|
efd47f |
TAG_CONFIG,
|
|
|
6f4115 |
TAG_DUMPMACHINE,
|
|
|
efd47f |
TAG_DEBUG,
|
|
|
efd47f |
TAG_DRY_RUN,
|
|
|
efd47f |
TAG_FEATURES,
|
|
|
0a9bff |
TAG_LEGABITS,
|
|
|
efd47f |
TAG_MODE,
|
|
|
b9575f |
TAG_FINISH,
|
|
|
efd47f |
TAG_WARNINGS,
|
|
|
2bc175 |
TAG_ANNOTATE,
|
|
|
efd47f |
TAG_DEPS,
|
|
|
efd47f |
TAG_SILENT,
|
|
|
efd47f |
TAG_TAG,
|
|
|
34988f |
TAG_CCWRAP,
|
|
|
efd47f |
TAG_VERBOSE,
|
|
|
302dac |
TAG_TARGET,
|
|
|
302dac |
TAG_HOST,
|
|
|
302dac |
TAG_FLAVOR,
|
|
|
302dac |
TAG_AR,
|
|
|
302dac |
TAG_RANLIB,
|
|
|
9a02e2 |
TAG_WINDRES,
|
|
|
302dac |
TAG_DLLTOOL,
|
|
|
fbda3a |
TAG_MDSO,
|
|
|
fbda3a |
TAG_IMPLIB,
|
|
|
116dbb |
TAG_OUTPUT,
|
|
|
63a1b4 |
TAG_BINDIR,
|
|
|
523027 |
TAG_LDRPATH,
|
|
|
bfa8ca |
TAG_SHREXT,
|
|
|
9c664d |
TAG_RPATH,
|
|
|
17e18a |
TAG_SYSROOT,
|
|
|
9aa1f4 |
TAG_RELEASE,
|
|
|
a126a7 |
TAG_OBJECTLIST,
|
|
|
05ca7e |
TAG_DLOPEN,
|
|
|
bb5843 |
TAG_DLPREOPEN,
|
|
|
916050 |
TAG_EXPORT_DYNAMIC,
|
|
|
873ecb |
TAG_EXPSYM_FILE,
|
|
|
73ca78 |
TAG_EXPSYM_REGEX,
|
|
|
5a9161 |
TAG_VERSION_INFO,
|
|
|
cd3d41 |
TAG_VERSION_NUMBER,
|
|
|
116dbb |
TAG_NO_SUPPRESS,
|
|
|
b76221 |
TAG_NO_INSTALL,
|
|
|
116dbb |
TAG_PREFER_PIC,
|
|
|
116dbb |
TAG_PREFER_NON_PIC,
|
|
|
499a71 |
TAG_HEURISTICS,
|
|
|
116dbb |
TAG_SHARED,
|
|
|
116dbb |
TAG_STATIC,
|
|
|
56f236 |
TAG_STATIC_LIBTOOL_LIBS,
|
|
|
f7645c |
TAG_ALL_STATIC,
|
|
|
0e609b |
TAG_DISABLE_STATIC,
|
|
|
f5fa4c |
TAG_DISABLE_SHARED,
|
|
|
93b62c |
TAG_NO_UNDEFINED,
|
|
|
a943fc |
TAG_MODULE,
|
|
|
68f313 |
TAG_AVOID_VERSION,
|
|
|
116dbb |
TAG_COMPILER_FLAG,
|
|
|
116dbb |
TAG_VERBATIM_FLAG,
|
|
|
53b931 |
TAG_THREAD_SAFE,
|
|
|
5e0269 |
TAG_WEAK,
|
|
|
9ca8c4 |
};
|
|
|
9ca8c4 |
|
|
|
0cbb20 |
struct slbt_split_vector {
|
|
|
0cbb20 |
char * dargs;
|
|
|
0cbb20 |
char ** dargv;
|
|
|
0cbb20 |
char ** targv;
|
|
|
0cbb20 |
char ** cargv;
|
|
|
0cbb20 |
};
|
|
|
0cbb20 |
|
|
|
46ea99 |
struct slbt_host_strs {
|
|
|
c67e64 |
char * machine;
|
|
|
46ea99 |
char * host;
|
|
|
46ea99 |
char * flavor;
|
|
|
46ea99 |
char * ar;
|
|
|
46ea99 |
char * ranlib;
|
|
|
9a02e2 |
char * windres;
|
|
|
46ea99 |
char * dlltool;
|
|
|
fbda3a |
char * mdso;
|
|
|
46ea99 |
};
|
|
|
46ea99 |
|
|
|
a126a7 |
struct slbt_obj_list {
|
|
|
a126a7 |
const char * name;
|
|
|
a126a7 |
void * addr;
|
|
|
a126a7 |
size_t size;
|
|
|
a126a7 |
int objc;
|
|
|
a126a7 |
char ** objv;
|
|
|
a126a7 |
};
|
|
|
a126a7 |
|
|
|
9ca8c4 |
struct slbt_driver_ctx_impl {
|
|
|
9ca8c4 |
struct slbt_common_ctx cctx;
|
|
|
9ca8c4 |
struct slbt_driver_ctx ctx;
|
|
|
46ea99 |
struct slbt_host_strs host;
|
|
|
a313a4 |
struct slbt_host_strs ahost;
|
|
|
a82cc2 |
struct slbt_fd_ctx fdctx;
|
|
|
a126a7 |
struct slbt_obj_list * objlistv;
|
|
|
f8e27e |
char * libname;
|
|
|
0cbb20 |
char * dargs;
|
|
|
0cbb20 |
char ** dargv;
|
|
|
56cab3 |
char ** targv;
|
|
|
56cab3 |
char ** cargv;
|
|
|
e8bfe5 |
char ** envp;
|
|
|
41c05b |
struct slbt_error_info**errinfp;
|
|
|
41c05b |
struct slbt_error_info**erricap;
|
|
|
41c05b |
struct slbt_error_info *erriptr[64];
|
|
|
41c05b |
struct slbt_error_info erribuf[64];
|
|
|
9ca8c4 |
};
|
|
|
9ca8c4 |
|
|
|
9706fa |
struct slbt_exec_ctx_impl {
|
|
|
9706fa |
int argc;
|
|
|
9706fa |
char * args;
|
|
|
9706fa |
char * shadow;
|
|
|
9706fa |
char * dsoprefix;
|
|
|
9706fa |
size_t size;
|
|
|
9706fa |
struct slbt_exec_ctx ctx;
|
|
|
9706fa |
int fdwrapper;
|
|
|
d98877 |
char ** lout[2];
|
|
|
d98877 |
char ** mout[2];
|
|
|
9706fa |
char * vbuffer[];
|
|
|
9706fa |
};
|
|
|
9706fa |
|
|
|
3a8090 |
static inline struct slbt_driver_ctx_impl * slbt_get_driver_ictx(const struct slbt_driver_ctx * dctx)
|
|
|
3a8090 |
{
|
|
|
3a8090 |
uintptr_t addr;
|
|
|
3a8090 |
|
|
|
3a8090 |
if (dctx) {
|
|
|
3a8090 |
addr = (uintptr_t)dctx - offsetof(struct slbt_driver_ctx_impl,ctx);
|
|
|
3a8090 |
return (struct slbt_driver_ctx_impl *)addr;
|
|
|
3a8090 |
}
|
|
|
3a8090 |
|
|
|
3a8090 |
return 0;
|
|
|
3a8090 |
}
|
|
|
3a8090 |
|
|
|
e8bfe5 |
static inline char ** slbt_driver_envp(const struct slbt_driver_ctx * dctx)
|
|
|
e8bfe5 |
{
|
|
|
e8bfe5 |
struct slbt_driver_ctx_impl * ictx;
|
|
|
e8bfe5 |
ictx = slbt_get_driver_ictx(dctx);
|
|
|
e8bfe5 |
return ictx->envp;
|
|
|
e8bfe5 |
}
|
|
|
e8bfe5 |
|
|
|
a82cc2 |
static inline int slbt_driver_fdin(const struct slbt_driver_ctx * dctx)
|
|
|
a82cc2 |
{
|
|
|
a82cc2 |
struct slbt_fd_ctx fdctx;
|
|
|
a82cc2 |
slbt_get_driver_fdctx(dctx,&fdctx);
|
|
|
a82cc2 |
return fdctx.fdin;
|
|
|
a82cc2 |
}
|
|
|
a82cc2 |
|
|
|
a82cc2 |
static inline int slbt_driver_fdout(const struct slbt_driver_ctx * dctx)
|
|
|
a82cc2 |
{
|
|
|
a82cc2 |
struct slbt_fd_ctx fdctx;
|
|
|
a82cc2 |
slbt_get_driver_fdctx(dctx,&fdctx);
|
|
|
a82cc2 |
return fdctx.fdout;
|
|
|
a82cc2 |
}
|
|
|
a82cc2 |
|
|
|
a82cc2 |
static inline int slbt_driver_fderr(const struct slbt_driver_ctx * dctx)
|
|
|
a82cc2 |
{
|
|
|
a82cc2 |
struct slbt_fd_ctx fdctx;
|
|
|
a82cc2 |
slbt_get_driver_fdctx(dctx,&fdctx);
|
|
|
a82cc2 |
return fdctx.fderr;
|
|
|
a82cc2 |
}
|
|
|
a82cc2 |
|
|
|
a82cc2 |
static inline int slbt_driver_fdlog(const struct slbt_driver_ctx * dctx)
|
|
|
a82cc2 |
{
|
|
|
a82cc2 |
struct slbt_fd_ctx fdctx;
|
|
|
a82cc2 |
slbt_get_driver_fdctx(dctx,&fdctx);
|
|
|
a82cc2 |
return fdctx.fdlog;
|
|
|
a82cc2 |
}
|
|
|
a82cc2 |
|
|
|
ca72f5 |
static inline int slbt_driver_fdcwd(const struct slbt_driver_ctx * dctx)
|
|
|
ca72f5 |
{
|
|
|
ca72f5 |
struct slbt_fd_ctx fdctx;
|
|
|
ca72f5 |
slbt_get_driver_fdctx(dctx,&fdctx);
|
|
|
ca72f5 |
return fdctx.fdcwd;
|
|
|
ca72f5 |
}
|
|
|
ca72f5 |
|
|
|
ca72f5 |
static inline int slbt_driver_fddst(const struct slbt_driver_ctx * dctx)
|
|
|
ca72f5 |
{
|
|
|
ca72f5 |
struct slbt_fd_ctx fdctx;
|
|
|
ca72f5 |
slbt_get_driver_fdctx(dctx,&fdctx);
|
|
|
ca72f5 |
return fdctx.fddst;
|
|
|
ca72f5 |
}
|
|
|
ca72f5 |
|
|
|
9706fa |
static inline struct slbt_exec_ctx_impl * slbt_get_exec_ictx(const struct slbt_exec_ctx * ectx)
|
|
|
9706fa |
{
|
|
|
9706fa |
uintptr_t addr;
|
|
|
9706fa |
|
|
|
9706fa |
addr = (uintptr_t)ectx - offsetof(struct slbt_exec_ctx_impl,ctx);
|
|
|
9706fa |
return (struct slbt_exec_ctx_impl *)addr;
|
|
|
9706fa |
}
|
|
|
9706fa |
|
|
|
9706fa |
static inline int slbt_exec_get_fdwrapper(const struct slbt_exec_ctx * ectx)
|
|
|
9706fa |
{
|
|
|
9706fa |
struct slbt_exec_ctx_impl * ictx;
|
|
|
9706fa |
ictx = slbt_get_exec_ictx(ectx);
|
|
|
9706fa |
return ictx->fdwrapper;
|
|
|
9706fa |
}
|
|
|
9706fa |
|
|
|
9706fa |
static inline void slbt_exec_set_fdwrapper(const struct slbt_exec_ctx * ectx, int fd)
|
|
|
9706fa |
{
|
|
|
9706fa |
struct slbt_exec_ctx_impl * ictx;
|
|
|
9706fa |
ictx = slbt_get_exec_ictx(ectx);
|
|
|
9706fa |
ictx->fdwrapper = fd;
|
|
|
9706fa |
}
|
|
|
9706fa |
|
|
|
9706fa |
static inline void slbt_exec_close_fdwrapper(const struct slbt_exec_ctx * ectx)
|
|
|
9706fa |
{
|
|
|
9706fa |
struct slbt_exec_ctx_impl * ictx;
|
|
|
9706fa |
ictx = slbt_get_exec_ictx(ectx);
|
|
|
9706fa |
close(ictx->fdwrapper);
|
|
|
9706fa |
ictx->fdwrapper = (-1);
|
|
|
9706fa |
}
|
|
|
9706fa |
|
|
|
9ca8c4 |
#endif
|