/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Routines for preparing tdata trees for conversion into CTF data, and
* for placing the resulting data into an output file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <fcntl.h>
#include <libelf.h>
#include <gelf.h>
#include <unistd.h>
#include "ctftools.h"
#include "list.h"
#include "memory.h"
#include "traverse.h"
#include "symbol.h"
typedef struct iidesc_match {
int iim_fuzzy;
char *iim_name;
char *iim_file;
static int
{
case II_GFUN:
case II_SFUN:
case II_GVAR:
case II_SVAR:
return (0);
break;
default:
break;
}
return (1);
}
/*ARGSUSED1*/
static int
{
/*
* Doing this on every node is horribly inefficient, but given that
* we may be suppressing some types, we can't trust nextid in the
* tdata_t.
*/
return (1);
}
NULL,
save_type_by_id, /* intrinsic */
save_type_by_id, /* pointer */
save_type_by_id, /* array */
save_type_by_id, /* function */
save_type_by_id, /* struct */
save_type_by_id, /* union */
save_type_by_id, /* enum */
save_type_by_id, /* forward */
save_type_by_id, /* typedef */
tdtrav_assert, /* typedef_unres */
save_type_by_id, /* volatile */
save_type_by_id, /* const */
save_type_by_id /* restrict */
};
static iiburst_t *
{
iiburst->iib_nfuncs = 0;
iiburst->iib_nobjts = 0;
return (iiburst);
}
static void
{
}
static void
{
}
/*
* See if this iidesc matches the ELF symbol data we pass in.
*
* A fuzzy match is where we have a local symbol matching the name of a
* global type description. This is common when a mapfile is used for a
* DSO, but we don't accept it by default.
*
* A weak fuzzy match is when a weak symbol was resolved and matched to
* a global type description.
*/
static int
{
return (0);
case II_GFUN:
case II_GVAR:
return (-1);
/* continue to look for strong match */
return (0);
}
break;
case II_SFUN:
case II_SVAR:
return (-1);
}
break;
}
return (0);
}
static iidesc_t *
{
(int (*)())matching_iidesc, match);
}
/*
* If we have a weak symbol, attempt to find the strong symbol it will
* resolve to. Note: the code where this actually happens is in
*
* Finding the matching symbol is unfortunately not trivial. For a
* symbol to be a candidate, it must:
*
* - have the same type (function, object)
* - have the same value (address)
* - have the same size
* - not be another weak symbol
* - belong to the same section (checked via section index)
*
* If such a candidate is global, then we assume we've found it. The
* linker generates the symbol table such that the curfile might be
* incorrect; this is OK for global symbols, since find_iidesc() doesn't
* need to check for the source file for the symbol.
*
* We might have found a strong local symbol, where the curfile is
* accurate and matches that of the weak symbol. We assume this is a
* reasonable match.
*
* If we've got a local symbol with a non-matching curfile, there are
* two possibilities. Either this is a completely different symbol, or
* it's a once-global symbol that was scoped to local via a mapfile. In
* the latter case, curfile is likely inaccurate since the linker does
* not preserve the needed curfile in the order of the symbol table (see
* the comments about locally scoped symbols in libld's update_osym()).
* As we can't tell this case from the former one, we use this symbol
* iff no other matching symbol is found.
*
* What we really need here is a SUNW section containing weak<->strong
* mappings that we can consume.
*/
static int
{
char *tmpfile;
int candidate = 0;
int i;
return (0);
for (i = 0; i < nent; i++) {
continue;
continue;
continue;
continue;
continue;
candidate = 1;
continue;
}
return (1);
}
if (candidate) {
return (1);
}
return (0);
}
/*
* When we've found the underlying symbol's type description
* for a weak symbol, we need to copy it and rename it to match
* the weak symbol. We also need to add it to the td so it's
* handled along with the others later.
*/
static iidesc_t *
{
switch (type) {
case STT_OBJECT:
break;
case STT_FUNC:
break;
}
return (new);
}
/*
* Process the symbol table of the output file, associating each symbol
* with a type description if possible, and sorting them into functions
* and data, maintaining symbol table order.
*/
static iiburst_t *
int dynsym)
{
int i, stidx;
int nent;
for (i = 0; i < nent; i++) {
int *curr;
case STT_FILE:
continue;
case STT_OBJECT:
break;
case STT_FUNC:
break;
default:
continue;
}
continue;
(*curr)++;
continue;
}
(*curr)++;
continue;
}
}
(*curr)++;
}
/*
* Stabs are generated for every function declared in a given C source
* file. When converting an object file, we may encounter a stab that
* has no symbol table entry because the optimizer has decided to omit
* that item (for example, an unreferenced static function). We may
* see iidescs that do not have an associated symtab entry, and so
* we do not write records for those functions into the CTF data.
* All others get marked as a root by this function.
*/
/*
* caused some types that were referenced solely by those
* generated prior to the evisceration, to be incorrect. Find the
* highest type index, and change the label indicies to be no higher
* than this value.
*/
return (iiburst);
}
static void
{
int *secxlate;
int curnmoff = 0;
int changing = 0;
int pad;
int i;
/*
* Neither the existing stab sections nor the SUNW_ctf sections (new or
* existing) are SHF_ALLOC'd, so they won't be in areas referenced by
* program headers. As such, we can just blindly copy the program
* headers from the existing file to the new file.
*/
}
}
char *sname;
}
/*
* If we're building CTF against the dynsym,
* we'll rip out the symtab so debuggers aren't
* confused.
*/
} else {
}
}
char *sname;
changing = 1;
continue;
}
/*
* If this file has program headers, we need to explicitly lay
* out sections. If none of the sections prior to this one have
* been removed, then we can just use the existing location. If
* one or more sections have been changed, then we need to
* adjust this one to avoid holes.
*/
if (pad)
}
}
seclen + 1);
changing = 1;
}
for (i = 0; i < nsym; i++) {
short newscn;
continue;
}
}
}
}
if (symtab_idx == -1) {
}
/* Add the ctf section */
if (pad)
}
/* update the section header location */
if (r)
new_offset += align - r;
}
/* commit to disk */
}
static caddr_t
{
flags & CTF_USE_DYNSYM);
return (data);
}
void
{
(void) elf_version(EV_CURRENT);
}