blob: 38d357cb781df992e79f55840ee7ad109401878c [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* x86_64 specific symbolic name handling.
2 Copyright (C) 2002, 2005 Red Hat, Inc.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4
5 This program is Open Source software; you can redistribute it and/or
6 modify it under the terms of the Open Software License version 1.0 as
7 published by the Open Source Initiative.
8
9 You should have received a copy of the Open Software License along
10 with this program; if not, you may obtain a copy of the Open Software
11 License version 1.0 from http://www.opensource.org/licenses/osl.php or
12 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13 3001 King Ranch Road, Ukiah, CA 95482. */
14
15#ifdef HAVE_CONFIG_H
16# include <config.h>
17#endif
18
19#include <assert.h>
20#include <elf.h>
21#include <stddef.h>
22
23#include <libebl_x86_64.h>
24
25
26/* Return of the backend. */
27const char *
28x86_64_backend_name (void)
29{
30 return "x86-64";
31}
32
33
34/* Relocation mapping table. */
35static struct
36{
37 const char *name;
38 enum { both = 0, rel = 1, exec = 2 } appear;
39} reloc_map_table[] =
40 {
41 [R_X86_64_NONE] = { "R_X86_64_NONE", both },
42 [R_X86_64_64] = { "R_X86_64_64", both },
43 [R_X86_64_PC32] = { "R_X86_64_PC32", rel },
44 [R_X86_64_GOT32] = { "R_X86_64_GOT32", rel },
45 [R_X86_64_PLT32] = { "R_X86_64_PLT32", rel },
46 [R_X86_64_COPY] = { "R_X86_64_COPY", exec },
47 [R_X86_64_GLOB_DAT] = { "R_X86_64_GLOB_DAT", exec },
48 [R_X86_64_JUMP_SLOT] = { "R_X86_64_JUMP_SLOT", exec },
49 [R_X86_64_RELATIVE] = { "R_X86_64_RELATIVE", exec },
50 [R_X86_64_GOTPCREL] = { "R_X86_64_GOTPCREL", exec },
51 [R_X86_64_32] = { "R_X86_64_32", both },
52 [R_X86_64_32S] = { "R_X86_64_32S", rel },
53 [R_X86_64_16] = { "R_X86_64_16", rel },
54 [R_X86_64_PC16] = { "R_X86_64_PC16", rel },
55 [R_X86_64_8] = { "R_X86_64_8", rel },
56 [R_X86_64_PC8] = { "R_X86_64_PC8", rel },
57 [R_X86_64_DTPMOD64] = { "R_X86_64_DTPMOD64", rel },
58 [R_X86_64_DTPOFF64] = { "R_X86_64_DTPOFF64", rel },
59 [R_X86_64_TPOFF64] = { "R_X86_64_TPOFF64", rel },
60 [R_X86_64_TLSGD] = { "R_X86_64_TLSGD", rel },
61 [R_X86_64_TLSLD] = { "R_X86_64_TLSLD", rel },
62 [R_X86_64_DTPOFF32] = { "R_X86_64_DTPOFF32", rel },
63 [R_X86_64_GOTTPOFF] = { "R_X86_64_GOTTPOFF", rel },
64 [R_X86_64_TPOFF32] = { "R_X86_64_TPOFF32", rel }
65 };
66
67
68/* Determine relocation type string for x86-64. */
69const char *
70x86_64_reloc_type_name (int type, char *buf __attribute__ ((unused)),
71 size_t len __attribute__ ((unused)))
72{
73 if (type < 0 || type >= R_X86_64_NUM)
74 return NULL;
75
76 return reloc_map_table[type].name;
77}
78
79
80/* Check for correct relocation type. */
81bool
82x86_64_reloc_type_check (int type)
83{
84 return (type >= R_X86_64_NONE && type < R_X86_64_NUM
85 && reloc_map_table[type].name != NULL) ? true : false;
86}
87
88
89/* Check for correct relocation type use. */
90bool
91x86_64_reloc_valid_use (Elf *elf, int type)
92{
93 if (type < R_X86_64_NONE || type >= R_X86_64_NUM
94 || reloc_map_table[type].name == NULL)
95 return false;
96
97 Elf64_Ehdr *ehdr = elf64_getehdr (elf);
98 assert (ehdr != NULL);
99
100 if (reloc_map_table[type].appear == rel)
101 return ehdr->e_type == ET_REL;
102
103 if (reloc_map_table[type].appear == exec)
104 return ehdr->e_type != ET_REL;
105
106 assert (reloc_map_table[type].appear == both);
107 return true;
108}
109
110/* Check for the simple reloc types. */
111Elf_Type
112x86_64_reloc_simple_type (Elf *elf __attribute__ ((unused)), int type)
113{
114 switch (type)
115 {
116 case R_X86_64_64:
117 return ELF_T_XWORD;
118 case R_X86_64_32:
119 return ELF_T_WORD;
120 case R_X86_64_32S:
121 return ELF_T_SWORD;
122 case R_X86_64_16:
123 return ELF_T_HALF;
124 case R_X86_64_8:
125 return ELF_T_BYTE;
126 default:
127 return ELF_T_NUM;
128 }
129}
130
131/* Check whether given relocation is a copy relocation. */
132bool
133x86_64_copy_reloc_p (int reloc)
134{
135 return reloc == R_X86_64_COPY;
136}