summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-01-29 01:39:04 +0000
committermidipix <writeonce@midipix.org>2024-01-29 01:39:04 +0000
commitdfb34894f7bfc10608738513df625609590628f1 (patch)
treea49c9f7de24a8bc7dad512aa8c8f646910c394da
parentdc33d486a5720a60971a859e42cdca2cb34d9203 (diff)
downloadslibtool-dfb34894f7bfc10608738513df625609590628f1.tar.bz2
slibtool-dfb34894f7bfc10608738513df625609590628f1.tar.xz
slbt_ar_parse_primary_armap_sysv_32(): move to own translation unit.
-rw-r--r--project/common.mk1
-rw-r--r--src/arbits/slbt_archive_meta.c103
-rw-r--r--src/arbits/slbt_armap_sysv_32.c119
-rw-r--r--src/internal/slibtool_ar_impl.h4
4 files changed, 124 insertions, 103 deletions
diff --git a/project/common.mk b/project/common.mk
index 2a2ab6c..8825a63 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -3,6 +3,7 @@ API_SRCS = \
src/arbits/slbt_archive_meta.c \
src/arbits/slbt_armap_bsd_32.c \
src/arbits/slbt_armap_bsd_64.c \
+ src/arbits/slbt_armap_sysv_32.c \
src/arbits/output/slbt_ar_output_arname.c \
src/arbits/output/slbt_ar_output_members.c \
src/driver/slbt_amain.c \
diff --git a/src/arbits/slbt_archive_meta.c b/src/arbits/slbt_archive_meta.c
index 9aaf6ee..5b48546 100644
--- a/src/arbits/slbt_archive_meta.c
+++ b/src/arbits/slbt_archive_meta.c
@@ -229,109 +229,6 @@ static uint32_t slbt_ar_get_member_attr(struct ar_meta_member_info * m)
return AR_MEMBER_ATTR_DEFAULT;
}
-static int slbt_ar_parse_primary_armap_sysv_32(
- const struct slbt_driver_ctx * dctx,
- struct slbt_archive_meta_impl * m)
-{
- struct ar_raw_armap_sysv_32 * armap;
- struct ar_meta_member_info * memberp;
- struct ar_meta_armap_common_32 *armapref;
- struct ar_meta_armap_ref_32 * symrefs;
- uint32_t idx;
- uint32_t uref;
- uint32_t nsyms;
- uint32_t nstrs;
- const char * ch;
- const char * cap;
- unsigned char * uch;
- unsigned char (*mark)[0x04];
-
- armap = &m->armaps.armap_sysv_32;
- memberp = m->memberv[0];
-
- mark = memberp->ar_object_data;
-
- armap->ar_num_of_syms = mark;
- uch = *mark++;
-
- armap->ar_first_ref_offset = mark;
-
- nsyms = (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3];
- mark += nsyms;
-
- if (memberp->ar_object_size < (sizeof(*mark) + (nsyms * sizeof(*mark))))
- return SLBT_CUSTOM_ERROR(
- dctx,
- SLBT_ERR_AR_INVALID_ARMAP_NUMBER_OF_SYMS);
-
- m->symstrs = (const char *)mark;
-
- cap = memberp->ar_object_data;
- cap += memberp->ar_object_size;
-
- if ((cap == m->symstrs) && nsyms)
- return SLBT_CUSTOM_ERROR(
- dctx,
- SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
-
- if (nsyms && !m->symstrs[0])
- return SLBT_CUSTOM_ERROR(
- dctx,
- SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
-
- for (ch=&m->symstrs[1],nstrs=0; ch<cap; ch++) {
- if (!ch[0] && !ch[-1] && (nstrs < nsyms))
- return SLBT_CUSTOM_ERROR(
- dctx,
- SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
-
- if (!ch[0] && ch[-1])
- nstrs++;
- }
-
- if (nstrs != nsyms)
- return SLBT_CUSTOM_ERROR(
- dctx,
- SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
-
- if (cap[-1])
- return SLBT_CUSTOM_ERROR(
- dctx,
- SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
-
- if (!(m->symstrv = calloc(nsyms + 1,sizeof(const char *))))
- return SLBT_SYSTEM_ERROR(dctx,0);
-
- if (!(m->armaps.armap_symrefs_32 = calloc(nsyms + 1,sizeof(*symrefs))))
- return SLBT_SYSTEM_ERROR(dctx,0);
-
- mark = armap->ar_first_ref_offset;
- symrefs = m->armaps.armap_symrefs_32;
-
- for (idx=0,uch=*mark; idx<nsyms; idx++,uch=*++mark) {
- uref = (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3];
- symrefs[idx].ar_member_offset = uref;
- }
-
- armap->ar_string_table = m->symstrv;
-
- armapref = &m->armaps.armap_common_32;
- armapref->ar_member = memberp;
- armapref->ar_symrefs = symrefs;
- armapref->ar_armap_sysv = armap;
- armapref->ar_armap_attr = AR_ARMAP_ATTR_SYSV | AR_ARMAP_ATTR_BE_32;
- armapref->ar_num_of_symbols = nsyms;
- armapref->ar_size_of_refs = nsyms * sizeof(*mark);
- armapref->ar_size_of_strs = cap - m->symstrs;
- armapref->ar_string_table = m->symstrs;
-
- m->armaps.armap_nsyms = nsyms;
-
- m->armeta.a_armap_primary.ar_armap_common_32 = armapref;
-
- return 0;
-}
-
static int slbt_ar_parse_primary_armap_sysv_64(
const struct slbt_driver_ctx * dctx,
struct slbt_archive_meta_impl * m)
diff --git a/src/arbits/slbt_armap_sysv_32.c b/src/arbits/slbt_armap_sysv_32.c
new file mode 100644
index 0000000..12840ef
--- /dev/null
+++ b/src/arbits/slbt_armap_sysv_32.c
@@ -0,0 +1,119 @@
+/*******************************************************************/
+/* slibtool: a skinny libtool implementation, written in C */
+/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
+/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
+/*******************************************************************/
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <slibtool/slibtool.h>
+#include <slibtool/slibtool_arbits.h>
+#include "slibtool_ar_impl.h"
+#include "slibtool_driver_impl.h"
+#include "slibtool_errinfo_impl.h"
+
+int slbt_ar_parse_primary_armap_sysv_32(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_archive_meta_impl * m)
+{
+ struct ar_raw_armap_sysv_32 * armap;
+ struct ar_meta_member_info * memberp;
+ struct ar_meta_armap_common_32 *armapref;
+ struct ar_meta_armap_ref_32 * symrefs;
+ uint32_t idx;
+ uint32_t uref;
+ uint32_t nsyms;
+ uint32_t nstrs;
+ const char * ch;
+ const char * cap;
+ unsigned char * uch;
+ unsigned char (*mark)[0x04];
+
+ armap = &m->armaps.armap_sysv_32;
+ memberp = m->memberv[0];
+
+ mark = memberp->ar_object_data;
+
+ armap->ar_num_of_syms = mark;
+ uch = *mark++;
+
+ armap->ar_first_ref_offset = mark;
+
+ nsyms = (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3];
+ mark += nsyms;
+
+ if (memberp->ar_object_size < (sizeof(*mark) + (nsyms * sizeof(*mark))))
+ return SLBT_CUSTOM_ERROR(
+ dctx,
+ SLBT_ERR_AR_INVALID_ARMAP_NUMBER_OF_SYMS);
+
+ m->symstrs = (const char *)mark;
+
+ cap = memberp->ar_object_data;
+ cap += memberp->ar_object_size;
+
+ if ((cap == m->symstrs) && nsyms)
+ return SLBT_CUSTOM_ERROR(
+ dctx,
+ SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
+
+ if (nsyms && !m->symstrs[0])
+ return SLBT_CUSTOM_ERROR(
+ dctx,
+ SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
+
+ for (ch=&m->symstrs[1],nstrs=0; ch<cap; ch++) {
+ if (!ch[0] && !ch[-1] && (nstrs < nsyms))
+ return SLBT_CUSTOM_ERROR(
+ dctx,
+ SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
+
+ if (!ch[0] && ch[-1])
+ nstrs++;
+ }
+
+ if (nstrs != nsyms)
+ return SLBT_CUSTOM_ERROR(
+ dctx,
+ SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
+
+ if (cap[-1])
+ return SLBT_CUSTOM_ERROR(
+ dctx,
+ SLBT_ERR_AR_INVALID_ARMAP_STRING_TABLE);
+
+ if (!(m->symstrv = calloc(nsyms + 1,sizeof(const char *))))
+ return SLBT_SYSTEM_ERROR(dctx,0);
+
+ if (!(m->armaps.armap_symrefs_32 = calloc(nsyms + 1,sizeof(*symrefs))))
+ return SLBT_SYSTEM_ERROR(dctx,0);
+
+ mark = armap->ar_first_ref_offset;
+ symrefs = m->armaps.armap_symrefs_32;
+
+ for (idx=0,uch=*mark; idx<nsyms; idx++,uch=*++mark) {
+ uref = (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3];
+ symrefs[idx].ar_member_offset = uref;
+ }
+
+ armap->ar_string_table = m->symstrv;
+
+ armapref = &m->armaps.armap_common_32;
+ armapref->ar_member = memberp;
+ armapref->ar_symrefs = symrefs;
+ armapref->ar_armap_sysv = armap;
+ armapref->ar_armap_attr = AR_ARMAP_ATTR_SYSV | AR_ARMAP_ATTR_BE_32;
+ armapref->ar_num_of_symbols = nsyms;
+ armapref->ar_size_of_refs = nsyms * sizeof(*mark);
+ armapref->ar_size_of_strs = cap - m->symstrs;
+ armapref->ar_string_table = m->symstrs;
+
+ m->armaps.armap_nsyms = nsyms;
+
+ m->armeta.a_armap_primary.ar_armap_common_32 = armapref;
+
+ return 0;
+}
diff --git a/src/internal/slibtool_ar_impl.h b/src/internal/slibtool_ar_impl.h
index 7530a0a..2eec770 100644
--- a/src/internal/slibtool_ar_impl.h
+++ b/src/internal/slibtool_ar_impl.h
@@ -54,6 +54,10 @@ int slbt_ar_parse_primary_armap_bsd_64(
const struct slbt_driver_ctx * dctx,
struct slbt_archive_meta_impl * m);
+int slbt_ar_parse_primary_armap_sysv_32(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_archive_meta_impl * m);
+
static inline struct slbt_archive_meta_impl * slbt_archive_meta_ictx(const struct slbt_archive_meta * meta)
{
uintptr_t addr;