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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * String conversion routine for relocation types.
29  */
30 #include	<stdio.h>
31 #include	<sys/elf_amd64.h>
32 #include	"relocate_amd64_msg.h"
33 #include	"_conv.h"
34 
35 /*
36  * AMD64 specific relocations.
37  */
38 static const Msg rels[R_AMD64_NUM] = {
39 	[R_AMD64_NONE]		= MSG_R_AMD64_NONE,
40 	[R_AMD64_64]		= MSG_R_AMD64_64,
41 	[R_AMD64_PC32]		= MSG_R_AMD64_PC32,
42 	[R_AMD64_GOT32]		= MSG_R_AMD64_GOT32,
43 	[R_AMD64_PLT32]		= MSG_R_AMD64_PLT32,
44 	[R_AMD64_COPY]		= MSG_R_AMD64_COPY,
45 	[R_AMD64_GLOB_DAT]	= MSG_R_AMD64_GLOB_DAT,
46 	[R_AMD64_JUMP_SLOT]	= MSG_R_AMD64_JUMP_SLOT,
47 	[R_AMD64_RELATIVE]	= MSG_R_AMD64_RELATIVE,
48 	[R_AMD64_GOTPCREL]	= MSG_R_AMD64_GOTPCREL,
49 	[R_AMD64_32]		= MSG_R_AMD64_32,
50 	[R_AMD64_32S]		= MSG_R_AMD64_32S,
51 	[R_AMD64_16]		= MSG_R_AMD64_16,
52 	[R_AMD64_PC16]		= MSG_R_AMD64_PC16,
53 	[R_AMD64_8]		= MSG_R_AMD64_8,
54 	[R_AMD64_PC8]		= MSG_R_AMD64_PC8,
55 	[R_AMD64_DTPMOD64]	= MSG_R_AMD64_DTPMOD64,
56 	[R_AMD64_DTPOFF64]	= MSG_R_AMD64_DTPOFF64,
57 	[R_AMD64_TPOFF64]	= MSG_R_AMD64_TPOFF64,
58 	[R_AMD64_TLSGD]		= MSG_R_AMD64_TLSGD,
59 	[R_AMD64_TLSLD]		= MSG_R_AMD64_TLSLD,
60 	[R_AMD64_DTPOFF32]	= MSG_R_AMD64_DTPOFF32,
61 	[R_AMD64_GOTTPOFF]	= MSG_R_AMD64_GOTTPOFF,
62 	[R_AMD64_TPOFF32]	= MSG_R_AMD64_TPOFF32,
63 	[R_AMD64_PC64]		= MSG_R_AMD64_PC64,
64 	[R_AMD64_GOTOFF64]	= MSG_R_AMD64_GOTOFF64,
65 	[R_AMD64_GOTPC32]	= MSG_R_AMD64_GOTPC32,
66 	[R_AMD64_GOT64]		= MSG_R_AMD64_GOT64,
67 	[R_AMD64_GOTPCREL64]	= MSG_R_AMD64_GOTPCREL64,
68 	[R_AMD64_GOTPC64]	= MSG_R_AMD64_GOTPC64,
69 	[R_AMD64_GOTPLT64]	= MSG_R_AMD64_GOTPLT64,
70 	[R_AMD64_PLTOFF64]	= MSG_R_AMD64_PLTOFF64,
71 	[R_AMD64_SIZE32]	= MSG_R_AMD64_SIZE32,
72 	[R_AMD64_SIZE64]	= MSG_R_AMD64_SIZE64,
73 	[R_AMD64_GOTPC32_TLSDESC] = MSG_R_AMD64_GOTPC32_TLSDESC,
74 	[R_AMD64_TLSDESC_CALL]	= MSG_R_AMD64_TLSDESC_CALL,
75 	[R_AMD64_TLSDESC]	= MSG_R_AMD64_TLSDESC,
76 	[R_AMD64_IRELATIVE]	= MSG_R_AMD64_IRELATIVE,
77 	[R_AMD64_RELATIVE64]	= MSG_R_AMD64_RELATIVE64,
78 	[R_AMD64_UNKNOWN39]	= MSG_R_AMD64_UNKNOWN39,
79 	[R_AMD64_UNKNOWN40]	= MSG_R_AMD64_UNKNOWN40,
80 	[R_AMD64_GOTPCRELX]	= MSG_R_AMD64_GOTPCRELX,
81 	[R_AMD64_REX_GOTPCRELX] = MSG_R_AMD64_REX_GOTPCRELX
82 };
83 
84 #if	(R_AMD64_NUM != (R_AMD64_REX_GOTPCRELX + 1))
85 #error	"R_AMD64_NUM has grown"
86 #endif
87 
88 const char *
conv_reloc_amd64_type(Word type,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)89 conv_reloc_amd64_type(Word type, Conv_fmt_flags_t fmt_flags,
90     Conv_inv_buf_t *inv_buf)
91 {
92 	if (type >= R_AMD64_NUM)
93 		return (conv_invalid_val(inv_buf, type, fmt_flags));
94 	return (MSG_ORIG(rels[type]));
95 }
96