xref: /illumos-gate/usr/src/uts/intel/amd64/krtld/kobj_convrelstr.c (revision 1b863af9bc9a5c76ed773e129889fc19dbf9e41c)
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 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include	<sys/types.h>
28 #include	"reloc.h"
29 
30 static const char	*rels[R_AMD64_NUM] = {
31 	[R_AMD64_NONE]		= "R_AMD64_NONE",
32 	[R_AMD64_64]		= "R_AMD64_64",
33 	[R_AMD64_PC32]		= "R_AMD64_PC32",
34 	[R_AMD64_GOT32]		= "R_AMD64_GOT32",
35 	[R_AMD64_PLT32]		= "R_AMD64_PLT32",
36 	[R_AMD64_COPY]		= "R_AMD64_COPY",
37 	[R_AMD64_GLOB_DAT]	= "R_AMD64_GLOB_DAT",
38 	[R_AMD64_JUMP_SLOT]	= "R_AMD64_JUMP_SLOT",
39 	[R_AMD64_RELATIVE]	= "R_AMD64_RELATIVE",
40 	[R_AMD64_GOTPCREL]	= "R_AMD64_GOTPCREL",
41 	[R_AMD64_32]		= "R_AMD64_32",
42 	[R_AMD64_32S]		= "R_AMD64_32S",
43 	[R_AMD64_16]		= "R_AMD64_16",
44 	[R_AMD64_PC16]		= "R_AMD64_PC16",
45 	[R_AMD64_8]		= "R_AMD64_8",
46 	[R_AMD64_PC8]		= "R_AMD64_PC8",
47 	[R_AMD64_DTPMOD64]	= "R_AMD64_DTPMOD64",
48 	[R_AMD64_DTPOFF64]	= "R_AMD64_DTPOFF64",
49 	[R_AMD64_TPOFF64]	= "R_AMD64_TPOFF64",
50 	[R_AMD64_TLSGD]		= "R_AMD64_TLSGD",
51 	[R_AMD64_TLSLD]		= "R_AMD64_TLSLD",
52 	[R_AMD64_DTPOFF32]	= "R_AMD64_DTPOFF32",
53 	[R_AMD64_GOTTPOFF]	= "R_AMD64_GOTTPOFF",
54 	[R_AMD64_TPOFF32]	= "R_AMD64_TPOFF32",
55 	[R_AMD64_PC64]		= "R_AMD64_PC64",
56 	[R_AMD64_GOTOFF64]	= "R_AMD64_GOTOFF64",
57 	[R_AMD64_GOTPC32]	= "R_AMD64_GOTPC32",
58 	[R_AMD64_GOT64]		= "R_AMD64_GOT64",
59 	[R_AMD64_GOTPCREL64]	= "R_AMD64_GOTPCREL64",
60 	[R_AMD64_GOTPC64]	= "R_AMD64_GOTPC64",
61 	[R_AMD64_GOTPLT64]	= "R_AMD64_GOTPLT64",
62 	[R_AMD64_PLTOFF64]	= "R_AMD64_PLTOFF64",
63 	[R_AMD64_SIZE32]	= "R_AMD64_SIZE32",
64 	[R_AMD64_SIZE64]	= "R_AMD64_SIZE64",
65 	[R_AMD64_GOTPC32_TLSDESC] = "R_AMD64_GOTPC32_TLSDESC",
66 	[R_AMD64_TLSDESC_CALL]	= "R_AMD64_TLSDESC_CALL",
67 	[R_AMD64_TLSDESC]	= "R_AMD64_TLSDESC",
68 	[R_AMD64_IRELATIVE]	= "R_AMD64_IRELATIVE",
69 	[R_AMD64_RELATIVE64]	= "R_AMD64_RELATIVE64",
70 	[R_AMD64_UNKNOWN39]	= "R_AMD64_UNKNOWN39",
71 	[R_AMD64_UNKNOWN40]	= "R_AMD64_UNKNOWN40",
72 	[R_AMD64_GOTPCRELX]	= "R_AMD64_GOTPCRELX",
73 	[R_AMD64_REX_GOTPCRELX]	= "R_AMD64_REX_GOTPCRELX",
74 };
75 
76 #if	(R_AMD64_NUM != (R_AMD64_REX_GOTPCRELX + 1))
77 #error	"R_AMD64_NUM has grown"
78 #endif
79 
80 /*
81  * This is a 'stub' of the orignal version defined in liblddbg.so.  This stub
82  * returns the 'int string' of the relocation in question instead of converting
83  * the relocation to it's full syntax.
84  */
85 const char *
86 conv_reloc_amd64_type(Word type)
87 {
88 	static char	strbuf[32];
89 	int		ndx = 31;
90 
91 	if (type < R_AMD64_NUM)
92 		return (rels[type]);
93 
94 	strbuf[ndx--] = '\0';
95 	do {
96 		strbuf[ndx--] = '0' + (type % 10);
97 		type = type / 10;
98 	} while ((ndx >= (int)0) && (type > (Word)0));
99 
100 	return (&strbuf[ndx + 1]);
101 }
102