summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-03-16 04:01:52 +0000
committermidipix <writeonce@midipix.org>2024-03-16 15:31:40 +0000
commit213eb30aa5d5023f4156249349c278322a8ac2bf (patch)
treeff16bc982ae7ec2bf2cdad1aeb7533a36035c12d /src
parenta77f8d5a6e4cd54ef6a45ef93d30bb2fb742d86f (diff)
downloadslibtool-213eb30aa5d5023f4156249349c278322a8ac2bf.tar.bz2
slibtool-213eb30aa5d5023f4156249349c278322a8ac2bf.tar.xz
slbt_update_mapstrv(): PE/COFF: vector sorting: properly handle weak aliases.
Diffstat (limited to 'src')
-rw-r--r--src/arbits/slbt_archive_mapstrv.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/arbits/slbt_archive_mapstrv.c b/src/arbits/slbt_archive_mapstrv.c
index f48576a..10d59f1 100644
--- a/src/arbits/slbt_archive_mapstrv.c
+++ b/src/arbits/slbt_archive_mapstrv.c
@@ -17,14 +17,56 @@ static int slbt_strcmp(const void * a, const void * b)
return strcmp(*(const char **)a,*(const char **)b);
}
+static int slbt_coff_strcmp(const void * a, const void * b)
+{
+ const char * dot;
+ const char * mark;
+ const char * stra;
+ const char * strb;
+ const char ** pstra;
+ const char ** pstrb;
+ char strbufa[4096];
+ char strbufb[4096];
+
+ pstra = (const char **)a;
+ pstrb = (const char **)b;
+
+ stra = *pstra;
+ strb = *pstrb;
+
+ if (!strncmp(*pstra,".weak.",6)) {
+ stra = strbufa;
+ mark = &(*pstra)[6];
+ dot = strchr(mark,'.');
+
+ strncpy(strbufa,mark,dot-mark);
+ strbufa[dot-mark] = '\0';
+ }
+
+ if (!strncmp(*pstrb,".weak.",6)) {
+ strb = strbufb;
+ mark = &(*pstrb)[6];
+ dot = strchr(mark,'.');
+
+ strncpy(strbufb,mark,dot-mark);
+ strbufb[dot-mark] = '\0';
+ }
+
+ return strcmp(stra,strb);
+}
+
slbt_hidden int slbt_update_mapstrv(
const struct slbt_driver_ctx * dctx,
struct slbt_archive_meta_impl * mctx)
{
+ bool fcoff;
size_t nsyms;
const char ** symv;
const char ** mapstrv;
+ fcoff = slbt_host_objfmt_is_coff(dctx);
+ fcoff |= (mctx->ofmtattr & AR_OBJECT_ATTR_COFF);
+
for (nsyms=0,symv=mctx->symstrv; *symv; symv++)
nsyms++;
@@ -34,7 +76,7 @@ slbt_hidden int slbt_update_mapstrv(
for (nsyms=0,symv=mctx->symstrv; *symv; symv++)
mapstrv[nsyms++] = *symv;
- qsort(mapstrv,nsyms,sizeof(const char *),slbt_strcmp);
+ qsort(mapstrv,nsyms,sizeof(const char *),fcoff ? slbt_coff_strcmp : slbt_strcmp);
mctx->mapstrv = mapstrv;