xref: /netbsd-src/external/cddl/osnet/dist/tools/ctf/common/symbol.c (revision 89300bd9df17b74e8b6eaccab1411408c4acfe01)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #if HAVE_NBTOOL_CONFIG_H
30 # include "nbtool_config.h"
31 #endif
32 
33 #include <sys/types.h>
34 #include <string.h>
35 
36 #include "symbol.h"
37 
38 int
ignore_symbol(GElf_Sym * sym,const char * name)39 ignore_symbol(GElf_Sym *sym, const char *name)
40 {
41 	uchar_t type = GELF_ST_TYPE(sym->st_info);
42 
43 	/*
44 	 * As an optimization, we do not output function or data object
45 	 * records for undefined or anonymous symbols.
46 	 */
47 	if (sym->st_shndx == SHN_UNDEF || sym->st_name == 0)
48 		return (1);
49 
50 	/*
51 	 * _START_ and _END_ are added to the symbol table by the
52 	 * linker, and will never have associated type information.
53 	 */
54 	if (strcmp(name, "_START_") == 0 || strcmp(name, "_END_") == 0)
55 		return (1);
56 
57 	/*
58 	 * Do not output records for absolute-valued object symbols
59 	 * that have value zero.  The compiler insists on generating
60 	 * things like this for __fsr_init_value settings, etc.
61 	 */
62 	if (type == STT_OBJECT && sym->st_shndx == SHN_ABS &&
63 	    sym->st_value == 0)
64 		return (1);
65 	return (0);
66 }
67