elftools 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +111 -7
  3. data/lib/elftools/constants/machine.rb +248 -0
  4. data/lib/elftools/constants/machine_names.rb +246 -0
  5. data/lib/elftools/constants/relocation/aarch64.rb +213 -0
  6. data/lib/elftools/constants/relocation/alpha.rb +47 -0
  7. data/lib/elftools/constants/relocation/amdgpu.rb +28 -0
  8. data/lib/elftools/constants/relocation/arm.rb +150 -0
  9. data/lib/elftools/constants/relocation/avr.rb +51 -0
  10. data/lib/elftools/constants/relocation/bfin.rb +72 -0
  11. data/lib/elftools/constants/relocation/bpf.rb +21 -0
  12. data/lib/elftools/constants/relocation/cr16.rb +46 -0
  13. data/lib/elftools/constants/relocation/cris.rb +46 -0
  14. data/lib/elftools/constants/relocation/crx.rb +35 -0
  15. data/lib/elftools/constants/relocation/csky.rb +79 -0
  16. data/lib/elftools/constants/relocation/d10v.rb +23 -0
  17. data/lib/elftools/constants/relocation/d30v.rb +27 -0
  18. data/lib/elftools/constants/relocation/dlx.rb +24 -0
  19. data/lib/elftools/constants/relocation/epiphany.rb +28 -0
  20. data/lib/elftools/constants/relocation/fr30.rb +27 -0
  21. data/lib/elftools/constants/relocation/frv.rb +57 -0
  22. data/lib/elftools/constants/relocation/ft32.rb +27 -0
  23. data/lib/elftools/constants/relocation/h8.rb +69 -0
  24. data/lib/elftools/constants/relocation/hppa.rb +135 -0
  25. data/lib/elftools/constants/relocation/i370.rb +26 -0
  26. data/lib/elftools/constants/relocation/i386.rb +59 -0
  27. data/lib/elftools/constants/relocation/i860.rb +48 -0
  28. data/lib/elftools/constants/relocation/i960.rb +22 -0
  29. data/lib/elftools/constants/relocation/ia64.rb +117 -0
  30. data/lib/elftools/constants/relocation/ip2k.rb +29 -0
  31. data/lib/elftools/constants/relocation/iq2000.rb +27 -0
  32. data/lib/elftools/constants/relocation/kvx.rb +97 -0
  33. data/lib/elftools/constants/relocation/lm32.rb +32 -0
  34. data/lib/elftools/constants/relocation/loongarch.rb +144 -0
  35. data/lib/elftools/constants/relocation/m32c.rb +27 -0
  36. data/lib/elftools/constants/relocation/m32r.rb +57 -0
  37. data/lib/elftools/constants/relocation/m68hc11.rb +35 -0
  38. data/lib/elftools/constants/relocation/m68k.rb +57 -0
  39. data/lib/elftools/constants/relocation/mcore.rb +27 -0
  40. data/lib/elftools/constants/relocation/mep.rb +36 -0
  41. data/lib/elftools/constants/relocation/metag.rb +63 -0
  42. data/lib/elftools/constants/relocation/microblaze.rb +48 -0
  43. data/lib/elftools/constants/relocation/mips.rb +125 -0
  44. data/lib/elftools/constants/relocation/mmix.rb +51 -0
  45. data/lib/elftools/constants/relocation/mn10200.rb +22 -0
  46. data/lib/elftools/constants/relocation/mn10300.rb +49 -0
  47. data/lib/elftools/constants/relocation/moxie.rb +17 -0
  48. data/lib/elftools/constants/relocation/msp430.rb +27 -0
  49. data/lib/elftools/constants/relocation/msp430x.rb +37 -0
  50. data/lib/elftools/constants/relocation/mt.rb +21 -0
  51. data/lib/elftools/constants/relocation/nds32.rb +167 -0
  52. data/lib/elftools/constants/relocation/nfp.rb +41 -0
  53. data/lib/elftools/constants/relocation/nfp3200.rb +46 -0
  54. data/lib/elftools/constants/relocation/nios2.rb +74 -0
  55. data/lib/elftools/constants/relocation/or1k.rb +69 -0
  56. data/lib/elftools/constants/relocation/pj.rb +24 -0
  57. data/lib/elftools/constants/relocation/ppc.rb +131 -0
  58. data/lib/elftools/constants/relocation/ppc64.rb +177 -0
  59. data/lib/elftools/constants/relocation/pru.rb +31 -0
  60. data/lib/elftools/constants/relocation/riscv.rb +74 -0
  61. data/lib/elftools/constants/relocation/rl78.rb +70 -0
  62. data/lib/elftools/constants/relocation/rx.rb +81 -0
  63. data/lib/elftools/constants/relocation/s12z.rb +22 -0
  64. data/lib/elftools/constants/relocation/s390.rb +82 -0
  65. data/lib/elftools/constants/relocation/score.rb +36 -0
  66. data/lib/elftools/constants/relocation/sh.rb +124 -0
  67. data/lib/elftools/constants/relocation/sparc.rb +108 -0
  68. data/lib/elftools/constants/relocation/spu.rb +32 -0
  69. data/lib/elftools/constants/relocation/tic6x.rb +48 -0
  70. data/lib/elftools/constants/relocation/tilegx.rb +134 -0
  71. data/lib/elftools/constants/relocation/tilepro.rb +105 -0
  72. data/lib/elftools/constants/relocation/v800.rb +101 -0
  73. data/lib/elftools/constants/relocation/v850.rb +66 -0
  74. data/lib/elftools/constants/relocation/vax.rb +29 -0
  75. data/lib/elftools/constants/relocation/visium.rb +30 -0
  76. data/lib/elftools/constants/relocation/wasm32.rb +16 -0
  77. data/lib/elftools/constants/relocation/x86_64.rb +68 -0
  78. data/lib/elftools/constants/relocation/xgate.rb +34 -0
  79. data/lib/elftools/constants/relocation/xstormy16.rb +29 -0
  80. data/lib/elftools/constants/relocation/xtensa.rb +75 -0
  81. data/lib/elftools/constants/relocation/z80.rb +28 -0
  82. data/lib/elftools/constants/relocation.rb +181 -0
  83. data/lib/elftools/constants.rb +124 -231
  84. data/lib/elftools/dynamic/hash_table.rb +216 -0
  85. data/lib/elftools/dynamic/string_table.rb +30 -0
  86. data/lib/elftools/dynamic/symbols.rb +146 -0
  87. data/lib/elftools/dynamic/tag.rb +66 -0
  88. data/lib/elftools/dynamic.rb +102 -62
  89. data/lib/elftools/elf_file.rb +74 -23
  90. data/lib/elftools/lazy_array.rb +42 -4
  91. data/lib/elftools/note.rb +6 -3
  92. data/lib/elftools/relocation.rb +94 -0
  93. data/lib/elftools/sections/dynamic_section.rb +13 -0
  94. data/lib/elftools/sections/relocation_section.rb +24 -43
  95. data/lib/elftools/sections/section.rb +4 -4
  96. data/lib/elftools/sections/sym_tab_section.rb +14 -34
  97. data/lib/elftools/sections/symbol.rb +112 -0
  98. data/lib/elftools/segments/dynamic_segment.rb +1 -0
  99. data/lib/elftools/segments/load_segment.rb +33 -5
  100. data/lib/elftools/segments/segment.rb +8 -4
  101. data/lib/elftools/structs.rb +24 -3
  102. data/lib/elftools/util.rb +1 -1
  103. data/lib/elftools/version.rb +1 -1
  104. metadata +101 -11
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'elftools/constants/machine'
4
+
5
+ # This file is generated by `bundle exec rake gen:constants`, do not edit it.
6
+ # Source: https://sourceware.org/cgit/binutils-gdb/tree/include/elf
7
+
8
+ module ELFTools
9
+ module Constants
10
+ # Relocation types, recorded in the +r_info+ of a relocation.
11
+ #
12
+ # Every architecture numbers them on its own, so they are grouped by
13
+ # architecture and only loaded once one of the groups is asked for.
14
+ module R
15
+ autoload :AARCH64, 'elftools/constants/relocation/aarch64'
16
+ autoload :ALPHA, 'elftools/constants/relocation/alpha'
17
+ autoload :AMDGPU, 'elftools/constants/relocation/amdgpu'
18
+ autoload :ARM, 'elftools/constants/relocation/arm'
19
+ autoload :AVR, 'elftools/constants/relocation/avr'
20
+ autoload :BFIN, 'elftools/constants/relocation/bfin'
21
+ autoload :BPF, 'elftools/constants/relocation/bpf'
22
+ autoload :CR16, 'elftools/constants/relocation/cr16'
23
+ autoload :CRIS, 'elftools/constants/relocation/cris'
24
+ autoload :CRX, 'elftools/constants/relocation/crx'
25
+ autoload :CSKY, 'elftools/constants/relocation/csky'
26
+ autoload :D10V, 'elftools/constants/relocation/d10v'
27
+ autoload :D30V, 'elftools/constants/relocation/d30v'
28
+ autoload :DLX, 'elftools/constants/relocation/dlx'
29
+ autoload :EPIPHANY, 'elftools/constants/relocation/epiphany'
30
+ autoload :FR30, 'elftools/constants/relocation/fr30'
31
+ autoload :FRV, 'elftools/constants/relocation/frv'
32
+ autoload :FT32, 'elftools/constants/relocation/ft32'
33
+ autoload :H8, 'elftools/constants/relocation/h8'
34
+ autoload :HPPA, 'elftools/constants/relocation/hppa'
35
+ autoload :I370, 'elftools/constants/relocation/i370'
36
+ autoload :I386, 'elftools/constants/relocation/i386'
37
+ autoload :I860, 'elftools/constants/relocation/i860'
38
+ autoload :I960, 'elftools/constants/relocation/i960'
39
+ autoload :IA64, 'elftools/constants/relocation/ia64'
40
+ autoload :IP2K, 'elftools/constants/relocation/ip2k'
41
+ autoload :IQ2000, 'elftools/constants/relocation/iq2000'
42
+ autoload :KVX, 'elftools/constants/relocation/kvx'
43
+ autoload :LM32, 'elftools/constants/relocation/lm32'
44
+ autoload :LOONGARCH, 'elftools/constants/relocation/loongarch'
45
+ autoload :M32C, 'elftools/constants/relocation/m32c'
46
+ autoload :M32R, 'elftools/constants/relocation/m32r'
47
+ autoload :M68HC11, 'elftools/constants/relocation/m68hc11'
48
+ autoload :M68K, 'elftools/constants/relocation/m68k'
49
+ autoload :MCORE, 'elftools/constants/relocation/mcore'
50
+ autoload :MEP, 'elftools/constants/relocation/mep'
51
+ autoload :METAG, 'elftools/constants/relocation/metag'
52
+ autoload :MICROBLAZE, 'elftools/constants/relocation/microblaze'
53
+ autoload :MIPS, 'elftools/constants/relocation/mips'
54
+ autoload :MMIX, 'elftools/constants/relocation/mmix'
55
+ autoload :MN10200, 'elftools/constants/relocation/mn10200'
56
+ autoload :MN10300, 'elftools/constants/relocation/mn10300'
57
+ autoload :MOXIE, 'elftools/constants/relocation/moxie'
58
+ autoload :MSP430, 'elftools/constants/relocation/msp430'
59
+ autoload :MSP430X, 'elftools/constants/relocation/msp430x'
60
+ autoload :MT, 'elftools/constants/relocation/mt'
61
+ autoload :NDS32, 'elftools/constants/relocation/nds32'
62
+ autoload :NFP, 'elftools/constants/relocation/nfp'
63
+ autoload :NFP3200, 'elftools/constants/relocation/nfp3200'
64
+ autoload :NIOS2, 'elftools/constants/relocation/nios2'
65
+ autoload :OR1K, 'elftools/constants/relocation/or1k'
66
+ autoload :PJ, 'elftools/constants/relocation/pj'
67
+ autoload :PPC, 'elftools/constants/relocation/ppc'
68
+ autoload :PPC64, 'elftools/constants/relocation/ppc64'
69
+ autoload :PRU, 'elftools/constants/relocation/pru'
70
+ autoload :RISCV, 'elftools/constants/relocation/riscv'
71
+ autoload :RL78, 'elftools/constants/relocation/rl78'
72
+ autoload :RX, 'elftools/constants/relocation/rx'
73
+ autoload :S12Z, 'elftools/constants/relocation/s12z'
74
+ autoload :S390, 'elftools/constants/relocation/s390'
75
+ autoload :SCORE, 'elftools/constants/relocation/score'
76
+ autoload :SH, 'elftools/constants/relocation/sh'
77
+ autoload :SPARC, 'elftools/constants/relocation/sparc'
78
+ autoload :SPU, 'elftools/constants/relocation/spu'
79
+ autoload :TIC6X, 'elftools/constants/relocation/tic6x'
80
+ autoload :TILEGX, 'elftools/constants/relocation/tilegx'
81
+ autoload :TILEPRO, 'elftools/constants/relocation/tilepro'
82
+ autoload :V800, 'elftools/constants/relocation/v800'
83
+ autoload :V850, 'elftools/constants/relocation/v850'
84
+ autoload :VAX, 'elftools/constants/relocation/vax'
85
+ autoload :VISIUM, 'elftools/constants/relocation/visium'
86
+ autoload :WASM32, 'elftools/constants/relocation/wasm32'
87
+ autoload :X86_64, 'elftools/constants/relocation/x86_64'
88
+ autoload :XGATE, 'elftools/constants/relocation/xgate'
89
+ autoload :XSTORMY16, 'elftools/constants/relocation/xstormy16'
90
+ autoload :XTENSA, 'elftools/constants/relocation/xtensa'
91
+ autoload :Z80, 'elftools/constants/relocation/z80'
92
+
93
+ # The architecture that relocates each machine.
94
+ # @return [Hash{Integer => Symbol}]
95
+ MACHINES = {
96
+ EM::EM_386 => :I386,
97
+ EM::EM_68HC11 => :M68HC11,
98
+ EM::EM_68HC12 => :M68HC11,
99
+ EM::EM_68K => :M68K,
100
+ EM::EM_860 => :I860,
101
+ EM::EM_960 => :I960,
102
+ EM::EM_AARCH64 => :AARCH64,
103
+ EM::EM_ADAPTEVA_EPIPHANY => :EPIPHANY,
104
+ EM::EM_ALPHA => :ALPHA,
105
+ EM::EM_ALTERA_NIOS2 => :NIOS2,
106
+ EM::EM_AMDGPU => :AMDGPU,
107
+ EM::EM_ARM => :ARM,
108
+ EM::EM_AVR => :AVR,
109
+ EM::EM_BLACKFIN => :BFIN,
110
+ EM::EM_BPF => :BPF,
111
+ EM::EM_CR16 => :CR16,
112
+ EM::EM_CRIS => :CRIS,
113
+ EM::EM_CRX => :CRX,
114
+ EM::EM_CSKY => :CSKY,
115
+ EM::EM_CYGNUS_FRV => :FRV,
116
+ EM::EM_CYGNUS_MEP => :MEP,
117
+ EM::EM_D10V => :D10V,
118
+ EM::EM_D30V => :D30V,
119
+ EM::EM_DLX => :DLX,
120
+ EM::EM_FR30 => :FR30,
121
+ EM::EM_FT32 => :FT32,
122
+ EM::EM_H8S => :H8,
123
+ EM::EM_H8_300 => :H8,
124
+ EM::EM_H8_300H => :H8,
125
+ EM::EM_IAMCU => :I386,
126
+ EM::EM_IA_64 => :IA64,
127
+ EM::EM_IP2K => :IP2K,
128
+ EM::EM_IQ2000 => :IQ2000,
129
+ EM::EM_KVX => :KVX,
130
+ EM::EM_LATTICEMICO32 => :LM32,
131
+ EM::EM_LOONGARCH => :LOONGARCH,
132
+ EM::EM_M32C => :M32C,
133
+ EM::EM_M32R => :M32R,
134
+ EM::EM_MCORE => :MCORE,
135
+ EM::EM_METAG => :METAG,
136
+ EM::EM_MICROBLAZE => :MICROBLAZE,
137
+ EM::EM_MIPS => :MIPS,
138
+ EM::EM_MMIX => :MMIX,
139
+ EM::EM_MN10200 => :MN10200,
140
+ EM::EM_MN10300 => :MN10300,
141
+ EM::EM_MOXIE => :MOXIE,
142
+ EM::EM_MSP430 => :MSP430,
143
+ EM::EM_MT => :MT,
144
+ EM::EM_NDS32 => :NDS32,
145
+ EM::EM_NFP => :NFP,
146
+ EM::EM_OR1K => :OR1K,
147
+ EM::EM_PARISC => :HPPA,
148
+ EM::EM_PJ => :PJ,
149
+ EM::EM_PPC => :PPC,
150
+ EM::EM_PPC64 => :PPC64,
151
+ EM::EM_RISCV => :RISCV,
152
+ EM::EM_RL78 => :RL78,
153
+ EM::EM_RX => :RX,
154
+ EM::EM_S12Z => :S12Z,
155
+ EM::EM_S370 => :I370,
156
+ EM::EM_S390 => :S390,
157
+ EM::EM_S390_OLD => :S390,
158
+ EM::EM_SCORE => :SCORE,
159
+ EM::EM_SH => :SH,
160
+ EM::EM_SPARC => :SPARC,
161
+ EM::EM_SPARC32PLUS => :SPARC,
162
+ EM::EM_SPARCV9 => :SPARC,
163
+ EM::EM_SPU => :SPU,
164
+ EM::EM_TILEGX => :TILEGX,
165
+ EM::EM_TILEPRO => :TILEPRO,
166
+ EM::EM_TI_C6000 => :TIC6X,
167
+ EM::EM_TI_PRU => :PRU,
168
+ EM::EM_V800 => :V800,
169
+ EM::EM_V850 => :V850,
170
+ EM::EM_VAX => :VAX,
171
+ EM::EM_VISIUM => :VISIUM,
172
+ EM::EM_WEBASSEMBLY => :WASM32,
173
+ EM::EM_X86_64 => :X86_64,
174
+ EM::EM_XGATE => :XGATE,
175
+ EM::EM_XSTORMY16 => :XSTORMY16,
176
+ EM::EM_XTENSA => :XTENSA,
177
+ EM::EM_Z80 => :Z80
178
+ }.freeze
179
+ end
180
+ end
181
+ end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'elftools/constants/machine'
4
+ require 'elftools/constants/relocation'
5
+
3
6
  module ELFTools
