elf_read.c revision c2c65e21c1fd025c3fc6103cc713dd5343fc9ad6
/*
* 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) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1987, 1988 Microsoft Corporation */
/* All Rights Reserved */
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define _LARGEFILE64_SOURCE
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <libelf.h>
#include <stdlib.h>
#include <limits.h>
#include <locale.h>
#include <string.h>
#include <errno.h>
#include <procfs.h>
#include <elfcap.h>
#include "file.h"
#include "elf_read.h"
extern const char *File;
static int get_class(void);
static int get_version(void);
static int get_format(void);
static int process_shdr(Elf_Info *);
static int process_phdr(Elf_Info *);
static int file_xlatetom(Elf_Type, char *);
static int xlatetom_nhdr(Elf_Nhdr *);
static int
get_class(void)
{
}
static int
get_version(void)
{
/* do as what libelf:_elf_config() does */
}
static int
get_format(void)
{
}
/*
* file_xlatetom: translate different headers from file
* representation to memory representaion.
*/
#define HDRSZ 512
static int
{
version = get_version();
format = get_format();
/* will convert only these types */
return (ELF_READ_FAIL);
return (ELF_READ_FAIL);
return (ELF_READ_OKAY);
}
/*
* xlatetom_nhdr: There is no routine to convert Note header
* so we convert each field of this header.
*/
static int
{
int r = ELF_READ_FAIL;
return (r);
}
/*
* elf_read: reads elf header, program, section headers to
* collect all information needed for file(1)
* output and stores them in Elf_Info.
*/
int
{
int ret = 1;
ret = 0;
ret = 0;
return (ELF_READ_FAIL);
if (ret == 0) {
return (ELF_READ_FAIL);
}
return (ELF_READ_FAIL);
/* We don't need section info for core files */
return (ELF_READ_FAIL);
return (ELF_READ_OKAY);
}
/*
* get_phdr: reads program header of specified index.
*/
static int
{
return (ELF_READ_FAIL);
return (ELF_READ_FAIL);
return (ELF_READ_FAIL);
return (ELF_READ_OKAY);
}
/*
* get_shdr: reads section header of specified index.
*/
static int
{
return (ELF_READ_FAIL);
return (ELF_READ_FAIL);
return (ELF_READ_FAIL);
return (ELF_READ_OKAY);
}
/*
* process_phdr: Read Program Headers and see if it is a core
* file of either new or (pre-restructured /proc)
* type, read the name of the file that dumped this
* core, else see if this is a dynamically linked.
*/
static int
{
register int inx;
int class;
int ntype;
return (ELF_READ_FAIL);
/* read the note if it is a core */
/*
* If the next segment is also a note, use it instead.
*/
return (ELF_READ_FAIL);
/* read the first phdr back */
return (ELF_READ_FAIL);
}
!= nsz)
return (ELF_READ_FAIL);
/* Translate the ELF note header */
return (ELF_READ_FAIL);
exit(1);
}
return (ELF_READ_FAIL);
/*
* We want to print the string contained
* in psinfo->pr_fname[], where 'psinfo'
* is either an old NT_PRPSINFO structure
* or a new NT_PSINFO structure.
*
* Old core files have only type NT_PRPSINFO.
* New core files have type NT_PSINFO.
*
* These structures are also different by
* virtue of being contained in a core file
* of either 32-bit or 64-bit type.
*
* To further complicate matters, we ourself
* might be compiled either 32-bit or 64-bit.
*
* For these reason, we just *know* the offsets of
* pr_fname[] into the four different structures
* here, regardless of how we are compiled.
*/
if (class == ELFCLASS32) {
/* 32-bit core file, 32-bit structures */
else /* old: NT_PRPSINFO */
} else if (class == ELFCLASS64) {
/* 64-bit core file, 64-bit structures */
else /* old: NT_PRPSINFO */
}
}
}
}
return (ELF_READ_OKAY);
}
/*
* capabilities by looking at the SUNW_cap
* section and set string in Elf_Info.
* Also look for symbol tables and debug
* information sections. Set the "stripped" field
* in Elf_Info with corresponding flags.
*/
static int
{
int i, j, idx;
char *section_name;
/* if there are no sections, return success anyway */
return (ELF_READ_OKAY);
/* read section names from String Section */
return (ELF_READ_FAIL);
return (ELF_READ_FAIL);
return (ELF_READ_FAIL);
/* read all the sections and process them */
char *str;
return (ELF_READ_FAIL);
idx--;
continue;
}
return (ELF_READ_FAIL);
}
for (j = 0; j < capn; j++) {
/*
* read cap and xlate the values
*/
!= csize ||
== 0) {
return (ELF_READ_FAIL);
}
0, mac);
}
}
}
/*
* Definition time:
* - "not stripped" means that an executable file
* contains a Symbol Table (.symtab)
* - "stripped" means that an executable file
* does not contain a Symbol Table.
* When strip -l or strip -x is run, it strips the
* debugging information (.line section name (strip -l),
* .line, .debug*, .stabs*, .dwarf* section names
* and SHT_SUNW_DEBUGSTR and SHT_SUNW_DEBUG
* section types (strip -x), however the Symbol
* Table will still be present.
* Therefore, if
* - No Symbol Table present, then report
* "stripped"
* - Symbol Table present with debugging
* information (line number or debug section names,
* or SHT_SUNW_DEBUGSTR or SHT_SUNW_DEBUG section
* types) then report:
* "not stripped"
* - Symbol Table present with no debugging
* information (line number or debug section names,
* or SHT_SUNW_DEBUGSTR or SHT_SUNW_DEBUG section
* types) then report:
* "not stripped, no debugging information
* available"
*/
continue;
continue;
}
(is_in_list(str)))) {
}
}
return (ELF_READ_OKAY);
}