xref: /titanic_50/usr/src/cmd/sgs/libconv/common/relocate_amd64.c (revision fa9e4066f08beec538e775443c5be79dd423fcab)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * String conversion routine for relocation types.
30  */
31 #include	<stdio.h>
32 #include	<sys/elf_amd64.h>
33 #include	"_conv.h"
34 #include	"relocate_amd64_msg.h"
35 
36 /*
37  * Intel386 specific relocations.
38  */
39 static const Msg rels[] = {
40 	MSG_R_AMD64_NONE,
41 	MSG_R_AMD64_64,
42 	MSG_R_AMD64_PC32,
43 	MSG_R_AMD64_GOT32,
44 	MSG_R_AMD64_PLT32,
45 	MSG_R_AMD64_COPY,
46 	MSG_R_AMD64_GLOB_DATA,
47 	MSG_R_AMD64_JUMP_SLOT,
48 	MSG_R_AMD64_RELATIVE,
49 	MSG_R_AMD64_GOTPCREL,
50 	MSG_R_AMD64_32,
51 	MSG_R_AMD64_32S,
52 	MSG_R_AMD64_16,
53 	MSG_R_AMD64_PC16,
54 	MSG_R_AMD64_8,
55 	MSG_R_AMD64_PC8,
56 	MSG_R_AMD64_DTPMOD64,
57 	MSG_R_AMD64_DTPOFF64,
58 	MSG_R_AMD64_TPOFF64,
59 	MSG_R_AMD64_TLSGD,
60 	MSG_R_AMD64_TLSLD,
61 	MSG_R_AMD64_DTPOFF32,
62 	MSG_R_AMD64_GOTTPOFF,
63 	MSG_R_AMD64_TPOFF32,
64 	MSG_R_AMD64_PC64,
65 	MSG_R_AMD64_GOTOFF64,
66 	MSG_R_AMD64_GOTPC32
67 };
68 
69 const char *
70 conv_reloc_amd64_type_str(uint_t rel)
71 {
72 	static char	string[STRSIZE] = { '\0' };
73 
74 	/*
75 	 * In order to assure that all values included in
76 	 * sys/elf_x86_64.h::R_AMD64_* are included in libconv/elfdump for
77 	 * decoding - we have the below #define trap.  Each time the rels[]
78 	 * table is updated, make sure the following entry is updated.
79 	 */
80 
81 #if	(R_AMD64_NUM != (R_AMD64_GOTPC32 + 1))
82 #error	"R_AMD64_NUM has grown"
83 #endif
84 
85 	if (rel >= R_AMD64_NUM)
86 		return (conv_invalid_str(string, STRSIZE, (Lword)rel, 0));
87 	else
88 		return (MSG_ORIG(rels[rel]));
89 }
90