4
7
  # Define constants from elf.h.
5
8
  # Mostly refer from https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h
@@ -8,6 +11,70 @@ module ELFTools
8
11
  # ELF magic header
9
12
  ELFMAG = "\x7FELF"
10
13
 
14
+ # Names a value after the constants that define it, for the modules where
15
+ # several of them may define one value.
16
+ #
17
+ # A machine defines names of its own, and a name may mark where a range of
18
+ # values begins or ends, or how many of them are defined, rather than name
19
+ # one of them.
20
+ module Naming
21
+ # Architectures a constant can be named after, the longest first so that
22
+ # a name is read as the architecture it spells out in full.
23
+ ARCHITECTURES = (R.constants - [:MACHINES]).sort_by { |name| -name.length }.freeze
24
+
25
+ # Return the name of +value+.
26
+ #
27
+ # Names of a machine other than +machine+ are passed over, as are the
28
+ # ones that mark a range or a count instead of naming a value.
29
+ # @param [Integer?] machine Value of +e_machine+.
30
+ # @param [Integer] value The value to name.
31
+ # @return [String] The name.
32
+ # @example
33
+ # Constants::STT.mapping(Constants::EM_ARM, 13)
34
+ # #=> 'STT_ARM_TFUNC'
35
+ # Constants::STT.mapping(Constants::EM_X86_64, 13)
36
+ # #=> '<unknown>: 0xd'
37
+ def mapping(machine, value)
38
+ architecture = R::MACHINES[machine]
39
+ name = names_by_value.fetch(value, []).find do |constant|
40
+ !marker?(constant) && [nil, architecture].include?(architecture_of(constant))
41
+ end
42
+ name ? name.to_s : format('<unknown>: 0x%x', value)
43
+ end
44
+
45
+ private
46
+
47
+ # The constants defining each value, in the order they are defined.
48
+ # @return [Hash{Integer => Array<Symbol>}] The constants.
49
+ def names_by_value
50
+ @names_by_value ||= constants.group_by { |constant| const_get(constant) }
51
+ end
52
+
53
+ # The architecture a constant is named after.
54
+ # @example
55
+ # architecture_of(:SHN_MIPS_ACOMMON)
56
+ # #=> :MIPS
57
+ # architecture_of(:SHN_ABS)
58
+ # #=> nil
59
+ # @return [Symbol?] The architecture, +nil+ if the name spells out none.
60
+ def architecture_of(constant)
61
+ rest = constant.to_s.sub(/\A#{name.split('::').last}_/, '')
62
+ ARCHITECTURES.find { |architecture| rest.start_with?("#{architecture}_") }
63
+ end
64
+
65
+ # Whether a constant marks where a range of values begins or ends, or
66
+ # how many of them are defined, rather than naming one of them.
67
+ # @example
68
+ # marker?(:STT_LOPROC)
69
+ # #=> true
70
+ # marker?(:STT_FUNC)
71
+ # #=> false
72
+ # @return [Boolean] The answer.
73
+ def marker?(constant)
74
+ constant.to_s.match?(/_((LO|HI)(OS|PROC|RESERVE)|NUM)\z/)
75
+ end
76
+ end
77
+
11
78
  # Values of `d_un.d_val' in the DT_FLAGS and DT_FLAGS_1 entry.
12
79
  module DF
13
80
  DF_ORIGIN = 0x00000001 # Object may use DF_ORIGIN
@@ -52,6 +119,8 @@ module ELFTools
52
119
 
53
120
  # Dynamic table types, records in +d_tag+.
54
121
  module DT
122
+ extend Naming
123
+
55
124
  DT_NULL = 0 # marks the end of the _DYNAMIC array
56
125
  DT_NEEDED = 1 # libraries need to be linked by loader
57
126
  DT_PLTRELSZ = 2 # total size of relocation entries
@@ -193,255 +262,62 @@ module ELFTools
193
262
  include DT
194
263
 
195
264
  # These constants define the various ELF target machines.
265
+ #
266
+ # Constants are defined in +elftools/constants/machine+.
196
267
  module EM
197
- EM_NONE = 0 # none
198
- EM_M32 = 1 # AT&T WE 32100
199
- EM_SPARC = 2 # SPARC
200
- EM_386 = 3 # Intel 80386
201
- EM_68K = 4 # Motorola 68000
202
- EM_88K = 5 # Motorola 88000
203
- EM_486 = 6 # Intel 80486
204
- EM_860 = 7 # Intel 80860
205
- EM_MIPS = 8 # MIPS R3000 (officially, big-endian only)
206
- EM_S370 = 9 # IBM System/370
207
-
208
- # Next two are historical and binaries and
209
- # modules of these types will be rejected by Linux.
210
- EM_MIPS_RS3_LE = 10 # MIPS R3000 little-endian
211
- EM_MIPS_RS4_BE = 10 # MIPS R4000 big-endian
212
-
213
- EM_PARISC = 15 # HPPA
214
- EM_VPP500 = 17 # Fujitsu VPP500 (also some older versions of PowerPC)
215
- EM_SPARC32PLUS = 18 # Sun's "v8plus"
216
- EM_960 = 19 # Intel 80960
217
- EM_PPC = 20 # PowerPC
218
- EM_PPC64 = 21 # PowerPC64
219
- EM_S390 = 22 # IBM S/390
220
- EM_SPU = 23 # Cell BE SPU
221
- EM_V800 = 36 # NEC V800 series
222
- EM_FR20 = 37 # Fujitsu FR20
223
- EM_RH32 = 38 # TRW RH32
224
- EM_RCE = 39 # Motorola M*Core
225
- EM_ARM = 40 # ARM 32 bit
226
- EM_SH = 42 # SuperH
227
- EM_SPARCV9 = 43 # SPARC v9 64-bit
228
- EM_TRICORE = 44 # Siemens Tricore embedded processor
229
- EM_ARC = 45 # ARC Cores
230
- EM_H8_300 = 46 # Renesas H8/300
231
- EM_H8_300H = 47 # Renesas H8/300H
232
- EM_H8S = 48 # Renesas H8S
233
- EM_H8_500 = 49 # Renesas H8/500H
234
- EM_IA_64 = 50 # HP/Intel IA-64
235
- EM_MIPS_X = 51 # Stanford MIPS-X
236
- EM_COLDFIRE = 52 # Motorola Coldfire
237
- EM_68HC12 = 53 # Motorola M68HC12
238
- EM_MMA = 54 # Fujitsu Multimedia Accelerator
239
- EM_PCP = 55 # Siemens PCP
240
- EM_NCPU = 56 # Sony nCPU embedded RISC processor
241
- EM_NDR1 = 57 # Denso NDR1 microprocessor
242
- EM_STARCORE = 58 # Motorola Star*Core processor
243
- EM_ME16 = 59 # Toyota ME16 processor
244
- EM_ST100 = 60 # STMicroelectronics ST100 processor
245
- EM_TINYJ = 61 # Advanced Logic Corp. TinyJ embedded processor
246
- EM_X86_64 = 62 # AMD x86-64
247
- EM_PDSP = 63 # Sony DSP Processor
248
- EM_PDP10 = 64 # Digital Equipment Corp. PDP-10
249
- EM_PDP11 = 65 # Digital Equipment Corp. PDP-11
250
- EM_FX66 = 66 # Siemens FX66 microcontroller
251
- EM_ST9PLUS = 67 # STMicroelectronics ST9+ 8/16 bit microcontroller
252
- EM_ST7 = 68 # STMicroelectronics ST7 8-bit microcontroller
253
- EM_68HC16 = 69 # Motorola MC68HC16 Microcontroller
254
- EM_68HC11 = 70 # Motorola MC68HC11 Microcontroller
255
- EM_68HC08 = 71 # Motorola MC68HC08 Microcontroller
256
- EM_68HC05 = 72 # Motorola MC68HC05 Microcontroller
257
- EM_SVX = 73 # Silicon Graphics SVx
258
- EM_ST19 = 74 # STMicroelectronics ST19 8-bit cpu
259
- EM_VAX = 75 # Digital VAX
260
- EM_CRIS = 76 # Axis Communications 32-bit embedded processor
261
- EM_JAVELIN = 77 # Infineon Technologies 32-bit embedded cpu
262
- EM_FIREPATH = 78 # Element 14 64-bit DSP processor
263
- EM_ZSP = 79 # LSI Logic's 16-bit DSP processor
264
- EM_MMIX = 80 # Donald Knuth's educational 64-bit processor
265
- EM_HUANY = 81 # Harvard's machine-independent format
266
- EM_PRISM = 82 # SiTera Prism
267
- EM_AVR = 83 # Atmel AVR 8-bit microcontroller
268
- EM_FR30 = 84 # Fujitsu FR30
269
- EM_D10V = 85 # Mitsubishi D10V
270
- EM_D30V = 86 # Mitsubishi D30V
271
- EM_V850 = 87 # Renesas V850
272
- EM_M32R = 88 # Renesas M32R
273
- EM_MN10300 = 89 # Matsushita MN10300
274
- EM_MN10200 = 90 # Matsushita MN10200
275
- EM_PJ = 91 # picoJava
276
- EM_OPENRISC = 92 # OpenRISC 32-bit embedded processor
277
- EM_ARC_COMPACT = 93 # ARC International ARCompact processor
278
- EM_XTENSA = 94 # Tensilica Xtensa Architecture
279
- EM_VIDEOCORE = 95 # Alphamosaic VideoCore processor
280
- EM_TMM_GPP = 96 # Thompson Multimedia General Purpose Processor
281
- EM_NS32K = 97 # National Semiconductor 32000 series
282
- EM_TPC = 98 # Tenor Network TPC processor
283
- EM_SNP1K = 99 # Trebia SNP 1000 processor
284
- EM_ST200 = 100 # STMicroelectronics ST200 microcontroller
285
- EM_IP2K = 101 # Ubicom IP2022 micro controller
286
- EM_MAX = 102 # MAX Processor
287
- EM_CR = 103 # National Semiconductor CompactRISC
288
- EM_F2MC16 = 104 # Fujitsu F2MC16
289
- EM_MSP430 = 105 # TI msp430 micro controller
290
- EM_BLACKFIN = 106 # ADI Blackfin Processor
291
- EM_SE_C33 = 107 # S1C33 Family of Seiko Epson processors
292
- EM_SEP = 108 # Sharp embedded microprocessor
293
- EM_ARCA = 109 # Arca RISC Microprocessor
294
- EM_UNICORE = 110 # Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University
295
- EM_EXCESS = 111 # eXcess: 16/32/64-bit configurable embedded CPU
296
- EM_DXP = 112 # Icera Semiconductor Inc. Deep Execution Processor
297
- EM_ALTERA_NIOS2 = 113 # Altera Nios II soft-core processor
298
- EM_CRX = 114 # National Semiconductor CRX
299
- EM_XGATE = 115 # Motorola XGATE embedded processor
300
- EM_C116 = 116 # Infineon C16x/XC16x processor
301
- EM_M16C = 117 # Renesas M16C series microprocessors
302
- EM_DSPIC30F = 118 # Microchip Technology dsPIC30F Digital Signal Controller
303
- EM_CE = 119 # Freescale Communication Engine RISC core
304
- EM_M32C = 120 # Freescale Communication Engine RISC core
305
- EM_TSK3000 = 131 # Altium TSK3000 core
306
- EM_RS08 = 132 # Freescale RS08 embedded processor
307
- EM_SHARC = 133 # Analog Devices SHARC family of 32-bit DSP processors
308
- EM_ECOG2 = 134 # Cyan Technology eCOG2 microprocessor
309
- EM_SCORE7 = 135 # Sunplus S+core7 RISC processor
310
- EM_DSP24 = 136 # New Japan Radio (NJR) 24-bit DSP Processor
311
- EM_VIDEOCORE3 = 137 # Broadcom VideoCore III processor
312
- EM_LATTICEMICO32 = 138 # RISC processor for Lattice FPGA architecture
313
- EM_SE_C17 = 139 # Seiko Epson C17 family
314
- EM_TI_C6000 = 140 # The Texas Instruments TMS320C6000 DSP family
315
- EM_TI_C2000 = 141 # The Texas Instruments TMS320C2000 DSP family
316
- EM_TI_C5500 = 142 # The Texas Instruments TMS320C55x DSP family
317
- EM_TI_ARP32 = 143 # Texas Instruments Application Specific RISC Processor, 32bit fetch
318
- EM_TI_PRU = 144 # Texas Instruments Programmable Realtime Unit
319
- EM_MMDSP_PLUS = 160 # STMicroelectronics 64bit VLIW Data Signal Processor
320
- EM_CYPRESS_M8C = 161 # Cypress M8C microprocessor
321
- EM_R32C = 162 # Renesas R32C series microprocessors
322
- EM_TRIMEDIA = 163 # NXP Semiconductors TriMedia architecture family
323
- EM_QDSP6 = 164 # QUALCOMM DSP6 Processor
324
- EM_8051 = 165 # Intel 8051 and variants
325
- EM_STXP7X = 166 # STMicroelectronics STxP7x family
326
- EM_NDS32 = 167 # Andes Technology compact code size embedded RISC processor family
327
- EM_ECOG1 = 168 # Cyan Technology eCOG1X family
328
- EM_ECOG1X = 168 # Cyan Technology eCOG1X family
329
- EM_MAXQ30 = 169 # Dallas Semiconductor MAXQ30 Core Micro-controllers
330
- EM_XIMO16 = 170 # New Japan Radio (NJR) 16-bit DSP Processor
331
- EM_MANIK = 171 # M2000 Reconfigurable RISC Microprocessor
332
- EM_CRAYNV2 = 172 # Cray Inc. NV2 vector architecture
333
- EM_RX = 173 # Renesas RX family
334
- EM_METAG = 174 # Imagination Technologies Meta processor architecture
335
- EM_MCST_ELBRUS = 175 # MCST Elbrus general purpose hardware architecture
336
- EM_ECOG16 = 176 # Cyan Technology eCOG16 family
337
- EM_CR16 = 177 # National Semiconductor CompactRISC 16-bit processor
338
- EM_ETPU = 178 # Freescale Extended Time Processing Unit
339
- EM_SLE9X = 179 # Infineon Technologies SLE9X core
340
- EM_L1OM = 180 # Intel L1OM
341
- EM_K1OM = 181 # Intel K1OM
342
- EM_AARCH64 = 183 # ARM 64 bit
343
- EM_AVR32 = 185 # Atmel Corporation 32-bit microprocessor family
344
- EM_STM8 = 186 # STMicroeletronics STM8 8-bit microcontroller
345
- EM_TILE64 = 187 # Tilera TILE64 multicore architecture family
346
- EM_TILEPRO = 188 # Tilera TILEPro
347
- EM_MICROBLAZE = 189 # Xilinx MicroBlaze
348
- EM_CUDA = 190 # NVIDIA CUDA architecture
349
- EM_TILEGX = 191 # Tilera TILE-Gx
350
- EM_CLOUDSHIELD = 192 # CloudShield architecture family
351
- EM_COREA_1ST = 193 # KIPO-KAIST Core-A 1st generation processor family
352
- EM_COREA_2ND = 194 # KIPO-KAIST Core-A 2nd generation processor family
353
- EM_ARC_COMPACT2 = 195 # Synopsys ARCompact V2
354
- EM_OPEN8 = 196 # Open8 8-bit RISC soft processor core
355
- EM_RL78 = 197 # Renesas RL78 family
356
- EM_VIDEOCORE5 = 198 # Broadcom VideoCore V processor
357
- EM_78K0R = 199 # Renesas 78K0R
358
- EM_56800EX = 200 # Freescale 56800EX Digital Signal Controller (DSC)
359
- EM_BA1 = 201 # Beyond BA1 CPU architecture
360
- EM_BA2 = 202 # Beyond BA2 CPU architecture
361
- EM_XCORE = 203 # XMOS xCORE processor family
362
- EM_MCHP_PIC = 204 # Microchip 8-bit PIC(r) family
363
- EM_INTELGT = 205 # Intel Graphics Technology
364
- EM_KM32 = 210 # KM211 KM32 32-bit processor
365
- EM_KMX32 = 211 # KM211 KMX32 32-bit processor
366
- EM_KMX16 = 212 # KM211 KMX16 16-bit processor
367
- EM_KMX8 = 213 # KM211 KMX8 8-bit processor
368
- EM_KVARC = 214 # KM211 KVARC processor
369
- EM_CDP = 215 # Paneve CDP architecture family
370
- EM_COGE = 216 # Cognitive Smart Memory Processor
371
- EM_COOL = 217 # Bluechip Systems CoolEngine
372
- EM_NORC = 218 # Nanoradio Optimized RISC
373
- EM_CSR_KALIMBA = 219 # CSR Kalimba architecture family
374
- EM_Z80 = 220 # Zilog Z80
375
- EM_VISIUM = 221 # Controls and Data Services VISIUMcore processor
376
- EM_FT32 = 222 # FTDI Chip FT32 high performance 32-bit RISC architecture
377
- EM_MOXIE = 223 # Moxie processor family
378
- EM_AMDGPU = 224 # AMD GPU architecture
379
- EM_LANAI = 244 # Lanai 32-bit processor
380
- EM_CEVA = 245 # CEVA Processor Architecture Family
381
- EM_CEVA_X2 = 246 # CEVA X2 Processor Family
382
- EM_BPF = 247 # Linux BPF - in-kernel virtual machine
383
- EM_GRAPHCORE_IPU = 248 # Graphcore Intelligent Processing Unit
384
- EM_IMG1 = 249 # Imagination Technologies
385
- EM_NFP = 250 # Netronome Flow Processor (NFP)
386
- EM_VE = 251 # NEC Vector Engine
387
- EM_CSKY = 252 # C-SKY processor family
388
- EM_ARC_COMPACT3_64 = 253 # Synopsys ARCv2.3 64-bit
389
- EM_MCS6502 = 254 # MOS Technology MCS 6502 processor
390
- EM_ARC_COMPACT3 = 255 # Synopsys ARCv2.3 32-bit
391
- EM_KVX = 256 # Kalray VLIW core of the MPPA processor family
392
- EM_65816 = 257 # WDC 65816/65C816
393
- EM_LOONGARCH = 258 # LoongArch
394
- EM_KF32 = 259 # ChipON KungFu32
395
- EM_U16_U8CORE = 260 # LAPIS nX-U16/U8
396
- EM_TACHYUM = 261 # Tachyum
397
- EM_56800EF = 262 # NXP 56800EF Digital Signal Controller (DSC)
398
-
399
- EM_FRV = 0x5441 # Fujitsu FR-V
400
-
401
- # This is an interim value that we will use until the committee comes up with a final number.
402
- EM_ALPHA = 0x9026
403
-
404
- # Bogus old m32r magic number, used by old tools.
405
- EM_CYGNUS_M32R = 0x9041
406
- # This is the old interim value for S/390 architecture
407
- EM_S390_OLD = 0xA390
408
- # Also Panasonic/MEI MN10300, AM33
409
- EM_CYGNUS_MN10300 = 0xbeef
268
+ # Names are only loaded when a name is asked for.
269
+ autoload :NAMES, 'elftools/constants/machine_names'
410
270
 
411
271
  # Return the architecture name according to +val+.
412
272
  # Used by {ELFTools::ELFFile#machine}.
413
- #
414
- # Only supports famous archs.
415
273
  # @param [Integer] val Value of +e_machine+.
416
274
  # @return [String]
417
275
  # Name of architecture.
418
276
  # @example
419
277
  # mapping(3)
420
278
  # #=> 'Intel 80386'
421
- # mapping(6)
422
- # #=> 'Intel 80386'
423
279
  # mapping(62)
424
- # #=> 'Advanced Micro Devices X86-64'
280
+ # #=> 'Advanced Micro Devices X86-64 processor'
281
+ # mapping(243)
282
+ # #=> 'RISC-V'
425
283
  # mapping(1337)
426
284
  # #=> '<unknown>: 0x539'
427
285
  def self.mapping(val)
428
- case val
429
- when EM_NONE then 'None'
430
- when EM_386, EM_486 then 'Intel 80386'
431
- when EM_860 then 'Intel 80860'
432
- when EM_MIPS then 'MIPS R3000'
433
- when EM_PPC then 'PowerPC'
434
- when EM_PPC64 then 'PowerPC64'
435
- when EM_ARM then 'ARM'
436
- when EM_IA_64 then 'Intel IA-64'
437
- when EM_AARCH64 then 'AArch64'
438
- when EM_X86_64 then 'Advanced Micro Devices X86-64'
439
- else format('<unknown>: 0x%x', val)
440
- end
286
+ NAMES.fetch(val) { format('<unknown>: 0x%x', val) }
441
287
  end
442
288
  end
443
289
  include EM
444
290
 
291
+ # Relocation types, see +elftools/constants/relocation+ for the constants.
292
+ module R
293
+ # Return the name of a relocation type.
294
+ #
295
+ # A type only means something together with the machine that recorded it,
296
+ # both of them are needed to name it.
297
+ # @param [Integer?] machine Value of +e_machine+.
298
+ # @param [Integer] type The relocation type.
299
+ # @return [String] Name of the relocation type.
300
+ # @example
301
+ # mapping(Constants::EM_X86_64, 7)
302
+ # #=> 'R_X86_64_JUMP_SLOT'
303
+ # mapping(Constants::EM_ARM, 7)
304
+ # #=> 'R_ARM_THM_ABS5'
305
+ # mapping(Constants::EM_X86_64, 1337)
306
+ # #=> '<unknown>: 0x539'
307
+ def self.mapping(machine, type)
308
+ architecture = MACHINES[machine]
309
+ names = architecture && names_of(const_get(architecture))
310
+ names&.fetch(type, nil) || format('<unknown>: 0x%x', type)
311
+ end
312
+
313
+ # Names of every relocation type an architecture defines.
314
+ # @return [Hash{Integer => String}]
315
+ def self.names_of(architecture)
316
+ @names_of ||= {}
317
+ @names_of[architecture] ||= architecture.constants.to_h { |name| [architecture.const_get(name), name.to_s] }
318
+ end
319
+ end
320
+
445
321
  # This module defines ELF file types.
446
322
  module ET
447
323
  ET_NONE = 0 # no file type
@@ -518,6 +394,8 @@ module ELFTools
518
394
  # Special indices to section. These are used when there is no valid index to section header.
519
395
  # The meaning of these values is left upto the embedding header.
520
396
  module SHN
397
+ extend Naming
398
+
521
399
  SHN_UNDEF = 0 # undefined section
522
400
  SHN_LORESERVE = 0xff00 # start of reserved indices
523
401
 
@@ -674,6 +552,8 @@ module ELFTools
674
552
 
675
553
  # Symbol binding from Sym st_info field.
676
554
  module STB
555
+ extend Naming
556
+
677
557
  STB_LOCAL = 0 # Local symbol
678
558
  STB_GLOBAL = 1 # Global symbol
679
559
  STB_WEAK = 2 # Weak symbol
@@ -688,6 +568,8 @@ module ELFTools
688
568
 
689
569
  # Symbol types from Sym st_info field.
690
570
  module STT
571
+ extend Naming
572
+
691
573
  STT_NOTYPE = 0 # Symbol type is unspecified
692
574
  STT_OBJECT = 1 # Symbol is a data object
693
575
  STT_FUNC = 2 # Symbol is a code object
@@ -718,5 +600,16 @@ module ELFTools
718
600
  STT_ARM_16BIT = 15 # ARM: a THUMB label.
719
601
  end
720
602
  include STT
603
+
604
+ # Symbol visibility from Sym st_other field.
605
+ module STV
606
+ extend Naming
607
+
608
+ STV_DEFAULT = 0 # Visibility is specified by binding type
609
+ STV_INTERNAL = 1 # OS specific version of {STV_HIDDEN}
610
+ STV_HIDDEN = 2 # Can only be seen inside currently compilation unit
611
+ STV_PROTECTED = 3 # Symbol is visible but cannot be preempted
612
+ end
613
+ include STV
721
614
  end
722
615
  end