summaryrefslogtreecommitdiff
path: root/src/arbits
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-01-29 01:31:11 +0000
committermidipix <writeonce@midipix.org>2024-01-29 01:31:11 +0000
commit5658dae4619c35811b2290724e040988f95917dd (patch)
tree293d7fe4db5ca89c754bb47b3e75192346b12efd /src/arbits
parentf188e8f85522312ef04b8d1d162d8586b964975e (diff)
downloadslibtool-5658dae4619c35811b2290724e040988f95917dd.tar.bz2
slibtool-5658dae4619c35811b2290724e040988f95917dd.tar.xz
slbt_ar_parse_primary_armap_bsd_32(): move to own translation unit.
Diffstat (limited to 'src/arbits')
-rw-r--r--src/arbits/slbt_archive_meta.c131
-rw-r--r--src/arbits/slbt_armap_bsd_32.c147
2 files changed, 147 insertions, 131 deletions
diff --git a/src/arbits/slbt_archive_meta.c b/src/arbits/slbt_archive_meta.c
index ec45777..fcc3f2f 100644
--- a/src/arbits/slbt_archive_meta.c
+++ b/src/arbits/slbt_archive_meta.c
@@ -229,137 +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_bsd_32(
- const struct slbt_driver_ctx * dctx,
- struct slbt_archive_meta_impl * m)
-
-{
- struct ar_raw_armap_bsd_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 attr;
- uint32_t nsyms;
- uint32_t nstrs;
- uint32_t sizeofrefs_le;
- uint32_t sizeofrefs_be;
- uint32_t sizeofrefs;
- uint32_t sizeofstrs;
- const char * ch;
- const char * cap;
- unsigned char * uch;
- unsigned char (*mark)[0x04];
-
- armap = &m->armaps.armap_bsd_32;
- memberp = m->memberv[0];
-
- mark = memberp->ar_object_data;
-
- armap->ar_size_of_refs = mark;
- uch = *mark++;
-
- armap->ar_first_name_offset = mark;
-
- sizeofrefs_le = (uch[3] << 24) + (uch[2] << 16) + (uch[1] << 8) + uch[0];
- sizeofrefs_be = (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3];
-
- if (sizeofrefs_le < memberp->ar_object_size - sizeof(*mark)) {
- sizeofrefs = sizeofrefs_le;
- attr = AR_ARMAP_ATTR_LE_32;
-
- } else if (sizeofrefs_be < memberp->ar_object_size - sizeof(*mark)) {
- sizeofrefs = sizeofrefs_be;
- attr = AR_ARMAP_ATTR_BE_32;
- } else {
- return SLBT_CUSTOM_ERROR(
- dctx,
- SLBT_ERR_AR_INVALID_ARMAP_SIZE_OF_REFS);
- }
-
- nsyms = sizeofrefs / sizeof(struct ar_raw_armap_ref_32);
- mark += (sizeofrefs / sizeof(*mark));
-
- armap->ar_size_of_strs = mark;
- uch = *mark++;
-
- sizeofstrs = (attr == AR_ARMAP_ATTR_LE_32)
- ? (uch[3] << 24) + (uch[2] << 16) + (uch[1] << 8) + uch[0]
- : (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3];
-
- if (sizeofstrs > memberp->ar_object_size - 2*sizeof(*mark) - sizeofrefs)
- return SLBT_CUSTOM_ERROR(
- dctx,
- SLBT_ERR_AR_INVALID_ARMAP_SIZE_OF_STRS);
-
- m->symstrs = (const char *)mark;
-
- cap = m->symstrs;
- cap += sizeofstrs;
-
- 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 < nsyms))
- nstrs++;
- }
-
- if (nstrs != nsyms)
- 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_name_offset;
- symrefs = m->armaps.armap_symrefs_32;
-
- for (idx=0,uch=*++mark; idx<nsyms; idx++,uch=*++mark) {
- uref = (attr == AR_ARMAP_ATTR_BE_32)
- ? (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3]
- : (uch[3] << 24) + (uch[2] << 16) + (uch[1] << 8) + uch[0];
-
- symrefs[idx].ar_member_offset = uref;
- mark++;
- }
-
- armap->ar_string_table = m->symstrv;
-
- armapref = &m->armaps.armap_common_32;
- armapref->ar_member = memberp;
- armapref->ar_symrefs = symrefs;
- armapref->ar_armap_bsd = armap;
- armapref->ar_armap_attr = AR_ARMAP_ATTR_BSD | attr;
- armapref->ar_num_of_symbols = nsyms;
- armapref->ar_size_of_refs = sizeofrefs;
- armapref->ar_size_of_strs = sizeofstrs;
- 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_bsd_64(
const struct slbt_driver_ctx * dctx,
struct slbt_archive_meta_impl * m)
diff --git a/src/arbits/slbt_armap_bsd_32.c b/src/arbits/slbt_armap_bsd_32.c
new file mode 100644
index 0000000..ed236b6
--- /dev/null
+++ b/src/arbits/slbt_armap_bsd_32.c
@@ -0,0 +1,147 @@
+/*******************************************************************/
+/* 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_bsd_32(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_archive_meta_impl * m)
+
+{
+ struct ar_raw_armap_bsd_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 attr;
+ uint32_t nsyms;
+ uint32_t nstrs;
+ uint32_t sizeofrefs_le;
+ uint32_t sizeofrefs_be;
+ uint32_t sizeofrefs;
+ uint32_t sizeofstrs;
+ const char * ch;
+ const char * cap;
+ unsigned char * uch;
+ unsigned char (*mark)[0x04];
+
+ armap = &m->armaps.armap_bsd_32;
+ memberp = m->memberv[0];
+
+ mark = memberp->ar_object_data;
+
+ armap->ar_size_of_refs = mark;
+ uch = *mark++;
+
+ armap->ar_first_name_offset = mark;
+
+ sizeofrefs_le = (uch[3] << 24) + (uch[2] << 16) + (uch[1] << 8) + uch[0];
+ sizeofrefs_be = (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3];
+
+ if (sizeofrefs_le < memberp->ar_object_size - sizeof(*mark)) {
+ sizeofrefs = sizeofrefs_le;
+ attr = AR_ARMAP_ATTR_LE_32;
+
+ } else if (sizeofrefs_be < memberp->ar_object_size - sizeof(*mark)) {
+ sizeofrefs = sizeofrefs_be;
+ attr = AR_ARMAP_ATTR_BE_32;
+ } else {
+ return SLBT_CUSTOM_ERROR(
+ dctx,
+ SLBT_ERR_AR_INVALID_ARMAP_SIZE_OF_REFS);
+ }
+
+ nsyms = sizeofrefs / sizeof(struct ar_raw_armap_ref_32);
+ mark += (sizeofrefs / sizeof(*mark));
+
+ armap->ar_size_of_strs = mark;
+ uch = *mark++;
+
+ sizeofstrs = (attr == AR_ARMAP_ATTR_LE_32)
+ ? (uch[3] << 24) + (uch[2] << 16) + (uch[1] << 8) + uch[0]
+ : (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3];
+
+ if (sizeofstrs > memberp->ar_object_size - 2*sizeof(*mark) - sizeofrefs)
+ return SLBT_CUSTOM_ERROR(
+ dctx,
+ SLBT_ERR_AR_INVALID_ARMAP_SIZE_OF_STRS);
+
+ m->symstrs = (const char *)mark;
+
+ cap = m->symstrs;
+ cap += sizeofstrs;
+
+ 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 < nsyms))
+ nstrs++;
+ }
+
+ if (nstrs != nsyms)
+ 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_name_offset;
+ symrefs = m->armaps.armap_symrefs_32;
+
+ for (idx=0,uch=*++mark; idx<nsyms; idx++,uch=*++mark) {
+ uref = (attr == AR_ARMAP_ATTR_BE_32)
+ ? (uch[0] << 24) + (uch[1] << 16) + (uch[2] << 8) + uch[3]
+ : (uch[3] << 24) + (uch[2] << 16) + (uch[1] << 8) + uch[0];
+
+ symrefs[idx].ar_member_offset = uref;
+ mark++;
+ }
+
+ armap->ar_string_table = m->symstrv;
+
+ armapref = &m->armaps.armap_common_32;
+ armapref->ar_member = memberp;
+ armapref->ar_symrefs = symrefs;
+ armapref->ar_armap_bsd = armap;
+ armapref->ar_armap_attr = AR_ARMAP_ATTR_BSD | attr;
+ armapref->ar_num_of_symbols = nsyms;
+ armapref->ar_size_of_refs = sizeofrefs;
+ armapref->ar_size_of_strs = sizeofstrs;
+ armapref->ar_string_table = m->symstrs;
+
+ m->armaps.armap_nsyms = nsyms;
+
+ m->armeta.a_armap_primary.ar_armap_common_32 = armapref;
+
+ return 0;
+}