|
|
df2627 |
/*******************************************************************/
|
|
|
eac61a |
/* slibtool: a strong libtool implementation, written in C */
|
|
|
df2627 |
/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
|
|
|
df2627 |
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
|
|
|
df2627 |
/*******************************************************************/
|
|
|
df2627 |
|
|
|
df2627 |
#include <stdlib.h>
|
|
|
df2627 |
#include <inttypes.h>
|
|
|
df2627 |
#include <slibtool/slibtool.h>
|
|
|
df2627 |
#include "slibtool_driver_impl.h"
|
|
|
df2627 |
#include "slibtool_errinfo_impl.h"
|
|
|
4b56de |
#include "slibtool_visibility_impl.h"
|
|
|
df2627 |
#include "slibtool_ar_impl.h"
|
|
|
df2627 |
|
|
|
df2627 |
static int slbt_strcmp(const void * a, const void * b)
|
|
|
df2627 |
{
|
|
|
df2627 |
return strcmp(*(const char **)a,*(const char **)b);
|
|
|
df2627 |
}
|
|
|
df2627 |
|
|
|
213eb3 |
static int slbt_coff_strcmp(const void * a, const void * b)
|
|
|
213eb3 |
{
|
|
|
213eb3 |
const char * dot;
|
|
|
213eb3 |
const char * mark;
|
|
|
213eb3 |
const char * stra;
|
|
|
213eb3 |
const char * strb;
|
|
|
213eb3 |
const char ** pstra;
|
|
|
213eb3 |
const char ** pstrb;
|
|
|
213eb3 |
char strbufa[4096];
|
|
|
213eb3 |
char strbufb[4096];
|
|
|
213eb3 |
|
|
|
213eb3 |
pstra = (const char **)a;
|
|
|
213eb3 |
pstrb = (const char **)b;
|
|
|
213eb3 |
|
|
|
213eb3 |
stra = *pstra;
|
|
|
213eb3 |
strb = *pstrb;
|
|
|
213eb3 |
|
|
|
213eb3 |
if (!strncmp(*pstra,".weak.",6)) {
|
|
|
213eb3 |
stra = strbufa;
|
|
|
213eb3 |
mark = &(*pstra)[6];
|
|
|
213eb3 |
dot = strchr(mark,'.');
|
|
|
213eb3 |
|
|
|
213eb3 |
strncpy(strbufa,mark,dot-mark);
|
|
|
213eb3 |
strbufa[dot-mark] = '\0';
|
|
|
213eb3 |
}
|
|
|
213eb3 |
|
|
|
213eb3 |
if (!strncmp(*pstrb,".weak.",6)) {
|
|
|
213eb3 |
strb = strbufb;
|
|
|
213eb3 |
mark = &(*pstrb)[6];
|
|
|
213eb3 |
dot = strchr(mark,'.');
|
|
|
213eb3 |
|
|
|
213eb3 |
strncpy(strbufb,mark,dot-mark);
|
|
|
213eb3 |
strbufb[dot-mark] = '\0';
|
|
|
213eb3 |
}
|
|
|
213eb3 |
|
|
|
213eb3 |
return strcmp(stra,strb);
|
|
|
213eb3 |
}
|
|
|
213eb3 |
|
|
|
4b56de |
slbt_hidden int slbt_update_mapstrv(
|
|
|
df2627 |
const struct slbt_driver_ctx * dctx,
|
|
|
df2627 |
struct slbt_archive_meta_impl * mctx)
|
|
|
df2627 |
{
|
|
|
213eb3 |
bool fcoff;
|
|
|
df2627 |
size_t nsyms;
|
|
|
df2627 |
const char ** symv;
|
|
|
df2627 |
const char ** mapstrv;
|
|
|
df2627 |
|
|
|
213eb3 |
fcoff = slbt_host_objfmt_is_coff(dctx);
|
|
|
213eb3 |
fcoff |= (mctx->ofmtattr & AR_OBJECT_ATTR_COFF);
|
|
|
213eb3 |
|
|
|
df2627 |
for (nsyms=0,symv=mctx->symstrv; *symv; symv++)
|
|
|
df2627 |
nsyms++;
|
|
|
df2627 |
|
|
|
df2627 |
if (!(mapstrv = calloc(nsyms+1,sizeof(const char *))))
|
|
|
df2627 |
return SLBT_SYSTEM_ERROR(dctx,0);
|
|
|
df2627 |
|
|
|
df2627 |
for (nsyms=0,symv=mctx->symstrv; *symv; symv++)
|
|
|
df2627 |
mapstrv[nsyms++] = *symv;
|
|
|
df2627 |
|
|
|
213eb3 |
qsort(mapstrv,nsyms,sizeof(const char *),fcoff ? slbt_coff_strcmp : slbt_strcmp);
|
|
|
df2627 |
|
|
|
df2627 |
mctx->mapstrv = mapstrv;
|
|
|
df2627 |
|
|
|
df2627 |
return 0;
|
|
|
df2627 |
}
|