relocs.py 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. # Generates ELF, COFF and MachO object files for different architectures
  4. # containing all relocations:
  5. #
  6. # ELF: i386, x86_64, ppc64, aarch64, arm, mips, mips64el
  7. # COFF: i386, x86_64
  8. # MachO: i386, x86_64, arm
  9. # (see end of file for triples)
  10. #
  11. # To simplify generation, object files are generated with just the proper
  12. # number of relocations through repeated instructions. Afterwards, the
  13. # relocations in the object file are patched to their proper value.
  14. import operator
  15. import shutil
  16. import struct
  17. import subprocess
  18. import sys
  19. class EnumType(type):
  20. def __init__(self, name, bases = (), attributes = {}):
  21. super(EnumType, self).__init__(name, bases, attributes)
  22. type.__setattr__(self, '_map', {})
  23. type.__setattr__(self, '_nameMap', {})
  24. for symbol in attributes:
  25. if symbol.startswith('__') or symbol.endswith('__'):
  26. continue
  27. value = attributes[symbol]
  28. # MyEnum.symbol == value
  29. type.__setattr__(self, symbol, value)
  30. self._nameMap[symbol] = value
  31. # The first symbol with the given value is authoritative.
  32. if not (value in self._map):
  33. # MyEnum[value] == symbol
  34. self._map[value] = symbol
  35. # Not supported (Enums are immutable).
  36. def __setattr__(self, name, value):
  37. raise NotSupportedException(self.__setattr__)
  38. # Not supported (Enums are immutable).
  39. def __delattr__(self, name):
  40. raise NotSupportedException(self.__delattr__)
  41. # Gets the enum symbol for the specified value.
  42. def __getitem__(self, value):
  43. symbol = self._map.get(value)
  44. if symbol is None:
  45. raise KeyError(value)
  46. return symbol
  47. # Gets the enum symbol for the specified value or none.
  48. def lookup(self, value):
  49. symbol = self._map.get(value)
  50. return symbol
  51. # Not supported (Enums are immutable).
  52. def __setitem__(self, value, symbol):
  53. raise NotSupportedException(self.__setitem__)
  54. # Not supported (Enums are immutable).
  55. def __delitem__(self, value):
  56. raise NotSupportedException(self.__delitem__)
  57. def entries(self):
  58. # sort by (value, name)
  59. def makeKey(item):
  60. return (item[1], item[0])
  61. e = []
  62. for pair in sorted(self._nameMap.items(), key=makeKey):
  63. e.append(pair)
  64. return e
  65. def __iter__(self):
  66. for e in self.entries():
  67. yield e
  68. Enum = EnumType('Enum', (), {})
  69. class BinaryReader:
  70. def __init__(self, path):
  71. self.file = open(path, "r+b", 0)
  72. self.isLSB = None
  73. self.is64Bit = None
  74. self.isN64 = False
  75. def tell(self):
  76. return self.file.tell()
  77. def seek(self, pos):
  78. self.file.seek(pos)
  79. def read(self, N):
  80. data = self.file.read(N)
  81. if len(data) != N:
  82. raise ValueError("Out of data!")
  83. return data
  84. def int8(self):
  85. return ord(self.read(1))
  86. def uint8(self):
  87. return ord(self.read(1))
  88. def int16(self):
  89. return struct.unpack('><'[self.isLSB] + 'h', self.read(2))[0]
  90. def uint16(self):
  91. return struct.unpack('><'[self.isLSB] + 'H', self.read(2))[0]
  92. def int32(self):
  93. return struct.unpack('><'[self.isLSB] + 'i', self.read(4))[0]
  94. def uint32(self):
  95. return struct.unpack('><'[self.isLSB] + 'I', self.read(4))[0]
  96. def int64(self):
  97. return struct.unpack('><'[self.isLSB] + 'q', self.read(8))[0]
  98. def uint64(self):
  99. return struct.unpack('><'[self.isLSB] + 'Q', self.read(8))[0]
  100. def writeUInt8(self, value):
  101. self.file.write(struct.pack('><'[self.isLSB] + 'B', value))
  102. def writeUInt16(self, value):
  103. self.file.write(struct.pack('><'[self.isLSB] + 'H', value))
  104. def writeUInt32(self, value):
  105. self.file.write(struct.pack('><'[self.isLSB] + 'I', value))
  106. def writeUInt64(self, value):
  107. self.file.write(struct.pack('><'[self.isLSB] + 'Q', value))
  108. def word(self):
  109. if self.is64Bit:
  110. return self.uint64()
  111. else:
  112. return self.uint32()
  113. def writeWord(self, value):
  114. if self.is64Bit:
  115. self.writeUInt64(value)
  116. else:
  117. self.writeUInt32(value)
  118. class StringTable:
  119. def __init__(self, strings):
  120. self.string_table = strings
  121. def __getitem__(self, index):
  122. end = self.string_table.index('\x00', index)
  123. return self.string_table[index:end]
  124. class ElfSection:
  125. def __init__(self, f):
  126. self.sh_name = f.uint32()
  127. self.sh_type = f.uint32()
  128. self.sh_flags = f.word()
  129. self.sh_addr = f.word()
  130. self.sh_offset = f.word()
  131. self.sh_size = f.word()
  132. self.sh_link = f.uint32()
  133. self.sh_info = f.uint32()
  134. self.sh_addralign = f.word()
  135. self.sh_entsize = f.word()
  136. def patch(self, f, relocs):
  137. if self.sh_type == 4 or self.sh_type == 9: # SHT_RELA / SHT_REL
  138. self.patchRelocs(f, relocs)
  139. def patchRelocs(self, f, relocs):
  140. entries = self.sh_size // self.sh_entsize
  141. for index in range(entries):
  142. f.seek(self.sh_offset + index * self.sh_entsize)
  143. r_offset = f.word()
  144. if index < len(relocs):
  145. ri = index
  146. else:
  147. ri = 0
  148. if f.isN64:
  149. r_sym = f.uint32()
  150. r_ssym = f.uint8()
  151. f.seek(f.tell())
  152. f.writeUInt8(relocs[ri][1])
  153. f.writeUInt8(relocs[ri][1])
  154. f.writeUInt8(relocs[ri][1])
  155. else:
  156. pos = f.tell()
  157. r_info = f.word()
  158. r_type = relocs[ri][1]
  159. if f.is64Bit:
  160. r_info = (r_info & 0xFFFFFFFF00000000) | (r_type & 0xFFFFFFFF)
  161. else:
  162. r_info = (r_info & 0xFF00) | (r_type & 0xFF)
  163. print(" %s" % relocs[ri][0])
  164. f.seek(pos)
  165. f.writeWord(r_info)
  166. class CoffSection:
  167. def __init__(self, f):
  168. self.raw_name = f.read(8)
  169. self.virtual_size = f.uint32()
  170. self.virtual_address = f.uint32()
  171. self.raw_data_size = f.uint32()
  172. self.pointer_to_raw_data = f.uint32()
  173. self.pointer_to_relocations = f.uint32()
  174. self.pointer_to_line_numbers = f.uint32()
  175. self.relocation_count = f.uint16()
  176. self.line_number_count = f.uint16()
  177. self.characteristics = f.uint32()
  178. def compileAsm(filename, triple, src):
  179. cmd = ["llvm-mc", "-triple=" + triple, "-filetype=obj", "-o", filename]
  180. print(" Running: " + " ".join(cmd))
  181. p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
  182. p.communicate(input=src)
  183. p.wait()
  184. def compileIR(filename, triple, src):
  185. cmd = ["llc", "-mtriple=" + triple, "-filetype=obj", "-o", filename]
  186. print(" Running: " + " ".join(cmd))
  187. p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
  188. p.communicate(input=src)
  189. p.wait()
  190. def craftElf(filename, triple, relocs, dummyReloc):
  191. print("Crafting " + filename + " for " + triple)
  192. if type(dummyReloc) is tuple:
  193. preSrc, dummyReloc, relocsPerDummy = dummyReloc
  194. src = preSrc + "\n"
  195. for i in range((len(relocs) + relocsPerDummy - 1) / relocsPerDummy):
  196. src += dummyReloc.format(i) + "\n"
  197. compileIR(filename, triple, src)
  198. else:
  199. src = (dummyReloc + "\n") * len(relocs)
  200. compileAsm(filename, triple, src)
  201. print(" Patching relocations...")
  202. patchElf(filename, relocs)
  203. def patchElf(path, relocs):
  204. f = BinaryReader(path)
  205. magic = f.read(4)
  206. assert magic == '\x7FELF'
  207. fileclass = f.uint8()
  208. if fileclass == 1:
  209. f.is64Bit = False
  210. elif fileclass == 2:
  211. f.is64Bit = True
  212. else:
  213. raise ValueError("Unknown file class %x" % fileclass)
  214. byteordering = f.uint8()
  215. if byteordering == 1:
  216. f.isLSB = True
  217. elif byteordering == 2:
  218. f.isLSB = False
  219. else:
  220. raise ValueError("Unknown byte ordering %x" % byteordering)
  221. f.seek(18)
  222. e_machine = f.uint16()
  223. if e_machine == 0x0008 and f.is64Bit: # EM_MIPS && 64 bit
  224. f.isN64 = True
  225. e_version = f.uint32()
  226. e_entry = f.word()
  227. e_phoff = f.word()
  228. e_shoff = f.word()
  229. e_flags = f.uint32()
  230. e_ehsize = f.uint16()
  231. e_phentsize = f.uint16()
  232. e_phnum = f.uint16()
  233. e_shentsize = f.uint16()
  234. e_shnum = f.uint16()
  235. e_shstrndx = f.uint16()
  236. sections = []
  237. for index in range(e_shnum):
  238. f.seek(e_shoff + index * e_shentsize)
  239. s = ElfSection(f)
  240. sections.append(s)
  241. f.seek(sections[e_shstrndx].sh_offset)
  242. shstrtab = StringTable(f.read(sections[e_shstrndx].sh_size))
  243. strtab = None
  244. for section in sections:
  245. if shstrtab[section.sh_name] == ".strtab":
  246. f.seek(section.sh_offset)
  247. strtab = StringTable(f.read(section.sh_size))
  248. break
  249. for index in range(e_shnum):
  250. sections[index].patch(f, relocs)
  251. def craftCoff(filename, triple, relocs, dummyReloc):
  252. print("Crafting " + filename + " for " + triple)
  253. src = (dummyReloc + "\n") * len(relocs)
  254. compileAsm(filename, triple, src)
  255. print(" Patching relocations...")
  256. patchCoff(filename, relocs)
  257. def patchCoff(path, relocs):
  258. f = BinaryReader(path)
  259. f.isLSB = True
  260. machine_type = f.uint16()
  261. section_count = f.uint16()
  262. # Zero out timestamp to prevent churn when regenerating COFF files.
  263. f.writeUInt32(0)
  264. f.seek(20)
  265. sections = [CoffSection(f) for idx in range(section_count)]
  266. section = sections[0]
  267. f.seek(section.pointer_to_relocations)
  268. for i in range(section.relocation_count):
  269. virtual_addr = f.uint32()
  270. symtab_idx = f.uint32()
  271. print(" %s" % relocs[i][0])
  272. f.writeUInt16(relocs[i][1])
  273. def craftMacho(filename, triple, relocs, dummyReloc):
  274. print("Crafting " + filename + " for " + triple)
  275. if type(dummyReloc) is tuple:
  276. srcType, preSrc, dummyReloc, relocsPerDummy = dummyReloc
  277. src = preSrc + "\n"
  278. for i in range((len(relocs) + relocsPerDummy - 1) / relocsPerDummy):
  279. src += dummyReloc.format(i) + "\n"
  280. if srcType == "asm":
  281. compileAsm(filename, triple, src)
  282. elif srcType == "ir":
  283. compileIR(filename, triple, src)
  284. else:
  285. src = (dummyReloc + "\n") * len(relocs)
  286. compileAsm(filename, triple, src)
  287. print(" Patching relocations...")
  288. patchMacho(filename, relocs)
  289. def patchMacho(filename, relocs):
  290. f = BinaryReader(filename)
  291. magic = f.read(4)
  292. if magic == '\xFE\xED\xFA\xCE':
  293. f.isLSB, f.is64Bit = False, False
  294. elif magic == '\xCE\xFA\xED\xFE':
  295. f.isLSB, f.is64Bit = True, False
  296. elif magic == '\xFE\xED\xFA\xCF':
  297. f.isLSB, f.is64Bit = False, True
  298. elif magic == '\xCF\xFA\xED\xFE':
  299. f.isLSB, f.is64Bit = True, True
  300. else:
  301. raise ValueError("Not a Mach-O object file: %r (bad magic)" % path)
  302. cputype = f.uint32()
  303. cpusubtype = f.uint32()
  304. filetype = f.uint32()
  305. numLoadCommands = f.uint32()
  306. loadCommandsSize = f.uint32()
  307. flag = f.uint32()
  308. if f.is64Bit:
  309. reserved = f.uint32()
  310. start = f.tell()
  311. for i in range(numLoadCommands):
  312. patchMachoLoadCommand(f, relocs)
  313. if f.tell() - start != loadCommandsSize:
  314. raise ValueError("%s: warning: invalid load commands size: %r" % (
  315. sys.argv[0], loadCommandsSize))
  316. def patchMachoLoadCommand(f, relocs):
  317. start = f.tell()
  318. cmd = f.uint32()
  319. cmdSize = f.uint32()
  320. if cmd == 1:
  321. patchMachoSegmentLoadCommand(f, relocs)
  322. elif cmd == 25:
  323. patchMachoSegmentLoadCommand(f, relocs)
  324. else:
  325. f.read(cmdSize - 8)
  326. if f.tell() - start != cmdSize:
  327. raise ValueError("%s: warning: invalid load command size: %r" % (
  328. sys.argv[0], cmdSize))
  329. def patchMachoSegmentLoadCommand(f, relocs):
  330. segment_name = f.read(16)
  331. vm_addr = f.word()
  332. vm_size = f.word()
  333. file_offset = f.word()
  334. file_size = f.word()
  335. maxprot = f.uint32()
  336. initprot = f.uint32()
  337. numSections = f.uint32()
  338. flags = f.uint32()
  339. for i in range(numSections):
  340. patchMachoSection(f, relocs)
  341. def patchMachoSection(f, relocs):
  342. section_name = f.read(16)
  343. segment_name = f.read(16)
  344. address = f.word()
  345. size = f.word()
  346. offset = f.uint32()
  347. alignment = f.uint32()
  348. relocOffset = f.uint32()
  349. numReloc = f.uint32()
  350. flags = f.uint32()
  351. reserved1 = f.uint32()
  352. reserved2 = f.uint32()
  353. if f.is64Bit:
  354. reserved3 = f.uint32()
  355. prev_pos = f.tell()
  356. f.seek(relocOffset)
  357. for i in range(numReloc):
  358. ri = i < len(relocs) and i or 0
  359. print(" %s" % relocs[ri][0])
  360. word1 = f.uint32()
  361. pos = f.tell()
  362. value = f.uint32()
  363. f.seek(pos)
  364. value = (value & 0x0FFFFFFF) | ((relocs[ri][1] & 0xF) << 28)
  365. f.writeUInt32(value)
  366. f.seek(prev_pos)
  367. class Relocs_Elf_X86_64(Enum):
  368. R_X86_64_NONE = 0
  369. R_X86_64_64 = 1
  370. R_X86_64_PC32 = 2
  371. R_X86_64_GOT32 = 3
  372. R_X86_64_PLT32 = 4
  373. R_X86_64_COPY = 5
  374. R_X86_64_GLOB_DAT = 6
  375. R_X86_64_JUMP_SLOT = 7
  376. R_X86_64_RELATIVE = 8
  377. R_X86_64_GOTPCREL = 9
  378. R_X86_64_32 = 10
  379. R_X86_64_32S = 11
  380. R_X86_64_16 = 12
  381. R_X86_64_PC16 = 13
  382. R_X86_64_8 = 14
  383. R_X86_64_PC8 = 15
  384. R_X86_64_DTPMOD64 = 16
  385. R_X86_64_DTPOFF64 = 17
  386. R_X86_64_TPOFF64 = 18
  387. R_X86_64_TLSGD = 19
  388. R_X86_64_TLSLD = 20
  389. R_X86_64_DTPOFF32 = 21
  390. R_X86_64_GOTTPOFF = 22
  391. R_X86_64_TPOFF32 = 23
  392. R_X86_64_PC64 = 24
  393. R_X86_64_GOTOFF64 = 25
  394. R_X86_64_GOTPC32 = 26
  395. R_X86_64_GOT64 = 27
  396. R_X86_64_GOTPCREL64 = 28
  397. R_X86_64_GOTPC64 = 29
  398. R_X86_64_GOTPLT64 = 30
  399. R_X86_64_PLTOFF64 = 31
  400. R_X86_64_SIZE32 = 32
  401. R_X86_64_SIZE64 = 33
  402. R_X86_64_GOTPC32_TLSDESC = 34
  403. R_X86_64_TLSDESC_CALL = 35
  404. R_X86_64_TLSDESC = 36
  405. R_X86_64_IRELATIVE = 37
  406. class Relocs_Elf_i386(Enum):
  407. R_386_NONE = 0
  408. R_386_32 = 1
  409. R_386_PC32 = 2
  410. R_386_GOT32 = 3
  411. R_386_PLT32 = 4
  412. R_386_COPY = 5
  413. R_386_GLOB_DAT = 6
  414. R_386_JUMP_SLOT = 7
  415. R_386_RELATIVE = 8
  416. R_386_GOTOFF = 9
  417. R_386_GOTPC = 10
  418. R_386_32PLT = 11
  419. R_386_TLS_TPOFF = 14
  420. R_386_TLS_IE = 15
  421. R_386_TLS_GOTIE = 16
  422. R_386_TLS_LE = 17
  423. R_386_TLS_GD = 18
  424. R_386_TLS_LDM = 19
  425. R_386_16 = 20
  426. R_386_PC16 = 21
  427. R_386_8 = 22
  428. R_386_PC8 = 23
  429. R_386_TLS_GD_32 = 24
  430. R_386_TLS_GD_PUSH = 25
  431. R_386_TLS_GD_CALL = 26
  432. R_386_TLS_GD_POP = 27
  433. R_386_TLS_LDM_32 = 28
  434. R_386_TLS_LDM_PUSH = 29
  435. R_386_TLS_LDM_CALL = 30
  436. R_386_TLS_LDM_POP = 31
  437. R_386_TLS_LDO_32 = 32
  438. R_386_TLS_IE_32 = 33
  439. R_386_TLS_LE_32 = 34
  440. R_386_TLS_DTPMOD32 = 35
  441. R_386_TLS_DTPOFF32 = 36
  442. R_386_TLS_TPOFF32 = 37
  443. R_386_TLS_GOTDESC = 39
  444. R_386_TLS_DESC_CALL = 40
  445. R_386_TLS_DESC = 41
  446. R_386_IRELATIVE = 42
  447. R_386_NUM = 43
  448. class Relocs_Elf_PPC32(Enum):
  449. R_PPC_NONE = 0
  450. R_PPC_ADDR32 = 1
  451. R_PPC_ADDR24 = 2
  452. R_PPC_ADDR16 = 3
  453. R_PPC_ADDR16_LO = 4
  454. R_PPC_ADDR16_HI = 5
  455. R_PPC_ADDR16_HA = 6
  456. R_PPC_ADDR14 = 7
  457. R_PPC_ADDR14_BRTAKEN = 8
  458. R_PPC_ADDR14_BRNTAKEN = 9
  459. R_PPC_REL24 = 10
  460. R_PPC_REL14 = 11
  461. R_PPC_REL14_BRTAKEN = 12
  462. R_PPC_REL14_BRNTAKEN = 13
  463. R_PPC_REL32 = 26
  464. R_PPC_TPREL16_LO = 70
  465. R_PPC_TPREL16_HA = 72
  466. class Relocs_Elf_PPC64(Enum):
  467. R_PPC64_NONE = 0
  468. R_PPC64_ADDR32 = 1
  469. R_PPC64_ADDR16_LO = 4
  470. R_PPC64_ADDR16_HI = 5
  471. R_PPC64_ADDR14 = 7
  472. R_PPC64_REL24 = 10
  473. R_PPC64_REL32 = 26
  474. R_PPC64_ADDR64 = 38
  475. R_PPC64_ADDR16_HIGHER = 39
  476. R_PPC64_ADDR16_HIGHEST = 41
  477. R_PPC64_REL64 = 44
  478. R_PPC64_TOC16 = 47
  479. R_PPC64_TOC16_LO = 48
  480. R_PPC64_TOC16_HA = 50
  481. R_PPC64_TOC = 51
  482. R_PPC64_ADDR16_DS = 56
  483. R_PPC64_ADDR16_LO_DS = 57
  484. R_PPC64_TOC16_DS = 63
  485. R_PPC64_TOC16_LO_DS = 64
  486. R_PPC64_TLS = 67
  487. R_PPC64_TPREL16_LO = 70
  488. R_PPC64_TPREL16_HA = 72
  489. R_PPC64_DTPREL16_LO = 75
  490. R_PPC64_DTPREL16_HA = 77
  491. R_PPC64_GOT_TLSGD16_LO = 80
  492. R_PPC64_GOT_TLSGD16_HA = 82
  493. R_PPC64_GOT_TLSLD16_LO = 84
  494. R_PPC64_GOT_TLSLD16_HA = 86
  495. R_PPC64_GOT_TPREL16_LO_DS = 88
  496. R_PPC64_GOT_TPREL16_HA = 90
  497. R_PPC64_TLSGD = 107
  498. R_PPC64_TLSLD = 108
  499. class Relocs_Elf_AArch64(Enum):
  500. R_AARCH64_NONE = 0
  501. R_AARCH64_ABS64 = 0x101
  502. R_AARCH64_ABS32 = 0x102
  503. R_AARCH64_ABS16 = 0x103
  504. R_AARCH64_PREL64 = 0x104
  505. R_AARCH64_PREL32 = 0x105
  506. R_AARCH64_PREL16 = 0x106
  507. R_AARCH64_MOVW_UABS_G0 = 0x107
  508. R_AARCH64_MOVW_UABS_G0_NC = 0x108
  509. R_AARCH64_MOVW_UABS_G1 = 0x109
  510. R_AARCH64_MOVW_UABS_G1_NC = 0x10a
  511. R_AARCH64_MOVW_UABS_G2 = 0x10b
  512. R_AARCH64_MOVW_UABS_G2_NC = 0x10c
  513. R_AARCH64_MOVW_UABS_G3 = 0x10d
  514. R_AARCH64_MOVW_SABS_G0 = 0x10e
  515. R_AARCH64_MOVW_SABS_G1 = 0x10f
  516. R_AARCH64_MOVW_SABS_G2 = 0x110
  517. R_AARCH64_LD_PREL_LO19 = 0x111
  518. R_AARCH64_ADR_PREL_LO21 = 0x112
  519. R_AARCH64_ADR_PREL_PG_HI21 = 0x113
  520. R_AARCH64_ADR_PREL_PG_HI21_NC = 0x114
  521. R_AARCH64_ADD_ABS_LO12_NC = 0x115
  522. R_AARCH64_LDST8_ABS_LO12_NC = 0x116
  523. R_AARCH64_TSTBR14 = 0x117
  524. R_AARCH64_CONDBR19 = 0x118
  525. R_AARCH64_JUMP26 = 0x11a
  526. R_AARCH64_CALL26 = 0x11b
  527. R_AARCH64_LDST16_ABS_LO12_NC = 0x11c
  528. R_AARCH64_LDST32_ABS_LO12_NC = 0x11d
  529. R_AARCH64_LDST64_ABS_LO12_NC = 0x11e
  530. R_AARCH64_MOVW_PREL_G0 = 0x11f
  531. R_AARCH64_MOVW_PREL_G0_NC = 0x120
  532. R_AARCH64_MOVW_PREL_G1 = 0x121
  533. R_AARCH64_MOVW_PREL_G1_NC = 0x122
  534. R_AARCH64_MOVW_PREL_G2 = 0x123
  535. R_AARCH64_MOVW_PREL_G2_NC = 0x124
  536. R_AARCH64_MOVW_PREL_G3 = 0x125
  537. R_AARCH64_LDST128_ABS_LO12_NC = 0x12b
  538. R_AARCH64_MOVW_GOTOFF_G0 = 0x12c
  539. R_AARCH64_MOVW_GOTOFF_G0_NC = 0x12d
  540. R_AARCH64_MOVW_GOTOFF_G1 = 0x12e
  541. R_AARCH64_MOVW_GOTOFF_G1_NC = 0x12f
  542. R_AARCH64_MOVW_GOTOFF_G2 = 0x130
  543. R_AARCH64_MOVW_GOTOFF_G2_NC = 0x131
  544. R_AARCH64_MOVW_GOTOFF_G3 = 0x132
  545. R_AARCH64_GOTREL64 = 0x133
  546. R_AARCH64_GOTREL32 = 0x134
  547. R_AARCH64_GOT_LD_PREL19 = 0x135
  548. R_AARCH64_LD64_GOTOFF_LO15 = 0x136
  549. R_AARCH64_ADR_GOT_PAGE = 0x137
  550. R_AARCH64_LD64_GOT_LO12_NC = 0x138
  551. R_AARCH64_LD64_GOTPAGE_LO15 = 0x139
  552. R_AARCH64_TLSGD_ADR_PREL21 = 0x200
  553. R_AARCH64_TLSGD_ADR_PAGE21 = 0x201
  554. R_AARCH64_TLSGD_ADD_LO12_NC = 0x202
  555. R_AARCH64_TLSGD_MOVW_G1 = 0x203
  556. R_AARCH64_TLSGD_MOVW_G0_NC = 0x204
  557. R_AARCH64_TLSLD_ADR_PREL21 = 0x205
  558. R_AARCH64_TLSLD_ADR_PAGE21 = 0x206
  559. R_AARCH64_TLSLD_ADD_LO12_NC = 0x207
  560. R_AARCH64_TLSLD_MOVW_G1 = 0x208
  561. R_AARCH64_TLSLD_MOVW_G0_NC = 0x209
  562. R_AARCH64_TLSLD_LD_PREL19 = 0x20a
  563. R_AARCH64_TLSLD_MOVW_DTPREL_G2 = 0x20b
  564. R_AARCH64_TLSLD_MOVW_DTPREL_G1 = 0x20c
  565. R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC = 0x20d
  566. R_AARCH64_TLSLD_MOVW_DTPREL_G0 = 0x20e
  567. R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC = 0x20f
  568. R_AARCH64_TLSLD_ADD_DTPREL_HI12 = 0x210
  569. R_AARCH64_TLSLD_ADD_DTPREL_LO12 = 0x211
  570. R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC = 0x212
  571. R_AARCH64_TLSLD_LDST8_DTPREL_LO12 = 0x213
  572. R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC = 0x214
  573. R_AARCH64_TLSLD_LDST16_DTPREL_LO12 = 0x215
  574. R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC = 0x216
  575. R_AARCH64_TLSLD_LDST32_DTPREL_LO12 = 0x217
  576. R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC = 0x218
  577. R_AARCH64_TLSLD_LDST64_DTPREL_LO12 = 0x219
  578. R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC = 0x21a
  579. R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 = 0x21b
  580. R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC = 0x21c
  581. R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 = 0x21d
  582. R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC = 0x21e
  583. R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 = 0x21f
  584. R_AARCH64_TLSLE_MOVW_TPREL_G2 = 0x220
  585. R_AARCH64_TLSLE_MOVW_TPREL_G1 = 0x221
  586. R_AARCH64_TLSLE_MOVW_TPREL_G1_NC = 0x222
  587. R_AARCH64_TLSLE_MOVW_TPREL_G0 = 0x223
  588. R_AARCH64_TLSLE_MOVW_TPREL_G0_NC = 0x224
  589. R_AARCH64_TLSLE_ADD_TPREL_HI12 = 0x225
  590. R_AARCH64_TLSLE_ADD_TPREL_LO12 = 0x226
  591. R_AARCH64_TLSLE_ADD_TPREL_LO12_NC = 0x227
  592. R_AARCH64_TLSLE_LDST8_TPREL_LO12 = 0x228
  593. R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC = 0x229
  594. R_AARCH64_TLSLE_LDST16_TPREL_LO12 = 0x22a
  595. R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC = 0x22b
  596. R_AARCH64_TLSLE_LDST32_TPREL_LO12 = 0x22c
  597. R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC = 0x22d
  598. R_AARCH64_TLSLE_LDST64_TPREL_LO12 = 0x22e
  599. R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC = 0x22f
  600. R_AARCH64_TLSDESC_LD_PREL19 = 0x230
  601. R_AARCH64_TLSDESC_ADR_PREL21 = 0x231
  602. R_AARCH64_TLSDESC_ADR_PAGE21 = 0x232
  603. R_AARCH64_TLSDESC_LD64_LO12_NC = 0x233
  604. R_AARCH64_TLSDESC_ADD_LO12_NC = 0x234
  605. R_AARCH64_TLSDESC_OFF_G1 = 0x235
  606. R_AARCH64_TLSDESC_OFF_G0_NC = 0x236
  607. R_AARCH64_TLSDESC_LDR = 0x237
  608. R_AARCH64_TLSDESC_ADD = 0x238
  609. R_AARCH64_TLSDESC_CALL = 0x239
  610. R_AARCH64_TLSLE_LDST128_TPREL_LO12 = 0x23a
  611. R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC = 0x23b
  612. R_AARCH64_TLSLD_LDST128_DTPREL_LO12 = 0x23c
  613. R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC = 0x23d
  614. R_AARCH64_COPY = 0x400
  615. R_AARCH64_GLOB_DAT = 0x401
  616. R_AARCH64_JUMP_SLOT = 0x402
  617. R_AARCH64_RELATIVE = 0x403
  618. R_AARCH64_TLS_DTPREL64 = 0x404
  619. R_AARCH64_TLS_DTPMOD64 = 0x405
  620. R_AARCH64_TLS_TPREL64 = 0x406
  621. R_AARCH64_TLSDESC = 0x407
  622. R_AARCH64_IRELATIVE = 0x408
  623. class Relocs_Elf_AArch64_ILP32(Enum):
  624. R_AARCH64_P32_NONE = 0
  625. R_AARCH64_P32_ABS32 = 1
  626. R_AARCH64_P32_ABS16 = 2
  627. R_AARCH64_P32_PREL32 = 3
  628. R_AARCH64_P32_PREL16 = 4
  629. R_AARCH64_P32_MOVW_UABS_G0 = 5
  630. R_AARCH64_P32_MOVW_UABS_G0_NC = 6
  631. R_AARCH64_P32_MOVW_UABS_G1 = 7
  632. R_AARCH64_P32_MOVW_SABS_G0 = 8
  633. R_AARCH64_P32_LD_PREL_LO19 = 9
  634. R_AARCH64_P32_ADR_PREL_LO21 = 10
  635. R_AARCH64_P32_ADR_PREL_PG_HI21 = 11
  636. R_AARCH64_P32_ADD_ABS_LO12_NC = 12
  637. R_AARCH64_P32_LDST8_ABS_LO12_NC = 13
  638. R_AARCH64_P32_LDST16_ABS_LO12_NC = 14
  639. R_AARCH64_P32_LDST32_ABS_LO12_NC = 15
  640. R_AARCH64_P32_LDST64_ABS_LO12_NC = 16
  641. R_AARCH64_P32_LDST128_ABS_LO12_NC = 17
  642. R_AARCH64_P32_TSTBR14 = 18
  643. R_AARCH64_P32_CONDBR19 = 19
  644. R_AARCH64_P32_JUMP26 = 20
  645. R_AARCH64_P32_CALL26 = 21
  646. R_AARCH64_P32_MOVW_PREL_G0 = 22
  647. R_AARCH64_P32_MOVW_PREL_G0_NC = 23
  648. R_AARCH64_P32_MOVW_PREL_G1 = 24
  649. R_AARCH64_P32_GOT_LD_PREL19 = 25
  650. R_AARCH64_P32_ADR_GOT_PAGE = 26
  651. R_AARCH64_P32_LD32_GOT_LO12_NC = 27
  652. R_AARCH64_P32_LD32_GOTPAGE_LO14 = 28
  653. R_AARCH64_P32_TLSGD_ADR_PREL21 = 80
  654. R_AARCH64_P32_TLS_GD_ADR_PAGE21 = 81
  655. R_AARCH64_P32_TLSGD_ADD_LO12_NC = 82
  656. R_AARCH64_P32_TLSLD_ADR_PREL21 = 83
  657. R_AARCH64_P32_TLDLD_ADR_PAGE21 = 84
  658. R_AARCH64_P32_TLSLD_ADR_LO12_NC = 85
  659. R_AARCH64_P32_TLSLD_LD_PREL19 = 86
  660. R_AARCH64_P32_TLDLD_MOVW_DTPREL_G1 = 87
  661. R_AARCH64_P32_TLSLD_MOVW_DTPREL_G0 = 88
  662. R_AARCH64_P32_TLSLD_MOVW_DTPREL_G0_NC = 89
  663. R_AARCH64_P32_TLSLD_MOVW_ADD_DTPREL_HI12 = 90
  664. R_AARCH64_P32_TLSLD_ADD_DTPREL_LO12 = 91
  665. R_AARCH64_P32_TLSLD_ADD_DTPREL_LO12_NC = 92
  666. R_AARCH64_P32_TLSLD_LDST8_DTPREL_LO12 = 93
  667. R_AARCH64_P32_TLSLD_LDST8_DTPREL_LO12_NC = 94
  668. R_AARCH64_P32_TLSLD_LDST16_DTPREL_LO12 = 95
  669. R_AARCH64_P32_TLSLD_LDST16_DTPREL_LO12_NC = 96
  670. R_AARCH64_P32_TLSLD_LDST32_DTPREL_LO12 = 97
  671. R_AARCH64_P32_TLSLD_LDST32_DTPREL_LO12_NC = 98
  672. R_AARCH64_P32_TLSLD_LDST64_DTPREL_LO12 = 99
  673. R_AARCH64_P32_TLSLD_LDST64_DTPREL_LO12_NC = 100
  674. R_AARCH64_P32_TLSLD_LDST128_DTPREL_LO12 = 101
  675. R_AARCH64_P32_TLSLD_LDST128_DTPREL_LO12_NC = 102
  676. R_AARCH64_P32_TLSIE_MOVW_GOTTPREL_PAGE21 = 103
  677. R_AARCH64_P32_TLSIE_LD32_GOTTPREL_LO12_NC = 104
  678. R_AARCH64_P32_TLSIE_LD_GOTTPREL_PREL19 = 105
  679. R_AARCH64_P32_TLSLE_MOVEW_TPREL_G1 = 106
  680. R_AARCH64_P32_TLSLE_MOVW_TPREL_G0 = 107
  681. R_AARCH64_P32_TLSLE_MOVW_TPREL_G0_NC = 108
  682. R_AARCH64_P32_TLS_MOVW_TPREL_HI12 = 109
  683. R_AARCH64_P32_TLSLE_ADD_TPREL_LO12 = 110
  684. R_AARCH64_P32_TLSLE_ADD_TPREL_LO12_NC = 111
  685. R_AARCH64_P32_TLSLE_LDST8_TPREL_LO12 = 112
  686. R_AARCH64_P32_TLSLE_LDST8_TPREL_LO12_NC = 113
  687. R_AARCH64_P32_TLSLE_LDST16_TPREL_LO12 = 114
  688. R_AARCH64_P32_TLSLE_LDST16_TPREL_LO12_NC = 115
  689. R_AARCH64_P32_TLSLE_LDST32_TPREL_LO12 = 116
  690. R_AARCH64_P32_TLSLE_LDST32_TPREL_LO12_NC = 117
  691. R_AARCH64_P32_TLSLE_LDST64_TPREL_LO12 = 118
  692. R_AARCH64_P32_TLSLE_LDST64_TPREL_LO12_NC = 119
  693. R_AARCH64_P32_TLSLE_LDST128_TPREL_LO12 = 120
  694. R_AARCH64_P32_TLSLE_LDST128_TPREL_LO12_NC = 121
  695. R_AARCH64_P32_TLSDESC_LD_PRELL19 = 122
  696. R_AARCH64_P32_TLSDESC_ADR_PREL21 = 123
  697. R_AARCH64_P32_TLSDESC_ADR_PAGE21 = 124
  698. R_AARCH64_P32_TLSDESSC_LD32_LO12 = 125
  699. R_AARCH64_P32_TLSDESC_ADD_LO12 = 126
  700. R_AARCH64_P32_TLSDESC_CALL = 127
  701. R_AARCH64_P32_COPY = 180
  702. R_AARCH64_P32_GLOB_DAT = 181
  703. R_AARCH64_P32_JUMP_SLOT = 182
  704. R_AARCH64_P32_RELATIVE = 183
  705. R_AARCH64_P32_TLS_DTPREL = 184
  706. R_AARCH64_P32_TLS_DTPMOD = 185
  707. R_AARCH64_P32_TLS_TPREL = 186
  708. R_AARCH64_P32_TLSDESC = 187
  709. R_AARCH64_P32_IRELATIVE = 188
  710. class Relocs_Elf_ARM(Enum):
  711. R_ARM_NONE = 0x00
  712. R_ARM_PC24 = 0x01
  713. R_ARM_ABS32 = 0x02
  714. R_ARM_REL32 = 0x03
  715. R_ARM_LDR_PC_G0 = 0x04
  716. R_ARM_ABS16 = 0x05
  717. R_ARM_ABS12 = 0x06
  718. R_ARM_THM_ABS5 = 0x07
  719. R_ARM_ABS8 = 0x08
  720. R_ARM_SBREL32 = 0x09
  721. R_ARM_THM_CALL = 0x0a
  722. R_ARM_THM_PC8 = 0x0b
  723. R_ARM_BREL_ADJ = 0x0c
  724. R_ARM_TLS_DESC = 0x0d
  725. R_ARM_THM_SWI8 = 0x0e
  726. R_ARM_XPC25 = 0x0f
  727. R_ARM_THM_XPC22 = 0x10
  728. R_ARM_TLS_DTPMOD32 = 0x11
  729. R_ARM_TLS_DTPOFF32 = 0x12
  730. R_ARM_TLS_TPOFF32 = 0x13
  731. R_ARM_COPY = 0x14
  732. R_ARM_GLOB_DAT = 0x15
  733. R_ARM_JUMP_SLOT = 0x16
  734. R_ARM_RELATIVE = 0x17
  735. R_ARM_GOTOFF32 = 0x18
  736. R_ARM_BASE_PREL = 0x19
  737. R_ARM_GOT_BREL = 0x1a
  738. R_ARM_PLT32 = 0x1b
  739. R_ARM_CALL = 0x1c
  740. R_ARM_JUMP24 = 0x1d
  741. R_ARM_THM_JUMP24 = 0x1e
  742. R_ARM_BASE_ABS = 0x1f
  743. R_ARM_ALU_PCREL_7_0 = 0x20
  744. R_ARM_ALU_PCREL_15_8 = 0x21
  745. R_ARM_ALU_PCREL_23_15 = 0x22
  746. R_ARM_LDR_SBREL_11_0_NC = 0x23
  747. R_ARM_ALU_SBREL_19_12_NC = 0x24
  748. R_ARM_ALU_SBREL_27_20_CK = 0x25
  749. R_ARM_TARGET1 = 0x26
  750. R_ARM_SBREL31 = 0x27
  751. R_ARM_V4BX = 0x28
  752. R_ARM_TARGET2 = 0x29
  753. R_ARM_PREL31 = 0x2a
  754. R_ARM_MOVW_ABS_NC = 0x2b
  755. R_ARM_MOVT_ABS = 0x2c
  756. R_ARM_MOVW_PREL_NC = 0x2d
  757. R_ARM_MOVT_PREL = 0x2e
  758. R_ARM_THM_MOVW_ABS_NC = 0x2f
  759. R_ARM_THM_MOVT_ABS = 0x30
  760. R_ARM_THM_MOVW_PREL_NC = 0x31
  761. R_ARM_THM_MOVT_PREL = 0x32
  762. R_ARM_THM_JUMP19 = 0x33
  763. R_ARM_THM_JUMP6 = 0x34
  764. R_ARM_THM_ALU_PREL_11_0 = 0x35
  765. R_ARM_THM_PC12 = 0x36
  766. R_ARM_ABS32_NOI = 0x37
  767. R_ARM_REL32_NOI = 0x38
  768. R_ARM_ALU_PC_G0_NC = 0x39
  769. R_ARM_ALU_PC_G0 = 0x3a
  770. R_ARM_ALU_PC_G1_NC = 0x3b
  771. R_ARM_ALU_PC_G1 = 0x3c
  772. R_ARM_ALU_PC_G2 = 0x3d
  773. R_ARM_LDR_PC_G1 = 0x3e
  774. R_ARM_LDR_PC_G2 = 0x3f
  775. R_ARM_LDRS_PC_G0 = 0x40
  776. R_ARM_LDRS_PC_G1 = 0x41
  777. R_ARM_LDRS_PC_G2 = 0x42
  778. R_ARM_LDC_PC_G0 = 0x43
  779. R_ARM_LDC_PC_G1 = 0x44
  780. R_ARM_LDC_PC_G2 = 0x45
  781. R_ARM_ALU_SB_G0_NC = 0x46
  782. R_ARM_ALU_SB_G0 = 0x47
  783. R_ARM_ALU_SB_G1_NC = 0x48
  784. R_ARM_ALU_SB_G1 = 0x49
  785. R_ARM_ALU_SB_G2 = 0x4a
  786. R_ARM_LDR_SB_G0 = 0x4b
  787. R_ARM_LDR_SB_G1 = 0x4c
  788. R_ARM_LDR_SB_G2 = 0x4d
  789. R_ARM_LDRS_SB_G0 = 0x4e
  790. R_ARM_LDRS_SB_G1 = 0x4f
  791. R_ARM_LDRS_SB_G2 = 0x50
  792. R_ARM_LDC_SB_G0 = 0x51
  793. R_ARM_LDC_SB_G1 = 0x52
  794. R_ARM_LDC_SB_G2 = 0x53
  795. R_ARM_MOVW_BREL_NC = 0x54
  796. R_ARM_MOVT_BREL = 0x55
  797. R_ARM_MOVW_BREL = 0x56
  798. R_ARM_THM_MOVW_BREL_NC = 0x57
  799. R_ARM_THM_MOVT_BREL = 0x58
  800. R_ARM_THM_MOVW_BREL = 0x59
  801. R_ARM_TLS_GOTDESC = 0x5a
  802. R_ARM_TLS_CALL = 0x5b
  803. R_ARM_TLS_DESCSEQ = 0x5c
  804. R_ARM_THM_TLS_CALL = 0x5d
  805. R_ARM_PLT32_ABS = 0x5e
  806. R_ARM_GOT_ABS = 0x5f
  807. R_ARM_GOT_PREL = 0x60
  808. R_ARM_GOT_BREL12 = 0x61
  809. R_ARM_GOTOFF12 = 0x62
  810. R_ARM_GOTRELAX = 0x63
  811. R_ARM_GNU_VTENTRY = 0x64
  812. R_ARM_GNU_VTINHERIT = 0x65
  813. R_ARM_THM_JUMP11 = 0x66
  814. R_ARM_THM_JUMP8 = 0x67
  815. R_ARM_TLS_GD32 = 0x68
  816. R_ARM_TLS_LDM32 = 0x69
  817. R_ARM_TLS_LDO32 = 0x6a
  818. R_ARM_TLS_IE32 = 0x6b
  819. R_ARM_TLS_LE32 = 0x6c
  820. R_ARM_TLS_LDO12 = 0x6d
  821. R_ARM_TLS_LE12 = 0x6e
  822. R_ARM_TLS_IE12GP = 0x6f
  823. R_ARM_PRIVATE_0 = 0x70
  824. R_ARM_PRIVATE_1 = 0x71
  825. R_ARM_PRIVATE_2 = 0x72
  826. R_ARM_PRIVATE_3 = 0x73
  827. R_ARM_PRIVATE_4 = 0x74
  828. R_ARM_PRIVATE_5 = 0x75
  829. R_ARM_PRIVATE_6 = 0x76
  830. R_ARM_PRIVATE_7 = 0x77
  831. R_ARM_PRIVATE_8 = 0x78
  832. R_ARM_PRIVATE_9 = 0x79
  833. R_ARM_PRIVATE_10 = 0x7a
  834. R_ARM_PRIVATE_11 = 0x7b
  835. R_ARM_PRIVATE_12 = 0x7c
  836. R_ARM_PRIVATE_13 = 0x7d
  837. R_ARM_PRIVATE_14 = 0x7e
  838. R_ARM_PRIVATE_15 = 0x7f
  839. R_ARM_ME_TOO = 0x80
  840. R_ARM_THM_TLS_DESCSEQ16 = 0x81
  841. R_ARM_THM_TLS_DESCSEQ32 = 0x82
  842. R_ARM_IRELATIVE = 0xa0
  843. class Relocs_Elf_Mips(Enum):
  844. R_MIPS_NONE = 0
  845. R_MIPS_16 = 1
  846. R_MIPS_32 = 2
  847. R_MIPS_REL32 = 3
  848. R_MIPS_26 = 4
  849. R_MIPS_HI16 = 5
  850. R_MIPS_LO16 = 6
  851. R_MIPS_GPREL16 = 7
  852. R_MIPS_LITERAL = 8
  853. R_MIPS_GOT16 = 9
  854. R_MIPS_PC16 = 10
  855. R_MIPS_CALL16 = 11
  856. R_MIPS_GPREL32 = 12
  857. R_MIPS_SHIFT5 = 16
  858. R_MIPS_SHIFT6 = 17
  859. R_MIPS_64 = 18
  860. R_MIPS_GOT_DISP = 19
  861. R_MIPS_GOT_PAGE = 20
  862. R_MIPS_GOT_OFST = 21
  863. R_MIPS_GOT_HI16 = 22
  864. R_MIPS_GOT_LO16 = 23
  865. R_MIPS_SUB = 24
  866. R_MIPS_INSERT_A = 25
  867. R_MIPS_INSERT_B = 26
  868. R_MIPS_DELETE = 27
  869. R_MIPS_HIGHER = 28
  870. R_MIPS_HIGHEST = 29
  871. R_MIPS_CALL_HI16 = 30
  872. R_MIPS_CALL_LO16 = 31
  873. R_MIPS_SCN_DISP = 32
  874. R_MIPS_REL16 = 33
  875. R_MIPS_ADD_IMMEDIATE = 34
  876. R_MIPS_PJUMP = 35
  877. R_MIPS_RELGOT = 36
  878. R_MIPS_JALR = 37
  879. R_MIPS_TLS_DTPMOD32 = 38
  880. R_MIPS_TLS_DTPREL32 = 39
  881. R_MIPS_TLS_DTPMOD64 = 40
  882. R_MIPS_TLS_DTPREL64 = 41
  883. R_MIPS_TLS_GD = 42
  884. R_MIPS_TLS_LDM = 43
  885. R_MIPS_TLS_DTPREL_HI16 = 44
  886. R_MIPS_TLS_DTPREL_LO16 = 45
  887. R_MIPS_TLS_GOTTPREL = 46
  888. R_MIPS_TLS_TPREL32 = 47
  889. R_MIPS_TLS_TPREL64 = 48
  890. R_MIPS_TLS_TPREL_HI16 = 49
  891. R_MIPS_TLS_TPREL_LO16 = 50
  892. R_MIPS_GLOB_DAT = 51
  893. R_MIPS_COPY = 126
  894. R_MIPS_JUMP_SLOT = 127
  895. R_MIPS_NUM = 218
  896. class Relocs_Elf_Hexagon(Enum):
  897. R_HEX_NONE = 0
  898. R_HEX_B22_PCREL = 1
  899. R_HEX_B15_PCREL = 2
  900. R_HEX_B7_PCREL = 3
  901. R_HEX_LO16 = 4
  902. R_HEX_HI16 = 5
  903. R_HEX_32 = 6
  904. R_HEX_16 = 7
  905. R_HEX_8 = 8
  906. R_HEX_GPREL16_0 = 9
  907. R_HEX_GPREL16_1 = 10
  908. R_HEX_GPREL16_2 = 11
  909. R_HEX_GPREL16_3 = 12
  910. R_HEX_HL16 = 13
  911. R_HEX_B13_PCREL = 14
  912. R_HEX_B9_PCREL = 15
  913. R_HEX_B32_PCREL_X = 16
  914. R_HEX_32_6_X = 17
  915. R_HEX_B22_PCREL_X = 18
  916. R_HEX_B15_PCREL_X = 19
  917. R_HEX_B13_PCREL_X = 20
  918. R_HEX_B9_PCREL_X = 21
  919. R_HEX_B7_PCREL_X = 22
  920. R_HEX_16_X = 23
  921. R_HEX_12_X = 24
  922. R_HEX_11_X = 25
  923. R_HEX_10_X = 26
  924. R_HEX_9_X = 27
  925. R_HEX_8_X = 28
  926. R_HEX_7_X = 29
  927. R_HEX_6_X = 30
  928. R_HEX_32_PCREL = 31
  929. R_HEX_COPY = 32
  930. R_HEX_GLOB_DAT = 33
  931. R_HEX_JMP_SLOT = 34
  932. R_HEX_RELATIVE = 35
  933. R_HEX_PLT_B22_PCREL = 36
  934. R_HEX_GOTREL_LO16 = 37
  935. R_HEX_GOTREL_HI16 = 38
  936. R_HEX_GOTREL_32 = 39
  937. R_HEX_GOT_LO16 = 40
  938. R_HEX_GOT_HI16 = 41
  939. R_HEX_GOT_32 = 42
  940. R_HEX_GOT_16 = 43
  941. R_HEX_DTPMOD_32 = 44
  942. R_HEX_DTPREL_LO16 = 45
  943. R_HEX_DTPREL_HI16 = 46
  944. R_HEX_DTPREL_32 = 47
  945. R_HEX_DTPREL_16 = 48
  946. R_HEX_GD_PLT_B22_PCREL = 49
  947. R_HEX_GD_GOT_LO16 = 50
  948. R_HEX_GD_GOT_HI16 = 51
  949. R_HEX_GD_GOT_32 = 52
  950. R_HEX_GD_GOT_16 = 53
  951. R_HEX_IE_LO16 = 54
  952. R_HEX_IE_HI16 = 55
  953. R_HEX_IE_32 = 56
  954. R_HEX_IE_GOT_LO16 = 57
  955. R_HEX_IE_GOT_HI16 = 58
  956. R_HEX_IE_GOT_32 = 59
  957. R_HEX_IE_GOT_16 = 60
  958. R_HEX_TPREL_LO16 = 61
  959. R_HEX_TPREL_HI16 = 62
  960. R_HEX_TPREL_32 = 63
  961. R_HEX_TPREL_16 = 64
  962. R_HEX_6_PCREL_X = 65
  963. R_HEX_GOTREL_32_6_X = 66
  964. R_HEX_GOTREL_16_X = 67
  965. R_HEX_GOTREL_11_X = 68
  966. R_HEX_GOT_32_6_X = 69
  967. R_HEX_GOT_16_X = 70
  968. R_HEX_GOT_11_X = 71
  969. R_HEX_DTPREL_32_6_X = 72
  970. R_HEX_DTPREL_16_X = 73
  971. R_HEX_DTPREL_11_X = 74
  972. R_HEX_GD_GOT_32_6_X = 75
  973. R_HEX_GD_GOT_16_X = 76
  974. R_HEX_GD_GOT_11_X = 77
  975. R_HEX_IE_32_6_X = 78
  976. R_HEX_IE_16_X = 79
  977. R_HEX_IE_GOT_32_6_X = 80
  978. R_HEX_IE_GOT_16_X = 81
  979. R_HEX_IE_GOT_11_X = 82
  980. R_HEX_TPREL_32_6_X = 83
  981. R_HEX_TPREL_16_X = 84
  982. R_HEX_TPREL_11_X = 85
  983. class Relocs_Elf_Lanai(Enum):
  984. R_LANAI_NONE = 0
  985. R_LANAI_21 = 1
  986. R_LANAI_21_F = 2
  987. R_LANAI_25 = 3
  988. R_LANAI_32 = 4
  989. R_LANAI_HI16 = 5
  990. R_LANAI_LO16 = 6
  991. class Relocs_Coff_i386(Enum):
  992. IMAGE_REL_I386_ABSOLUTE = 0x0000
  993. IMAGE_REL_I386_DIR16 = 0x0001
  994. IMAGE_REL_I386_REL16 = 0x0002
  995. IMAGE_REL_I386_DIR32 = 0x0006
  996. IMAGE_REL_I386_DIR32NB = 0x0007
  997. IMAGE_REL_I386_SEG12 = 0x0009
  998. IMAGE_REL_I386_SECTION = 0x000A
  999. IMAGE_REL_I386_SECREL = 0x000B
  1000. IMAGE_REL_I386_TOKEN = 0x000C
  1001. IMAGE_REL_I386_SECREL7 = 0x000D
  1002. IMAGE_REL_I386_REL32 = 0x0014
  1003. class Relocs_Coff_X86_64(Enum):
  1004. IMAGE_REL_AMD64_ABSOLUTE = 0x0000
  1005. IMAGE_REL_AMD64_ADDR64 = 0x0001
  1006. IMAGE_REL_AMD64_ADDR32 = 0x0002
  1007. IMAGE_REL_AMD64_ADDR32NB = 0x0003
  1008. IMAGE_REL_AMD64_REL32 = 0x0004
  1009. IMAGE_REL_AMD64_REL32_1 = 0x0005
  1010. IMAGE_REL_AMD64_REL32_2 = 0x0006
  1011. IMAGE_REL_AMD64_REL32_3 = 0x0007
  1012. IMAGE_REL_AMD64_REL32_4 = 0x0008
  1013. IMAGE_REL_AMD64_REL32_5 = 0x0009
  1014. IMAGE_REL_AMD64_SECTION = 0x000A
  1015. IMAGE_REL_AMD64_SECREL = 0x000B
  1016. IMAGE_REL_AMD64_SECREL7 = 0x000C
  1017. IMAGE_REL_AMD64_TOKEN = 0x000D
  1018. IMAGE_REL_AMD64_SREL32 = 0x000E
  1019. IMAGE_REL_AMD64_PAIR = 0x000F
  1020. IMAGE_REL_AMD64_SSPAN32 = 0x0010
  1021. class Relocs_Coff_ARM(Enum):
  1022. IMAGE_REL_ARM_ABSOLUTE = 0x0000
  1023. IMAGE_REL_ARM_ADDR32 = 0x0001
  1024. IMAGE_REL_ARM_ADDR32NB = 0x0002
  1025. IMAGE_REL_ARM_BRANCH24 = 0x0003
  1026. IMAGE_REL_ARM_BRANCH11 = 0x0004
  1027. IMAGE_REL_ARM_TOKEN = 0x0005
  1028. IMAGE_REL_ARM_BLX24 = 0x0008
  1029. IMAGE_REL_ARM_BLX11 = 0x0009
  1030. IMAGE_REL_ARM_SECTION = 0x000E
  1031. IMAGE_REL_ARM_SECREL = 0x000F
  1032. IMAGE_REL_ARM_MOV32A = 0x0010
  1033. IMAGE_REL_ARM_MOV32T = 0x0011
  1034. IMAGE_REL_ARM_BRANCH20T = 0x0012
  1035. IMAGE_REL_ARM_BRANCH24T = 0x0014
  1036. IMAGE_REL_ARM_BLX23T = 0x0015
  1037. class Relocs_Macho_i386(Enum):
  1038. RIT_Vanilla = 0
  1039. RIT_Pair = 1
  1040. RIT_Difference = 2
  1041. RIT_Generic_PreboundLazyPointer = 3
  1042. RIT_Generic_LocalDifference = 4
  1043. RIT_Generic_TLV = 5
  1044. class Relocs_Macho_X86_64(Enum):
  1045. RIT_X86_64_Unsigned = 0
  1046. RIT_X86_64_Signed = 1
  1047. RIT_X86_64_Branch = 2
  1048. RIT_X86_64_GOTLoad = 3
  1049. RIT_X86_64_GOT = 4
  1050. RIT_X86_64_Subtractor = 5
  1051. RIT_X86_64_Signed1 = 6
  1052. RIT_X86_64_Signed2 = 7
  1053. RIT_X86_64_Signed4 = 8
  1054. RIT_X86_64_TLV = 9
  1055. class Relocs_Macho_ARM(Enum):
  1056. RIT_Vanilla = 0
  1057. RIT_Pair = 1
  1058. RIT_Difference = 2
  1059. RIT_ARM_LocalDifference = 3
  1060. RIT_ARM_PreboundLazyPointer = 4
  1061. RIT_ARM_Branch24Bit = 5
  1062. RIT_ARM_ThumbBranch22Bit = 6
  1063. RIT_ARM_ThumbBranch32Bit = 7
  1064. RIT_ARM_Half = 8
  1065. RIT_ARM_HalfDifference = 9
  1066. class Relocs_Macho_PPC(Enum):
  1067. PPC_RELOC_VANILLA = 0
  1068. PPC_RELOC_PAIR = 1
  1069. PPC_RELOC_BR14 = 2
  1070. PPC_RELOC_BR24 = 3
  1071. PPC_RELOC_HI16 = 4
  1072. PPC_RELOC_LO16 = 5
  1073. PPC_RELOC_HA16 = 6
  1074. PPC_RELOC_LO14 = 7
  1075. PPC_RELOC_SECTDIFF = 8
  1076. PPC_RELOC_PB_LA_PTR = 9
  1077. PPC_RELOC_HI16_SECTDIFF = 10
  1078. PPC_RELOC_LO16_SECTDIFF = 11
  1079. PPC_RELOC_HA16_SECTDIFF = 12
  1080. PPC_RELOC_JBSR = 13
  1081. PPC_RELOC_LO14_SECTDIFF = 14
  1082. PPC_RELOC_LOCAL_SECTDIFF = 15
  1083. craftElf("relocs.obj.elf-x86_64", "x86_64-pc-linux-gnu", Relocs_Elf_X86_64.entries(), "leaq sym@GOTTPOFF(%rip), %rax")
  1084. craftElf("relocs.obj.elf-i386", "i386-pc-linux-gnu", Relocs_Elf_i386.entries(), "mov sym@GOTOFF(%ebx), %eax")
  1085. #craftElf("relocs-elf-ppc32", "powerpc-unknown-linux-gnu", Relocs_Elf_PPC32.entries(), ...)
  1086. craftElf("relocs.obj.elf-ppc64", "powerpc64-unknown-linux-gnu", Relocs_Elf_PPC64.entries(),
  1087. ("@t = thread_local global i32 0, align 4", "define i32* @f{0}() nounwind {{ ret i32* @t }}", 2))
  1088. craftElf("relocs.obj.elf-aarch64", "aarch64", Relocs_Elf_AArch64.entries(), "movz x0, #:abs_g0:sym")
  1089. craftElf("relocs.obj.elf-aarch64-ilp32", "aarch64",
  1090. Relocs_Elf_AArch64_ILP32.entries(), "movz x0, #:abs_g0:sym")
  1091. Relocs_Elf_AArch64_ILP32
  1092. craftElf("relocs.obj.elf-arm", "arm-unknown-unknown", Relocs_Elf_ARM.entries(), "b sym")
  1093. craftElf("relocs.obj.elf-mips", "mips-unknown-linux", Relocs_Elf_Mips.entries(), "lui $2, %hi(sym)")
  1094. craftElf("relocs.obj.elf-mips64el", "mips64el-unknown-linux", Relocs_Elf_Mips.entries(), "lui $2, %hi(sym)")
  1095. #craftElf("relocs.obj.elf-hexagon", "hexagon-unknown-unknown", Relocs_Elf_Hexagon.entries(), ...)
  1096. #craftElf("relocs.obj.elf-lanai", "lanai-unknown-unknown", Relocs_Elf_Lanai.entries(), "mov hi(x), %r4")
  1097. craftCoff("relocs.obj.coff-i386", "i386-pc-win32", Relocs_Coff_i386.entries(), "mov foo@imgrel(%ebx, %ecx, 4), %eax")
  1098. craftCoff("relocs.obj.coff-x86_64", "x86_64-pc-win32", Relocs_Coff_X86_64.entries(), "mov foo@imgrel(%ebx, %ecx, 4), %eax")
  1099. #craftCoff("relocs.obj.coff-arm", "arm-pc-win32", Relocs_Coff_ARM.entries(), "...")
  1100. craftMacho("relocs.obj.macho-i386", "i386-apple-darwin9", Relocs_Macho_i386.entries(),
  1101. ("asm", ".subsections_via_symbols; .text; a: ; b:", "call a", 1))
  1102. craftMacho("relocs.obj.macho-x86_64", "x86_64-apple-darwin9", Relocs_Macho_X86_64.entries(),
  1103. ("asm", ".subsections_via_symbols; .text; a: ; b:", "call a", 1))
  1104. craftMacho("relocs.obj.macho-arm", "armv7-apple-darwin10", Relocs_Macho_ARM.entries(), "bl sym")
  1105. #craftMacho("relocs.obj.macho-ppc", "powerpc-apple-darwin10", Relocs_Macho_PPC.entries(), ...)