• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* x86_64 specific symbolic name handling.
2    Copyright (C) 2002 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.  */
27 const char *
x86_64_backend_name(void)28 x86_64_backend_name (void)
29 {
30   return "x86-64";
31 }
32 
33 
34 /* Relocation mapping table.  */
35 static 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", rel },
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", rel },
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.  */
69 const char *
x86_64_reloc_type_name(int type,char * buf,size_t len)70 x86_64_reloc_type_name (int type, char *buf, size_t len)
71 {
72   if (type < 0 || type >= R_X86_64_NUM)
73     return NULL;
74 
75   return reloc_map_table[type].name;
76 }
77 
78 
79 /* Check for correct relocation type.  */
80 bool
x86_64_reloc_type_check(int type)81 x86_64_reloc_type_check (int type)
82 {
83   return (type >= R_X86_64_NONE && type < R_X86_64_NUM
84 	  && reloc_map_table[type].name != NULL) ? true : false;
85 }
86 
87 
88 /* Check for correct relocation type use.  */
89 bool
x86_64_reloc_valid_use(Elf * elf,int type)90 x86_64_reloc_valid_use (Elf *elf, int type)
91 {
92   if (type < R_X86_64_NONE || type >= R_X86_64_NUM
93       || reloc_map_table[type].name == NULL)
94     return false;
95 
96   Elf64_Ehdr *ehdr = elf64_getehdr (elf);
97   assert (ehdr != NULL);
98 
99   if (reloc_map_table[type].appear == rel)
100     return ehdr->e_type == ET_REL;
101 
102   if (reloc_map_table[type].appear == exec)
103     return ehdr->e_type != ET_REL;
104 
105   assert (reloc_map_table[type].appear == both);
106   return true;
107 }
108