/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Copyright (c) 1988 AT&T
* All Rights Reserved
*/
#include <ar.h>
#include <stdlib.h>
#include <memory.h>
#include <errno.h>
#include <libelf.h>
#include "decl.h"
#include "msg.h"
#include "member.h"
/*
* Archive processing
* When processing an archive member, two things can happen
* that are a little tricky.
*
* Sliding
* Sliding support is left in for backward compatibility and for
* support of Archives produced on other systems. The bundled
* ar(1) produces archives with all members on a 4 byte boundry,
* so current archives should need no sliding.
*
* Archive members that are only 2-byte aligned within the file will
* be slid. To reuse the file's memory image, the library slides an
* archive member into its header to align the bytes. This means
* the header must be disposable.
*
* Header reuse
* Because the library can trample the header, it must be preserved to
* avoid restrictions on archive member reuse. That is, if the member
* header changes, the library may see garbage the next time it looks
* at the header. After extracting the original header, the library
* appends it to the parents `ed_memlist' list, thus future lookups first
* check this list to determine if a member has previously been processed
* and whether sliding occured.
*/
/*
* Size check
* If the header is too small, the following generates a negative
* subscript for x.x and fails to compile.
*
* The check is based on sizeof (Elf64) because that's always going
* to be at least as big as Elf32.
*/
struct x
{
};
/*
* Convert a string starting at 'p' and ending at 'end' into
* an integer. Base is the base of the number being converted
* (either 8 or 10).
*
* Returns the converted integer of the string being scaned.
*/
unsigned long
{
register unsigned c;
register unsigned long n = 0;
while (p < end) {
if ((c = *p - '0') >= base) {
while (*p++ == ' ')
if (p >= end)
return (n);
return (0);
}
n *= base;
n += c;
++p;
}
return (n);
}
/*
* Convert ar_hdr to Member
* Converts ascii file representation to the binary memory values.
*/
Member *
{
register Member *m;
register Memident *i;
_elf_seterr(EFMT_ARHDRSZ, 0);
return (0);
}
/*
* Determine in this member has already been processed
*/
return (i->m_member);
_elf_seterr(EFMT_ARFMAG, 0);
return (0);
}
/*
* Allocate a new member structure and assign it to the next free
* free memlist ident.
*/
return (0);
}
(sizeof (Memident) * MEMIDENTNO))) == 0) {
return (0);
}
l->m_next = 0;
(sizeof (Memident) * MEMIDENTNO));
if (elf->ed_memlist == 0)
elf->ed_memlist = l;
else
ol = l;
}
m->m_err = 0;
m->m_slide = 0;
/*
* Classify file name.
* If a name error occurs, delay until getarhdr().
*/
register char *p;
while (*--p != '/')
if (p <= m->m_name)
break;
*p = '\0';
register unsigned long j;
if (j < elf->ed_arstrsz)
else {
/*LINTED*/ /* MSG_INTL(EFMT_ARSTRNM) */
m->m_err = (int)EFMT_ARSTRNM;
}
else { /* "/?" */
/*LINTED*/ /* MSG_INTL(EFMT_ARUNKNM) */
m->m_err = (int)EFMT_ARUNKNM;
}
/* LINTED */
/* LINTED */
/* LINTED */
return (m);
}
/*
* Initial archive processing
* An archive may have two special members.
*
* A symbol table, named / or /SYM64/, must be first if it is present.
* Both forms use the same layout differing in the width of the
* integer type used (32 or 64-bit respectively).
*
* A long name string table, named //, must precede all "normal"
* members. This string table is used to hold the names of archive
* members with names that are longer than 15 characters. It should not
* be confused with the string table found at the end of the symbol
* table, which is used to hold symbol names.
*
* This code "peeks" at headers but doesn't change them.
* Later processing wants original headers.
*
* String table is converted, changing '/' name terminators
* to nulls. The last byte in the string table, which should
* be '\n', is set to nil, guaranteeing null termination. That
* byte should be '\n', but this code doesn't check.
*
* The symbol table conversion is delayed until needed.
*/
void
{
register struct ar_hdr *a;
register char *mem;
int j;
for (j = 0; j < 2; ++j) { /* 2 special members */
unsigned long n;
return;
((sz = n) != n)) {
return;
}
/* Long name string table */
int k;
return;
char *nmem;
return;
}
}
for (k = 0; k < sz; k++) {
if (*mem == '/')
*mem = '\0';
++mem;
}
/* 64-bit symbol table */
} else {
return;
}
}
}