relocs.py 40 KB

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