clscook.c revision 98cadd320d4521e7438bc624f89adef498589add
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* This stuff used to live in cook.c, but was moved out to
* facilitate dual (Elf32 and Elf64) compilation. See block
* comment in cook.c for more info.
*/
#include <string.h>
#include <ar.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/sysmacros.h>
#include "decl.h"
#include "member.h"
#include "msg.h"
/*
* This module is compiled twice, the second time having
* -D_ELF64 defined. The following set of macros, along
* with machelf.h, represent the differences between the
* two compilations. Be careful *not* to add any class-
* dependent code (anything that has elf32 or elf64 in the
* name) to this code without hiding it behind a switch-
* able macro like these.
*/
#if defined(_ELF64)
#define ELFCLASS ELFCLASS64
#define _elf_snode_init _elf64_snode_init
#define _elf_prepscan _elf64_prepscan
#define _elf_cookscn _elf64_cookscn
#define _elf_mtype _elf64_mtype
#define _elf_msize _elf64_msize
#define elf_fsize elf64_fsize
#define _elf_snode _elf64_snode
#define _elf_ehdr _elf64_ehdr
#define elf_xlatetom elf64_xlatetom
#define _elf_phdr _elf64_phdr
#define _elf_shdr _elf64_shdr
#define _elf_prepscn _elf64_prepscn
#else /* Elf32 */
#define ELFCLASS ELFCLASS32
#define _elf_snode_init _elf32_snode_init
#define _elf_prepscan _elf32_prepscan
#define _elf_cookscn _elf32_cookscn
#define _elf_mtype _elf32_mtype
#define _elf_msize _elf32_msize
#define elf_fsize elf32_fsize
#define _elf_snode _elf32_snode
#define _elf_ehdr _elf32_ehdr
#define elf_xlatetom elf32_xlatetom
#define _elf_phdr _elf32_phdr
#define _elf_shdr _elf32_shdr
#define _elf_prepscn _elf32_prepscn
#endif /* _ELF64 */
static Okay
{
Elf_Scn * s;
if (cnt == 0)
return (OK_YES);
return (OK_NO);
}
do {
*s = _elf_snode_init.sb_scn;
s->s_next = s + 1;
ELFMUTEXINIT(&s->s_mutex);
/*
* Section has not yet been cooked!
*
* We don't cook a section until it's data is actually
* referenced.
*/
s->s_myflags = 0;
} while (++s < end);
s->s_next = 0;
/*
* Section index SHN_UNDEF (0) does not and cannot
* have a data buffer. Fix it here. Also mark the
* initial section as being allocated for the block
*/
s->s_hdnode = 0;
s->s_tlnode = 0;
return (OK_YES);
}
_elf_cookscn(Elf_Scn * s)
{
unsigned work;
s->s_err = 0;
s->s_shflags = 0;
s->s_uflags = 0;
/*
* Prepare d_data for inspection, but don't actually
* translate data until needed. Leave the READY
* flag off. NOBITS sections see zero size.
*/
d->db_scn = s;
d->db_raw = 0;
d->db_buf = 0;
d->db_uflags = 0;
d->db_myflags = 0;
d->db_next = 0;
else
d->db_fsz = 0;
return (OK_YES);
}
Snode *
{
register Snode *s;
return (0);
}
*s = _elf_snode_init;
return (s);
}
int
{
_elf_seterr(EFMT_EHDRSZ, 0);
return (-1);
}
/*
* The translated Ehdr will fit over the original Ehdr.
*/
/* LINTED */
} else {
return (-1);
}
}
/*
* Memory size >= fsz, because otherwise the memory version
* loses information and cannot accurately implement the
* file.
*/
}
return (-1);
}
_elf_seterr(EREQ_CLASS, 0);
}
return (-1);
}
_elf_seterr(EFMT_VER2, 0);
}
return (-1);
}
return (0);
}
int
{
unsigned work;
return (0);
_elf_seterr(EFMT_PHDRSZ, 0);
return (-1);
}
_elf_seterr(EFMT_PHTAB, 0);
return (-1);
}
} else {
return (-1);
}
}
}
return (-1);
}
return (0);
}
int
{
return (0);
_elf_seterr(EFMT_SHDRSZ, 0);
return (-1);
}
/*
* If we are dealing with a file with 'extended section
* indexes' - then we need to load the first section
* header. The actual section count is stored in
* Shdr[0].sh_size.
*/
_elf_seterr(EFMT_SHTAB, 0);
return (-1);
}
return (-1);
}
}
_elf_seterr(EFMT_SHTAB, 0);
return (-1);
}
/* LINTED */
} else {
return (-1);
}
}
}
return (-1);
}
return (0);
}