xref: /titanic_52/usr/src/cmd/sgs/libelf/common/ar.c (revision ba7866cd2cbdf574f47d4e38a1301b90744dd677)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57257d1b4Sraf  * Common Development and Distribution License (the "License").
67257d1b4Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217257d1b4Sraf 
227257d1b4Sraf /*
23*ba7866cdSAli Bahrami  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
247257d1b4Sraf  */
257257d1b4Sraf 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  *	Copyright (c) 1988 AT&T
287c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <ar.h>
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <memory.h>
347c478bd9Sstevel@tonic-gate #include <errno.h>
357c478bd9Sstevel@tonic-gate #include <libelf.h>
367c478bd9Sstevel@tonic-gate #include "decl.h"
377c478bd9Sstevel@tonic-gate #include "msg.h"
387c478bd9Sstevel@tonic-gate #include "member.h"
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	MANGLE	'\177'
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * Archive processing
457c478bd9Sstevel@tonic-gate  *	When processing an archive member, two things can happen
467c478bd9Sstevel@tonic-gate  *	that are a little tricky.
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * Sliding
497c478bd9Sstevel@tonic-gate  *	Sliding support is left in for backward compatibility and for
507c478bd9Sstevel@tonic-gate  *	support of Archives produced on other systems.  The bundled
517c478bd9Sstevel@tonic-gate  *	ar(1) produces archives with all members on a 4 byte boundry,
527c478bd9Sstevel@tonic-gate  *	so current archives should need no sliding.
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  *	Archive members that are only 2-byte aligned within the file will
557c478bd9Sstevel@tonic-gate  *	be slid.  To reuse the file's memory image, the library slides an
567c478bd9Sstevel@tonic-gate  *	archive member into its header to align the bytes.  This means
577c478bd9Sstevel@tonic-gate  *	the header must be disposable.
587c478bd9Sstevel@tonic-gate  *
597c478bd9Sstevel@tonic-gate  * Header reuse
607c478bd9Sstevel@tonic-gate  *	Because the library can trample the header, it must be preserved to
617c478bd9Sstevel@tonic-gate  *	avoid restrictions on archive member reuse.  That is, if the member
627c478bd9Sstevel@tonic-gate  *	header changes, the library may see garbage the next time it looks
637c478bd9Sstevel@tonic-gate  *	at the header.  After extracting the original header, the library
647c478bd9Sstevel@tonic-gate  *	appends it to the parents `ed_memlist' list, thus future lookups first
657c478bd9Sstevel@tonic-gate  *	check this list to determine if a member has previously been processed
667c478bd9Sstevel@tonic-gate  *	and whether sliding occured.
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * Size check
727c478bd9Sstevel@tonic-gate  *	If the header is too small, the following generates a negative
737c478bd9Sstevel@tonic-gate  *	subscript for x.x and fails to compile.
747c478bd9Sstevel@tonic-gate  *
757c478bd9Sstevel@tonic-gate  * The check is based on sizeof (Elf64) because that's always going
767c478bd9Sstevel@tonic-gate  * to be at least as big as Elf32.
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate struct	x
807c478bd9Sstevel@tonic-gate {
817c478bd9Sstevel@tonic-gate 	char	x[sizeof (struct ar_hdr) - 3 * sizeof (Elf64) - 1];
827c478bd9Sstevel@tonic-gate };
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate static const char	fmag[] = ARFMAG;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * Convert a string starting at 'p' and ending at 'end' into
917c478bd9Sstevel@tonic-gate  * an integer.  Base is the base of the number being converted
927c478bd9Sstevel@tonic-gate  * (either 8 or 10).
937c478bd9Sstevel@tonic-gate  *
947c478bd9Sstevel@tonic-gate  * Returns the converted integer of the string being scaned.
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate unsigned long
977c478bd9Sstevel@tonic-gate _elf_number(char *p, char *end, int base)
987c478bd9Sstevel@tonic-gate {
997c478bd9Sstevel@tonic-gate 	register unsigned	c;
1007c478bd9Sstevel@tonic-gate 	register unsigned long	n = 0;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	while (p < end) {
1037c478bd9Sstevel@tonic-gate 		if ((c = *p - '0') >= base) {
1047c478bd9Sstevel@tonic-gate 			while (*p++ == ' ')
1057c478bd9Sstevel@tonic-gate 				if (p >= end)
1067c478bd9Sstevel@tonic-gate 					return (n);
1077c478bd9Sstevel@tonic-gate 			return (0);
1087c478bd9Sstevel@tonic-gate 		}
1097c478bd9Sstevel@tonic-gate 		n *= base;
1107c478bd9Sstevel@tonic-gate 		n += c;
1117c478bd9Sstevel@tonic-gate 		++p;
1127c478bd9Sstevel@tonic-gate 	}
1137c478bd9Sstevel@tonic-gate 	return (n);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * Convert ar_hdr to Member
1197c478bd9Sstevel@tonic-gate  *	Converts ascii file representation to the binary memory values.
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate Member *
1227c478bd9Sstevel@tonic-gate _elf_armem(Elf *elf, char *file, size_t fsz)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	register struct ar_hdr	*f = (struct ar_hdr *)file;
1257c478bd9Sstevel@tonic-gate 	register Member		*m;
1267c478bd9Sstevel@tonic-gate 	register Memlist	*l, * ol;
1277c478bd9Sstevel@tonic-gate 	register Memident	*i;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	if (fsz < sizeof (struct ar_hdr)) {
1307c478bd9Sstevel@tonic-gate 		_elf_seterr(EFMT_ARHDRSZ, 0);
1317c478bd9Sstevel@tonic-gate 		return (0);
1327c478bd9Sstevel@tonic-gate 	}
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * Determine in this member has already been processed
1367c478bd9Sstevel@tonic-gate 	 */
1377c478bd9Sstevel@tonic-gate 	for (l = elf->ed_memlist, ol = l; l; ol = l, l = l->m_next)
1387c478bd9Sstevel@tonic-gate 		for (i = (Memident *)(l + 1); i < l->m_free; i++)
1397c478bd9Sstevel@tonic-gate 			if (i->m_offset == file)
1407c478bd9Sstevel@tonic-gate 				return (i->m_member);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	if (f->ar_fmag[0] != fmag[0] || f->ar_fmag[1] != fmag[1]) {
1437c478bd9Sstevel@tonic-gate 		_elf_seterr(EFMT_ARFMAG, 0);
1447c478bd9Sstevel@tonic-gate 		return (0);
1457c478bd9Sstevel@tonic-gate 	}
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	/*
1487c478bd9Sstevel@tonic-gate 	 * Allocate a new member structure and assign it to the next free
1497c478bd9Sstevel@tonic-gate 	 * free memlist ident.
1507c478bd9Sstevel@tonic-gate 	 */
1517c478bd9Sstevel@tonic-gate 	if ((m = (Member *)malloc(sizeof (Member))) == 0) {
1527c478bd9Sstevel@tonic-gate 		_elf_seterr(EMEM_ARMEM, errno);
1537c478bd9Sstevel@tonic-gate 		return (0);
1547c478bd9Sstevel@tonic-gate 	}
1557c478bd9Sstevel@tonic-gate 	if ((elf->ed_memlist == 0) || (ol->m_free == ol->m_end)) {
1567c478bd9Sstevel@tonic-gate 		if ((l = (Memlist *)malloc(sizeof (Memlist) +
1577c478bd9Sstevel@tonic-gate 		    (sizeof (Memident) * MEMIDENTNO))) == 0) {
1587c478bd9Sstevel@tonic-gate 			_elf_seterr(EMEM_ARMEM, errno);
1597c478bd9Sstevel@tonic-gate 			return (0);
1607c478bd9Sstevel@tonic-gate 		}
1617c478bd9Sstevel@tonic-gate 		l->m_next = 0;
1627c478bd9Sstevel@tonic-gate 		l->m_free = (Memident *)(l + 1);
1637c478bd9Sstevel@tonic-gate 		l->m_end = (Memident *)((uintptr_t)l->m_free +
1647c478bd9Sstevel@tonic-gate 		    (sizeof (Memident) * MEMIDENTNO));
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 		if (elf->ed_memlist == 0)
1677c478bd9Sstevel@tonic-gate 			elf->ed_memlist = l;
1687c478bd9Sstevel@tonic-gate 		else
1697c478bd9Sstevel@tonic-gate 			ol->m_next = l;
1707c478bd9Sstevel@tonic-gate 		ol = l;
1717c478bd9Sstevel@tonic-gate 	}
1727c478bd9Sstevel@tonic-gate 	ol->m_free->m_offset = file;
1737c478bd9Sstevel@tonic-gate 	ol->m_free->m_member = m;
1747c478bd9Sstevel@tonic-gate 	ol->m_free++;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	m->m_err = 0;
1777c478bd9Sstevel@tonic-gate 	(void) memcpy(m->m_name, f->ar_name, ARSZ(ar_name));
1787c478bd9Sstevel@tonic-gate 	m->m_name[ARSZ(ar_name)] = '\0';
1797c478bd9Sstevel@tonic-gate 	m->m_hdr.ar_name = m->m_name;
1807c478bd9Sstevel@tonic-gate 	(void) memcpy(m->m_raw, f->ar_name, ARSZ(ar_name));
1817c478bd9Sstevel@tonic-gate 	m->m_raw[ARSZ(ar_name)] = '\0';
1827c478bd9Sstevel@tonic-gate 	m->m_hdr.ar_rawname = m->m_raw;
1837c478bd9Sstevel@tonic-gate 	m->m_slide = 0;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	/*
1867c478bd9Sstevel@tonic-gate 	 * Classify file name.
1877c478bd9Sstevel@tonic-gate 	 * If a name error occurs, delay until getarhdr().
1887c478bd9Sstevel@tonic-gate 	 */
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	if (f->ar_name[0] != '/') {	/* regular name */
1917c478bd9Sstevel@tonic-gate 		register char	*p;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 		p = &m->m_name[sizeof (m->m_name)];
1947c478bd9Sstevel@tonic-gate 		while (*--p != '/')
1957c478bd9Sstevel@tonic-gate 			if (p <= m->m_name)
1967c478bd9Sstevel@tonic-gate 				break;
1977c478bd9Sstevel@tonic-gate 		*p = '\0';
1987c478bd9Sstevel@tonic-gate 	} else if (f->ar_name[1] >= '0' && f->ar_name[1] <= '9') { /* strtab */
1997c478bd9Sstevel@tonic-gate 		register unsigned long	j;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 		j = _elf_number(&f->ar_name[1],
2027c478bd9Sstevel@tonic-gate 		    &f->ar_name[ARSZ(ar_name)], 10);
2037c478bd9Sstevel@tonic-gate 		if (j < elf->ed_arstrsz)
2047c478bd9Sstevel@tonic-gate 			m->m_hdr.ar_name = elf->ed_arstr + j;
2057c478bd9Sstevel@tonic-gate 		else {
2067c478bd9Sstevel@tonic-gate 			m->m_hdr.ar_name = 0;
2077c478bd9Sstevel@tonic-gate 			/*LINTED*/ /* MSG_INTL(EFMT_ARSTRNM) */
2087c478bd9Sstevel@tonic-gate 			m->m_err = (int)EFMT_ARSTRNM;
2097c478bd9Sstevel@tonic-gate 		}
2107c478bd9Sstevel@tonic-gate 	} else if (f->ar_name[1] == ' ')			/* "/" */
2117c478bd9Sstevel@tonic-gate 		m->m_name[1] = '\0';
2127c478bd9Sstevel@tonic-gate 	else if (f->ar_name[1] == '/' && f->ar_name[2] == ' ')	/* "//" */
2137c478bd9Sstevel@tonic-gate 		m->m_name[2] = '\0';
214*ba7866cdSAli Bahrami 	else if (f->ar_name[1] == 'S' && f->ar_name[2] == 'Y' &&
215*ba7866cdSAli Bahrami 	    f->ar_name[3] == 'M' && f->ar_name[4] == '6' &&
216*ba7866cdSAli Bahrami 	    f->ar_name[5] == '4' && f->ar_name[6] == '/' &&
217*ba7866cdSAli Bahrami 	    f->ar_name[7] == ' ')				/* "/SYM64/" */
218*ba7866cdSAli Bahrami 		m->m_name[7] = '\0';
2197c478bd9Sstevel@tonic-gate 	else {							/* "/?" */
2207c478bd9Sstevel@tonic-gate 		m->m_hdr.ar_name = 0;
2217c478bd9Sstevel@tonic-gate 		/*LINTED*/ /* MSG_INTL(EFMT_ARUNKNM) */
2227c478bd9Sstevel@tonic-gate 		m->m_err = (int)EFMT_ARUNKNM;
2237c478bd9Sstevel@tonic-gate 	}
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	m->m_hdr.ar_date = (time_t)_elf_number(f->ar_date,
2267c478bd9Sstevel@tonic-gate 	    &f->ar_date[ARSZ(ar_date)], 10);
2277c478bd9Sstevel@tonic-gate 	/* LINTED */
2287c478bd9Sstevel@tonic-gate 	m->m_hdr.ar_uid = (uid_t)_elf_number(f->ar_uid,
2297c478bd9Sstevel@tonic-gate 	    &f->ar_uid[ARSZ(ar_uid)], 10);
2307c478bd9Sstevel@tonic-gate 	/* LINTED */
2317c478bd9Sstevel@tonic-gate 	m->m_hdr.ar_gid = (gid_t)_elf_number(f->ar_gid,
2327c478bd9Sstevel@tonic-gate 	    &f->ar_gid[ARSZ(ar_gid)], 10);
2337c478bd9Sstevel@tonic-gate 	/* LINTED */
2347c478bd9Sstevel@tonic-gate 	m->m_hdr.ar_mode = (mode_t)_elf_number(f->ar_mode,
2357c478bd9Sstevel@tonic-gate 	    &f->ar_mode[ARSZ(ar_mode)], 8);
2367c478bd9Sstevel@tonic-gate 	m->m_hdr.ar_size = (off_t)_elf_number(f->ar_size,
2377c478bd9Sstevel@tonic-gate 	    &f->ar_size[ARSZ(ar_size)], 10);
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	return (m);
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * Initial archive processing
2457c478bd9Sstevel@tonic-gate  *	An archive may have two special members.
246*ba7866cdSAli Bahrami  *
247*ba7866cdSAli Bahrami  *	A symbol table, named / or /SYM64/, must be first if it is present.
248*ba7866cdSAli Bahrami  *	Both forms use the same layout differing in the width of the
249*ba7866cdSAli Bahrami  *	integer type used (32 or 64-bit respectively).
250*ba7866cdSAli Bahrami  *
251*ba7866cdSAli Bahrami  *	A long name string table, named //, must precede all "normal"
252*ba7866cdSAli Bahrami  *	members. This string table is used to hold the names of archive
253*ba7866cdSAli Bahrami  *	members with names that are longer than 15 characters. It should not
254*ba7866cdSAli Bahrami  *	be confused with the string table found at the end of the symbol
255*ba7866cdSAli Bahrami  *	table, which is used to hold symbol names.
2567c478bd9Sstevel@tonic-gate  *
2577c478bd9Sstevel@tonic-gate  *	This code "peeks" at headers but doesn't change them.
2587c478bd9Sstevel@tonic-gate  *	Later processing wants original headers.
2597c478bd9Sstevel@tonic-gate  *
2607c478bd9Sstevel@tonic-gate  *	String table is converted, changing '/' name terminators
2617c478bd9Sstevel@tonic-gate  *	to nulls.  The last byte in the string table, which should
2627c478bd9Sstevel@tonic-gate  *	be '\n', is set to nil, guaranteeing null termination.  That
2637c478bd9Sstevel@tonic-gate  *	byte should be '\n', but this code doesn't check.
2647c478bd9Sstevel@tonic-gate  *
2657c478bd9Sstevel@tonic-gate  *	The symbol table conversion is delayed until needed.
2667c478bd9Sstevel@tonic-gate  */
2677c478bd9Sstevel@tonic-gate void
2687c478bd9Sstevel@tonic-gate _elf_arinit(Elf * elf)
2697c478bd9Sstevel@tonic-gate {
2707c478bd9Sstevel@tonic-gate 	char				*base = elf->ed_ident;
2717c478bd9Sstevel@tonic-gate 	register char			*end = base + elf->ed_fsz;
2727c478bd9Sstevel@tonic-gate 	register struct ar_hdr		*a;
2737c478bd9Sstevel@tonic-gate 	register char			*hdr = base + SARMAG;
2747c478bd9Sstevel@tonic-gate 	register char			*mem;
2757c478bd9Sstevel@tonic-gate 	int				j;
2767c478bd9Sstevel@tonic-gate 	size_t				sz = SARMAG;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	elf->ed_status = ES_COOKED;
2797c478bd9Sstevel@tonic-gate 	elf->ed_nextoff = SARMAG;
2807c478bd9Sstevel@tonic-gate 	for (j = 0; j < 2; ++j)	 {	/* 2 special members */
2817c478bd9Sstevel@tonic-gate 		unsigned long	n;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 		if (((end - hdr) < sizeof (struct ar_hdr)) ||
2847c478bd9Sstevel@tonic-gate 		    (_elf_vm(elf, (size_t)(SARMAG),
2857c478bd9Sstevel@tonic-gate 		    sizeof (struct ar_hdr)) != OK_YES))
2867c478bd9Sstevel@tonic-gate 			return;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 		a = (struct ar_hdr *)hdr;
2897c478bd9Sstevel@tonic-gate 		mem = (char *)a + sizeof (struct ar_hdr);
2907c478bd9Sstevel@tonic-gate 		n = _elf_number(a->ar_size, &a->ar_size[ARSZ(ar_size)], 10);
2917c478bd9Sstevel@tonic-gate 		if ((end - mem < n) || (a->ar_name[0] != '/') ||
2927c478bd9Sstevel@tonic-gate 		    ((sz = n) != n)) {
2937c478bd9Sstevel@tonic-gate 			return;
2947c478bd9Sstevel@tonic-gate 		}
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 		hdr = mem + sz;
297*ba7866cdSAli Bahrami 		if (a->ar_name[1] == ' ') {	/* 32-bit symbol table */
2987c478bd9Sstevel@tonic-gate 			elf->ed_arsym = mem;
2997c478bd9Sstevel@tonic-gate 			elf->ed_arsymsz = sz;
3007c478bd9Sstevel@tonic-gate 			elf->ed_arsymoff = (char *)a - base;
3017c478bd9Sstevel@tonic-gate 		} else if (a->ar_name[1] == '/' && a->ar_name[2] == ' ') {
302*ba7866cdSAli Bahrami 						/* Long name string table */
3037c478bd9Sstevel@tonic-gate 			int	k;
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 			if (_elf_vm(elf, (size_t)(mem - elf->ed_ident),
3067c478bd9Sstevel@tonic-gate 			    sz) != OK_YES)
3077c478bd9Sstevel@tonic-gate 				return;
3087c478bd9Sstevel@tonic-gate 			if (elf->ed_vm == 0) {
3097c478bd9Sstevel@tonic-gate 				char	*nmem;
3107c478bd9Sstevel@tonic-gate 				if ((nmem = malloc(sz)) == 0) {
3117c478bd9Sstevel@tonic-gate 					_elf_seterr(EMEM_ARSTR, errno);
3127c478bd9Sstevel@tonic-gate 					return;
3137c478bd9Sstevel@tonic-gate 				}
3147c478bd9Sstevel@tonic-gate 				(void) memcpy(nmem, mem, sz);
3157c478bd9Sstevel@tonic-gate 				elf->ed_myflags |= EDF_ASTRALLOC;
3167c478bd9Sstevel@tonic-gate 				mem = nmem;
3177c478bd9Sstevel@tonic-gate 			}
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 			elf->ed_arstr = mem;
3207c478bd9Sstevel@tonic-gate 			elf->ed_arstrsz = sz;
3217c478bd9Sstevel@tonic-gate 			elf->ed_arstroff = (char *)a - base;
3227c478bd9Sstevel@tonic-gate 			for (k = 0; k < sz; k++) {
3237c478bd9Sstevel@tonic-gate 				if (*mem == '/')
3247c478bd9Sstevel@tonic-gate 					*mem = '\0';
3257c478bd9Sstevel@tonic-gate 				++mem;
3267c478bd9Sstevel@tonic-gate 			}
3277c478bd9Sstevel@tonic-gate 			*(mem - 1) = '\0';
328*ba7866cdSAli Bahrami 		} else if (a->ar_name[1] == 'S' && a->ar_name[2] == 'Y' &&
329*ba7866cdSAli Bahrami 		    a->ar_name[3] == 'M' && a->ar_name[4] == '6' &&
330*ba7866cdSAli Bahrami 		    a->ar_name[5] == '4' && a->ar_name[6] == '/' &&
331*ba7866cdSAli Bahrami 		    a->ar_name[7] == ' ') {
332*ba7866cdSAli Bahrami 						/* 64-bit symbol table */
333*ba7866cdSAli Bahrami 			elf->ed_arsym = mem;
334*ba7866cdSAli Bahrami 			elf->ed_arsymsz = sz;
335*ba7866cdSAli Bahrami 			elf->ed_arsymoff = (char *)a - base;
336*ba7866cdSAli Bahrami 			elf->ed_myflags |= EDF_ARSYM64;
3377c478bd9Sstevel@tonic-gate 		} else {
3387c478bd9Sstevel@tonic-gate 			return;
3397c478bd9Sstevel@tonic-gate 		}
3407c478bd9Sstevel@tonic-gate 		hdr += sz & 1;
3417c478bd9Sstevel@tonic-gate 	}
3427c478bd9Sstevel@tonic-gate }
343