3 # Generates ELF, COFF and MachO object files for different architectures
4 # containing all relocations:
6 # ELF: i386, x86_64, ppc64, aarch64, arm, mips, mips64el
8 # MachO: i386, x86_64, arm
9 # (see end of file for triples)
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.
23 def __init__(self, name, bases = (), attributes = {}):
24 super(EnumType, self).__init__(name, bases, attributes)
26 type.__setattr__(self, '_map', {})
27 type.__setattr__(self, '_nameMap', {})
29 for symbol in attributes:
30 if symbol.startswith('__') or symbol.endswith('__'):
33 value = attributes[symbol]
35 # MyEnum.symbol == value
36 type.__setattr__(self, symbol, value)
37 self._nameMap[symbol] = value
39 # The first symbol with the given value is authoritative.
40 if not (value in self._map):
41 # MyEnum[value] == symbol
42 self._map[value] = symbol
44 # Not supported (Enums are immutable).
45 def __setattr__(self, name, value):
46 raise NotSupportedException, self.__setattr__
48 # Not supported (Enums are immutable).
49 def __delattr__(self, name):
50 raise NotSupportedException, self.__delattr__
52 # Gets the enum symbol for the specified value.
53 def __getitem__(self, value):
54 symbol = self._map.get(value)
59 # Gets the enum symbol for the specified value or none.
60 def lookup(self, value):
61 symbol = self._map.get(value)
64 # Not supported (Enums are immutable).
65 def __setitem__(self, value, symbol):
66 raise NotSupportedException, self.__setitem__
68 # Not supported (Enums are immutable).
69 def __delitem__(self, value):
70 raise NotSupportedException, self.__delitem__
73 # sort by (value, name)
75 return (item[1], item[0])
77 for pair in sorted(self._nameMap.iteritems(), key=makeKey):
82 for e in self.entries():
85 Enum = EnumType('Enum', (), {})
88 def __init__(self, path):
89 self.file = open(path, "r+b", 0)
95 return self.file.tell()
101 data = self.file.read(N)
103 raise ValueError, "Out of data!"
107 return ord(self.read(1))
110 return ord(self.read(1))
113 return struct.unpack('><'[self.isLSB] + 'h', self.read(2))[0]
116 return struct.unpack('><'[self.isLSB] + 'H', self.read(2))[0]
119 return struct.unpack('><'[self.isLSB] + 'i', self.read(4))[0]
122 return struct.unpack('><'[self.isLSB] + 'I', self.read(4))[0]
125 return struct.unpack('><'[self.isLSB] + 'q', self.read(8))[0]
128 return struct.unpack('><'[self.isLSB] + 'Q', self.read(8))[0]
130 def writeUInt8(self, value):
131 self.file.write(struct.pack('><'[self.isLSB] + 'B', value))
133 def writeUInt16(self, value):
134 self.file.write(struct.pack('><'[self.isLSB] + 'H', value))
136 def writeUInt32(self, value):
137 self.file.write(struct.pack('><'[self.isLSB] + 'I', value))
139 def writeUInt64(self, value):
140 self.file.write(struct.pack('><'[self.isLSB] + 'Q', value))
148 def writeWord(self, value):
150 self.writeUInt64(value)
152 self.writeUInt32(value)
155 def __init__(self, strings):
156 self.string_table = strings
158 def __getitem__(self, index):
159 end = self.string_table.index('\x00', index)
160 return self.string_table[index:end]
163 def __init__(self, f):
164 self.sh_name = f.uint32()
165 self.sh_type = f.uint32()
166 self.sh_flags = f.word()
167 self.sh_addr = f.word()
168 self.sh_offset = f.word()
169 self.sh_size = f.word()
170 self.sh_link = f.uint32()
171 self.sh_info = f.uint32()
172 self.sh_addralign = f.word()
173 self.sh_entsize = f.word()
175 def patch(self, f, relocs):
176 if self.sh_type == 4 or self.sh_type == 9: # SHT_RELA / SHT_REL
177 self.patchRelocs(f, relocs)
179 def patchRelocs(self, f, relocs):
180 entries = self.sh_size // self.sh_entsize
182 for index in range(entries):
183 f.seek(self.sh_offset + index * self.sh_entsize)
186 if index < len(relocs):
195 f.writeUInt8(relocs[ri][1])
196 f.writeUInt8(relocs[ri][1])
197 f.writeUInt8(relocs[ri][1])
202 r_type = relocs[ri][1]
204 r_info = (r_info & 0xFFFFFFFF00000000) | (r_type & 0xFFFFFFFF)
206 r_info = (r_info & 0xFF00) | (r_type & 0xFF)
208 print(" %s" % relocs[ri][0])
214 def __init__(self, f):
215 self.raw_name = f.read(8)
216 self.virtual_size = f.uint32()
217 self.virtual_address = f.uint32()
218 self.raw_data_size = f.uint32()
219 self.pointer_to_raw_data = f.uint32()
220 self.pointer_to_relocations = f.uint32()
221 self.pointer_to_line_numbers = f.uint32()
222 self.relocation_count = f.uint16()
223 self.line_number_count = f.uint16()
224 self.characteristics = f.uint32()
227 def compileAsm(filename, triple, src):
228 cmd = ["llvm-mc", "-triple=" + triple, "-filetype=obj", "-o", filename]
229 print(" Running: " + " ".join(cmd))
230 p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
231 p.communicate(input=src)
234 def compileIR(filename, triple, src):
235 cmd = ["llc", "-mtriple=" + triple, "-filetype=obj", "-o", filename]
236 print(" Running: " + " ".join(cmd))
237 p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
238 p.communicate(input=src)
242 def craftElf(filename, triple, relocs, dummyReloc):
243 print("Crafting " + filename + " for " + triple)
244 if type(dummyReloc) is tuple:
245 preSrc, dummyReloc, relocsPerDummy = dummyReloc
247 for i in range((len(relocs) + relocsPerDummy - 1) / relocsPerDummy):
248 src += dummyReloc.format(i) + "\n"
249 compileIR(filename, triple, src)
251 src = (dummyReloc + "\n") * len(relocs)
252 compileAsm(filename, triple, src)
254 print(" Patching relocations...")
255 patchElf(filename, relocs)
257 def patchElf(path, relocs):
258 f = BinaryReader(path)
261 assert magic == '\x7FELF'
263 fileclass = f.uint8()
269 raise ValueError, "Unknown file class %x" % fileclass
271 byteordering = f.uint8()
272 if byteordering == 1:
274 elif byteordering == 2:
277 raise ValueError, "Unknown byte ordering %x" % byteordering
280 e_machine = f.uint16()
281 if e_machine == 0x0008 and f.is64Bit: # EM_MIPS && 64 bit
284 e_version = f.uint32()
289 e_ehsize = f.uint16()
290 e_phentsize = f.uint16()
292 e_shentsize = f.uint16()
294 e_shstrndx = f.uint16()
297 for index in range(e_shnum):
298 f.seek(e_shoff + index * e_shentsize)
302 f.seek(sections[e_shstrndx].sh_offset)
303 shstrtab = StringTable(f.read(sections[e_shstrndx].sh_size))
306 for section in sections:
307 if shstrtab[section.sh_name] == ".strtab":
308 f.seek(section.sh_offset)
309 strtab = StringTable(f.read(section.sh_size))
312 for index in range(e_shnum):
313 sections[index].patch(f, relocs)
316 def craftCoff(filename, triple, relocs, dummyReloc):
317 print("Crafting " + filename + " for " + triple)
318 src = (dummyReloc + "\n") * len(relocs)
319 compileAsm(filename, triple, src)
321 print(" Patching relocations...")
322 patchCoff(filename, relocs)
324 def patchCoff(path, relocs):
325 f = BinaryReader(path)
328 machine_type = f.uint16()
329 section_count = f.uint16()
331 sections = [CoffSection(f) for idx in range(section_count)]
333 section = sections[0]
334 f.seek(section.pointer_to_relocations)
335 for i in range(section.relocation_count):
336 virtual_addr = f.uint32()
337 symtab_idx = f.uint32()
338 print(" %s" % relocs[i][0])
339 f.writeUInt16(relocs[i][1])
342 def craftMacho(filename, triple, relocs, dummyReloc):
343 print("Crafting " + filename + " for " + triple)
345 if type(dummyReloc) is tuple:
346 srcType, preSrc, dummyReloc, relocsPerDummy = dummyReloc
348 for i in range((len(relocs) + relocsPerDummy - 1) / relocsPerDummy):
349 src += dummyReloc.format(i) + "\n"
351 compileAsm(filename, triple, src)
352 elif srcType == "ir":
353 compileIR(filename, triple, src)
355 src = (dummyReloc + "\n") * len(relocs)
356 compileAsm(filename, triple, src)
358 print(" Patching relocations...")
359 patchMacho(filename, relocs)
361 def patchMacho(filename, relocs):
362 f = BinaryReader(filename)
365 if magic == '\xFE\xED\xFA\xCE':
366 f.isLSB, f.is64Bit = False, False
367 elif magic == '\xCE\xFA\xED\xFE':
368 f.isLSB, f.is64Bit = True, False
369 elif magic == '\xFE\xED\xFA\xCF':
370 f.isLSB, f.is64Bit = False, True
371 elif magic == '\xCF\xFA\xED\xFE':
372 f.isLSB, f.is64Bit = True, True
374 raise ValueError,"Not a Mach-O object file: %r (bad magic)" % path
377 cpusubtype = f.uint32()
378 filetype = f.uint32()
379 numLoadCommands = f.uint32()
380 loadCommandsSize = f.uint32()
383 reserved = f.uint32()
387 for i in range(numLoadCommands):
388 patchMachoLoadCommand(f, relocs)
390 if f.tell() - start != loadCommandsSize:
391 raise ValueError,"%s: warning: invalid load commands size: %r" % (
392 sys.argv[0], loadCommandsSize)
394 def patchMachoLoadCommand(f, relocs):
400 patchMachoSegmentLoadCommand(f, relocs)
402 patchMachoSegmentLoadCommand(f, relocs)
406 if f.tell() - start != cmdSize:
407 raise ValueError,"%s: warning: invalid load command size: %r" % (
408 sys.argv[0], cmdSize)
410 def patchMachoSegmentLoadCommand(f, relocs):
411 segment_name = f.read(16)
414 file_offset = f.word()
417 initprot = f.uint32()
418 numSections = f.uint32()
420 for i in range(numSections):
421 patchMachoSection(f, relocs)
423 def patchMachoSection(f, relocs):
424 section_name = f.read(16)
425 segment_name = f.read(16)
429 alignment = f.uint32()
430 relocOffset = f.uint32()
431 numReloc = f.uint32()
433 reserved1 = f.uint32()
434 reserved2 = f.uint32()
436 reserved3 = f.uint32()
441 for i in range(numReloc):
442 ri = i < len(relocs) and i or 0
443 print(" %s" % relocs[ri][0])
448 value = (value & 0x0FFFFFFF) | ((relocs[ri][1] & 0xF) << 28)
453 class Relocs_Elf_X86_64(Enum):
460 R_X86_64_GLOB_DAT = 6
461 R_X86_64_JUMP_SLOT = 7
462 R_X86_64_RELATIVE = 8
463 R_X86_64_GOTPCREL = 9
470 R_X86_64_DTPMOD64 = 16
471 R_X86_64_DTPOFF64 = 17
472 R_X86_64_TPOFF64 = 18
475 R_X86_64_DTPOFF32 = 21
476 R_X86_64_GOTTPOFF = 22
477 R_X86_64_TPOFF32 = 23
479 R_X86_64_GOTOFF64 = 25
480 R_X86_64_GOTPC32 = 26
482 R_X86_64_GOTPCREL64 = 28
483 R_X86_64_GOTPC64 = 29
484 R_X86_64_GOTPLT64 = 30
485 R_X86_64_PLTOFF64 = 31
488 R_X86_64_GOTPC32_TLSDESC = 34
489 R_X86_64_TLSDESC_CALL = 35
490 R_X86_64_TLSDESC = 36
491 R_X86_64_IRELATIVE = 37
493 class Relocs_Elf_i386(Enum):
517 R_386_TLS_GD_PUSH = 25
518 R_386_TLS_GD_CALL = 26
519 R_386_TLS_GD_POP = 27
520 R_386_TLS_LDM_32 = 28
521 R_386_TLS_LDM_PUSH = 29
522 R_386_TLS_LDM_CALL = 30
523 R_386_TLS_LDM_POP = 31
524 R_386_TLS_LDO_32 = 32
527 R_386_TLS_DTPMOD32 = 35
528 R_386_TLS_DTPOFF32 = 36
529 R_386_TLS_TPOFF32 = 37
530 R_386_TLS_GOTDESC = 39
531 R_386_TLS_DESC_CALL = 40
536 class Relocs_Elf_PPC32(Enum):
545 R_PPC_ADDR14_BRTAKEN = 8
546 R_PPC_ADDR14_BRNTAKEN = 9
549 R_PPC_REL14_BRTAKEN = 12
550 R_PPC_REL14_BRNTAKEN = 13
552 R_PPC_TPREL16_LO = 70
553 R_PPC_TPREL16_HA = 72
555 class Relocs_Elf_PPC64(Enum):
558 R_PPC64_ADDR16_LO = 4
559 R_PPC64_ADDR16_HI = 5
564 R_PPC64_ADDR16_HIGHER = 39
565 R_PPC64_ADDR16_HIGHEST = 41
568 R_PPC64_TOC16_LO = 48
569 R_PPC64_TOC16_HA = 50
571 R_PPC64_ADDR16_DS = 56
572 R_PPC64_ADDR16_LO_DS = 57
573 R_PPC64_TOC16_DS = 63
574 R_PPC64_TOC16_LO_DS = 64
576 R_PPC64_TPREL16_LO = 70
577 R_PPC64_TPREL16_HA = 72
578 R_PPC64_DTPREL16_LO = 75
579 R_PPC64_DTPREL16_HA = 77
580 R_PPC64_GOT_TLSGD16_LO = 80
581 R_PPC64_GOT_TLSGD16_HA = 82
582 R_PPC64_GOT_TLSLD16_LO = 84
583 R_PPC64_GOT_TLSLD16_HA = 86
584 R_PPC64_GOT_TPREL16_LO_DS = 88
585 R_PPC64_GOT_TPREL16_HA = 90
589 class Relocs_Elf_AArch64(Enum):
590 R_AARCH64_NONE = 0x100
591 R_AARCH64_ABS64 = 0x101
592 R_AARCH64_ABS32 = 0x102
593 R_AARCH64_ABS16 = 0x103
594 R_AARCH64_PREL64 = 0x104
595 R_AARCH64_PREL32 = 0x105
596 R_AARCH64_PREL16 = 0x106
597 R_AARCH64_MOVW_UABS_G0 = 0x107
598 R_AARCH64_MOVW_UABS_G0_NC = 0x108
599 R_AARCH64_MOVW_UABS_G1 = 0x109
600 R_AARCH64_MOVW_UABS_G1_NC = 0x10a
601 R_AARCH64_MOVW_UABS_G2 = 0x10b
602 R_AARCH64_MOVW_UABS_G2_NC = 0x10c
603 R_AARCH64_MOVW_UABS_G3 = 0x10d
604 R_AARCH64_MOVW_SABS_G0 = 0x10e
605 R_AARCH64_MOVW_SABS_G1 = 0x10f
606 R_AARCH64_MOVW_SABS_G2 = 0x110
607 R_AARCH64_LD_PREL_LO19 = 0x111
608 R_AARCH64_ADR_PREL_LO21 = 0x112
609 R_AARCH64_ADR_PREL_PG_HI21 = 0x113
610 R_AARCH64_ADD_ABS_LO12_NC = 0x115
611 R_AARCH64_LDST8_ABS_LO12_NC = 0x116
612 R_AARCH64_TSTBR14 = 0x117
613 R_AARCH64_CONDBR19 = 0x118
614 R_AARCH64_JUMP26 = 0x11a
615 R_AARCH64_CALL26 = 0x11b
616 R_AARCH64_LDST16_ABS_LO12_NC = 0x11c
617 R_AARCH64_LDST32_ABS_LO12_NC = 0x11d
618 R_AARCH64_LDST64_ABS_LO12_NC = 0x11e
619 R_AARCH64_LDST128_ABS_LO12_NC = 0x12b
620 R_AARCH64_ADR_GOT_PAGE = 0x137
621 R_AARCH64_LD64_GOT_LO12_NC = 0x138
622 R_AARCH64_TLSLD_MOVW_DTPREL_G2 = 0x20b
623 R_AARCH64_TLSLD_MOVW_DTPREL_G1 = 0x20c
624 R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC = 0x20d
625 R_AARCH64_TLSLD_MOVW_DTPREL_G0 = 0x20e
626 R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC = 0x20f
627 R_AARCH64_TLSLD_ADD_DTPREL_HI12 = 0x210
628 R_AARCH64_TLSLD_ADD_DTPREL_LO12 = 0x211
629 R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC = 0x212
630 R_AARCH64_TLSLD_LDST8_DTPREL_LO12 = 0x213
631 R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC = 0x214
632 R_AARCH64_TLSLD_LDST16_DTPREL_LO12 = 0x215
633 R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC = 0x216
634 R_AARCH64_TLSLD_LDST32_DTPREL_LO12 = 0x217
635 R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC = 0x218
636 R_AARCH64_TLSLD_LDST64_DTPREL_LO12 = 0x219
637 R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC = 0x21a
638 R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 = 0x21b
639 R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC = 0x21c
640 R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 = 0x21d
641 R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC = 0x21e
642 R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 = 0x21f
643 R_AARCH64_TLSLE_MOVW_TPREL_G2 = 0x220
644 R_AARCH64_TLSLE_MOVW_TPREL_G1 = 0x221
645 R_AARCH64_TLSLE_MOVW_TPREL_G1_NC = 0x222
646 R_AARCH64_TLSLE_MOVW_TPREL_G0 = 0x223
647 R_AARCH64_TLSLE_MOVW_TPREL_G0_NC = 0x224
648 R_AARCH64_TLSLE_ADD_TPREL_HI12 = 0x225
649 R_AARCH64_TLSLE_ADD_TPREL_LO12 = 0x226
650 R_AARCH64_TLSLE_ADD_TPREL_LO12_NC = 0x227
651 R_AARCH64_TLSLE_LDST8_TPREL_LO12 = 0x228
652 R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC = 0x229
653 R_AARCH64_TLSLE_LDST16_TPREL_LO12 = 0x22a
654 R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC = 0x22b
655 R_AARCH64_TLSLE_LDST32_TPREL_LO12 = 0x22c
656 R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC = 0x22d
657 R_AARCH64_TLSLE_LDST64_TPREL_LO12 = 0x22e
658 R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC = 0x22f
659 R_AARCH64_TLSDESC_ADR_PAGE = 0x232
660 R_AARCH64_TLSDESC_LD64_LO12_NC = 0x233
661 R_AARCH64_TLSDESC_ADD_LO12_NC = 0x234
662 R_AARCH64_TLSDESC_CALL = 0x239
664 class Relocs_Elf_ARM(Enum):
669 R_ARM_LDR_PC_G0 = 0x04
672 R_ARM_THM_ABS5 = 0x07
675 R_ARM_THM_CALL = 0x0a
677 R_ARM_BREL_ADJ = 0x0c
678 R_ARM_TLS_DESC = 0x0d
679 R_ARM_THM_SWI8 = 0x0e
681 R_ARM_THM_XPC22 = 0x10
682 R_ARM_TLS_DTPMOD32 = 0x11
683 R_ARM_TLS_DTPOFF32 = 0x12
684 R_ARM_TLS_TPOFF32 = 0x13
686 R_ARM_GLOB_DAT = 0x15
687 R_ARM_JUMP_SLOT = 0x16
688 R_ARM_RELATIVE = 0x17
689 R_ARM_GOTOFF32 = 0x18
690 R_ARM_BASE_PREL = 0x19
691 R_ARM_GOT_BREL = 0x1a
695 R_ARM_THM_JUMP24 = 0x1e
696 R_ARM_BASE_ABS = 0x1f
697 R_ARM_ALU_PCREL_7_0 = 0x20
698 R_ARM_ALU_PCREL_15_8 = 0x21
699 R_ARM_ALU_PCREL_23_15 = 0x22
700 R_ARM_LDR_SBREL_11_0_NC = 0x23
701 R_ARM_ALU_SBREL_19_12_NC = 0x24
702 R_ARM_ALU_SBREL_27_20_CK = 0x25
708 R_ARM_MOVW_ABS_NC = 0x2b
709 R_ARM_MOVT_ABS = 0x2c
710 R_ARM_MOVW_PREL_NC = 0x2d
711 R_ARM_MOVT_PREL = 0x2e
712 R_ARM_THM_MOVW_ABS_NC = 0x2f
713 R_ARM_THM_MOVT_ABS = 0x30
714 R_ARM_THM_MOVW_PREL_NC = 0x31
715 R_ARM_THM_MOVT_PREL = 0x32
716 R_ARM_THM_JUMP19 = 0x33
717 R_ARM_THM_JUMP6 = 0x34
718 R_ARM_THM_ALU_PREL_11_0 = 0x35
719 R_ARM_THM_PC12 = 0x36
720 R_ARM_ABS32_NOI = 0x37
721 R_ARM_REL32_NOI = 0x38
722 R_ARM_ALU_PC_G0_NC = 0x39
723 R_ARM_ALU_PC_G0 = 0x3a
724 R_ARM_ALU_PC_G1_NC = 0x3b
725 R_ARM_ALU_PC_G1 = 0x3c
726 R_ARM_ALU_PC_G2 = 0x3d
727 R_ARM_LDR_PC_G1 = 0x3e
728 R_ARM_LDR_PC_G2 = 0x3f
729 R_ARM_LDRS_PC_G0 = 0x40
730 R_ARM_LDRS_PC_G1 = 0x41
731 R_ARM_LDRS_PC_G2 = 0x42
732 R_ARM_LDC_PC_G0 = 0x43
733 R_ARM_LDC_PC_G1 = 0x44
734 R_ARM_LDC_PC_G2 = 0x45
735 R_ARM_ALU_SB_G0_NC = 0x46
736 R_ARM_ALU_SB_G0 = 0x47
737 R_ARM_ALU_SB_G1_NC = 0x48
738 R_ARM_ALU_SB_G1 = 0x49
739 R_ARM_ALU_SB_G2 = 0x4a
740 R_ARM_LDR_SB_G0 = 0x4b
741 R_ARM_LDR_SB_G1 = 0x4c
742 R_ARM_LDR_SB_G2 = 0x4d
743 R_ARM_LDRS_SB_G0 = 0x4e
744 R_ARM_LDRS_SB_G1 = 0x4f
745 R_ARM_LDRS_SB_G2 = 0x50
746 R_ARM_LDC_SB_G0 = 0x51
747 R_ARM_LDC_SB_G1 = 0x52
748 R_ARM_LDC_SB_G2 = 0x53
749 R_ARM_MOVW_BREL_NC = 0x54
750 R_ARM_MOVT_BREL = 0x55
751 R_ARM_MOVW_BREL = 0x56
752 R_ARM_THM_MOVW_BREL_NC = 0x57
753 R_ARM_THM_MOVT_BREL = 0x58
754 R_ARM_THM_MOVW_BREL = 0x59
755 R_ARM_TLS_GOTDESC = 0x5a
756 R_ARM_TLS_CALL = 0x5b
757 R_ARM_TLS_DESCSEQ = 0x5c
758 R_ARM_THM_TLS_CALL = 0x5d
759 R_ARM_PLT32_ABS = 0x5e
761 R_ARM_GOT_PREL = 0x60
762 R_ARM_GOT_BREL12 = 0x61
763 R_ARM_GOTOFF12 = 0x62
764 R_ARM_GOTRELAX = 0x63
765 R_ARM_GNU_VTENTRY = 0x64
766 R_ARM_GNU_VTINHERIT = 0x65
767 R_ARM_THM_JUMP11 = 0x66
768 R_ARM_THM_JUMP8 = 0x67
769 R_ARM_TLS_GD32 = 0x68
770 R_ARM_TLS_LDM32 = 0x69
771 R_ARM_TLS_LDO32 = 0x6a
772 R_ARM_TLS_IE32 = 0x6b
773 R_ARM_TLS_LE32 = 0x6c
774 R_ARM_TLS_LDO12 = 0x6d
775 R_ARM_TLS_LE12 = 0x6e
776 R_ARM_TLS_IE12GP = 0x6f
777 R_ARM_PRIVATE_0 = 0x70
778 R_ARM_PRIVATE_1 = 0x71
779 R_ARM_PRIVATE_2 = 0x72
780 R_ARM_PRIVATE_3 = 0x73
781 R_ARM_PRIVATE_4 = 0x74
782 R_ARM_PRIVATE_5 = 0x75
783 R_ARM_PRIVATE_6 = 0x76
784 R_ARM_PRIVATE_7 = 0x77
785 R_ARM_PRIVATE_8 = 0x78
786 R_ARM_PRIVATE_9 = 0x79
787 R_ARM_PRIVATE_10 = 0x7a
788 R_ARM_PRIVATE_11 = 0x7b
789 R_ARM_PRIVATE_12 = 0x7c
790 R_ARM_PRIVATE_13 = 0x7d
791 R_ARM_PRIVATE_14 = 0x7e
792 R_ARM_PRIVATE_15 = 0x7f
794 R_ARM_THM_TLS_DESCSEQ16 = 0x81
795 R_ARM_THM_TLS_DESCSEQ32 = 0x82
797 class Relocs_Elf_Mips(Enum):
825 R_MIPS_CALL_HI16 = 30
826 R_MIPS_CALL_LO16 = 31
829 R_MIPS_ADD_IMMEDIATE = 34
833 R_MIPS_TLS_DTPMOD32 = 38
834 R_MIPS_TLS_DTPREL32 = 39
835 R_MIPS_TLS_DTPMOD64 = 40
836 R_MIPS_TLS_DTPREL64 = 41
839 R_MIPS_TLS_DTPREL_HI16 = 44
840 R_MIPS_TLS_DTPREL_LO16 = 45
841 R_MIPS_TLS_GOTTPREL = 46
842 R_MIPS_TLS_TPREL32 = 47
843 R_MIPS_TLS_TPREL64 = 48
844 R_MIPS_TLS_TPREL_HI16 = 49
845 R_MIPS_TLS_TPREL_LO16 = 50
848 R_MIPS_JUMP_SLOT = 127
851 class Relocs_Elf_Hexagon(Enum):
868 R_HEX_B32_PCREL_X = 16
870 R_HEX_B22_PCREL_X = 18
871 R_HEX_B15_PCREL_X = 19
872 R_HEX_B13_PCREL_X = 20
873 R_HEX_B9_PCREL_X = 21
874 R_HEX_B7_PCREL_X = 22
888 R_HEX_PLT_B22_PCREL = 36
889 R_HEX_GOTREL_LO16 = 37
890 R_HEX_GOTREL_HI16 = 38
897 R_HEX_DTPREL_LO16 = 45
898 R_HEX_DTPREL_HI16 = 46
901 R_HEX_GD_PLT_B22_PCREL = 49
902 R_HEX_GD_GOT_LO16 = 50
903 R_HEX_GD_GOT_HI16 = 51
909 R_HEX_IE_GOT_LO16 = 57
910 R_HEX_IE_GOT_HI16 = 58
913 R_HEX_TPREL_LO16 = 61
914 R_HEX_TPREL_HI16 = 62
918 R_HEX_GOTREL_32_6_X = 66
919 R_HEX_GOTREL_16_X = 67
920 R_HEX_GOTREL_11_X = 68
921 R_HEX_GOT_32_6_X = 69
924 R_HEX_DTPREL_32_6_X = 72
925 R_HEX_DTPREL_16_X = 73
926 R_HEX_DTPREL_11_X = 74
927 R_HEX_GD_GOT_32_6_X = 75
928 R_HEX_GD_GOT_16_X = 76
929 R_HEX_GD_GOT_11_X = 77
932 R_HEX_IE_GOT_32_6_X = 80
933 R_HEX_IE_GOT_16_X = 81
934 R_HEX_IE_GOT_11_X = 82
935 R_HEX_TPREL_32_6_X = 83
936 R_HEX_TPREL_16_X = 84
937 R_HEX_TPREL_11_X = 85
940 class Relocs_Coff_i386(Enum):
941 IMAGE_REL_I386_ABSOLUTE = 0x0000
942 IMAGE_REL_I386_DIR16 = 0x0001
943 IMAGE_REL_I386_REL16 = 0x0002
944 IMAGE_REL_I386_DIR32 = 0x0006
945 IMAGE_REL_I386_DIR32NB = 0x0007
946 IMAGE_REL_I386_SEG12 = 0x0009
947 IMAGE_REL_I386_SECTION = 0x000A
948 IMAGE_REL_I386_SECREL = 0x000B
949 IMAGE_REL_I386_TOKEN = 0x000C
950 IMAGE_REL_I386_SECREL7 = 0x000D
951 IMAGE_REL_I386_REL32 = 0x0014
953 class Relocs_Coff_X86_64(Enum):
954 IMAGE_REL_AMD64_ABSOLUTE = 0x0000
955 IMAGE_REL_AMD64_ADDR64 = 0x0001
956 IMAGE_REL_AMD64_ADDR32 = 0x0002
957 IMAGE_REL_AMD64_ADDR32NB = 0x0003
958 IMAGE_REL_AMD64_REL32 = 0x0004
959 IMAGE_REL_AMD64_REL32_1 = 0x0005
960 IMAGE_REL_AMD64_REL32_2 = 0x0006
961 IMAGE_REL_AMD64_REL32_3 = 0x0007
962 IMAGE_REL_AMD64_REL32_4 = 0x0008
963 IMAGE_REL_AMD64_REL32_5 = 0x0009
964 IMAGE_REL_AMD64_SECTION = 0x000A
965 IMAGE_REL_AMD64_SECREL = 0x000B
966 IMAGE_REL_AMD64_SECREL7 = 0x000C
967 IMAGE_REL_AMD64_TOKEN = 0x000D
968 IMAGE_REL_AMD64_SREL32 = 0x000E
969 IMAGE_REL_AMD64_PAIR = 0x000F
970 IMAGE_REL_AMD64_SSPAN32 = 0x0010
972 class Relocs_Coff_ARM(Enum):
973 IMAGE_REL_ARM_ABSOLUTE = 0x0000
974 IMAGE_REL_ARM_ADDR32 = 0x0001
975 IMAGE_REL_ARM_ADDR32NB = 0x0002
976 IMAGE_REL_ARM_BRANCH24 = 0x0003
977 IMAGE_REL_ARM_BRANCH11 = 0x0004
978 IMAGE_REL_ARM_TOKEN = 0x0005
979 IMAGE_REL_ARM_BLX24 = 0x0008
980 IMAGE_REL_ARM_BLX11 = 0x0009
981 IMAGE_REL_ARM_SECTION = 0x000E
982 IMAGE_REL_ARM_SECREL = 0x000F
983 IMAGE_REL_ARM_MOV32A = 0x0010
984 IMAGE_REL_ARM_MOV32T = 0x0011
985 IMAGE_REL_ARM_BRANCH20T = 0x0012
986 IMAGE_REL_ARM_BRANCH24T = 0x0014
987 IMAGE_REL_ARM_BLX23T = 0x0015
990 class Relocs_Macho_i386(Enum):
994 RIT_Generic_PreboundLazyPointer = 3
995 RIT_Generic_LocalDifference = 4
998 class Relocs_Macho_X86_64(Enum):
999 RIT_X86_64_Unsigned = 0
1000 RIT_X86_64_Signed = 1
1001 RIT_X86_64_Branch = 2
1002 RIT_X86_64_GOTLoad = 3
1004 RIT_X86_64_Subtractor = 5
1005 RIT_X86_64_Signed1 = 6
1006 RIT_X86_64_Signed2 = 7
1007 RIT_X86_64_Signed4 = 8
1010 class Relocs_Macho_ARM(Enum):
1014 RIT_ARM_LocalDifference = 3
1015 RIT_ARM_PreboundLazyPointer = 4
1016 RIT_ARM_Branch24Bit = 5
1017 RIT_ARM_ThumbBranch22Bit = 6
1018 RIT_ARM_ThumbBranch32Bit = 7
1020 RIT_ARM_HalfDifference = 9
1022 class Relocs_Macho_PPC(Enum):
1023 PPC_RELOC_VANILLA = 0
1031 PPC_RELOC_SECTDIFF = 8
1032 PPC_RELOC_PB_LA_PTR = 9
1033 PPC_RELOC_HI16_SECTDIFF = 10
1034 PPC_RELOC_LO16_SECTDIFF = 11
1035 PPC_RELOC_HA16_SECTDIFF = 12
1037 PPC_RELOC_LO14_SECTDIFF = 14
1038 PPC_RELOC_LOCAL_SECTDIFF = 15
1041 craftElf("relocs.obj.elf-x86_64", "x86_64-pc-linux-gnu", Relocs_Elf_X86_64.entries(), "leaq sym@GOTTPOFF(%rip), %rax")
1042 craftElf("relocs.obj.elf-i386", "i386-pc-linux-gnu", Relocs_Elf_i386.entries(), "mov sym@GOTOFF(%ebx), %eax")
1043 #craftElf("relocs-elf-ppc32", "powerpc-unknown-linux-gnu", Relocs_Elf_PPC32.entries(), ...)
1044 craftElf("relocs.obj.elf-ppc64", "powerpc64-unknown-linux-gnu", Relocs_Elf_PPC64.entries(),
1045 ("@t = thread_local global i32 0, align 4", "define i32* @f{0}() nounwind {{ ret i32* @t }}", 2))
1046 craftElf("relocs.obj.elf-aarch64", "aarch64", Relocs_Elf_AArch64.entries(), "movz x0, #:abs_g0:sym")
1047 craftElf("relocs.obj.elf-arm", "arm-unknown-unknown", Relocs_Elf_ARM.entries(), "b sym")
1048 craftElf("relocs.obj.elf-mips", "mips-unknown-linux", Relocs_Elf_Mips.entries(), "lui $2, %hi(sym)")
1049 craftElf("relocs.obj.elf-mips64el", "mips64el-unknown-linux", Relocs_Elf_Mips.entries(), "lui $2, %hi(sym)")
1050 #craftElf("relocs.obj.elf-hexagon", "hexagon-unknown-unknown", Relocs_Elf_Hexagon.entries(), ...)
1052 craftCoff("relocs.obj.coff-i386", "i386-pc-win32", Relocs_Coff_i386.entries(), "mov foo@imgrel(%ebx, %ecx, 4), %eax")
1053 craftCoff("relocs.obj.coff-x86_64", "x86_64-pc-win32", Relocs_Coff_X86_64.entries(), "mov foo@imgrel(%ebx, %ecx, 4), %eax")
1054 #craftCoff("relocs.obj.coff-arm", "arm-pc-win32", Relocs_Coff_ARM.entries(), "...")
1056 craftMacho("relocs.obj.macho-i386", "i386-apple-darwin9", Relocs_Macho_i386.entries(),
1057 ("asm", ".subsections_via_symbols; .text; a: ; b:", "call a", 1))
1058 craftMacho("relocs.obj.macho-x86_64", "x86_64-apple-darwin9", Relocs_Macho_X86_64.entries(),
1059 ("asm", ".subsections_via_symbols; .text; a: ; b:", "call a", 1))
1060 craftMacho("relocs.obj.macho-arm", "armv7-apple-darwin10", Relocs_Macho_ARM.entries(), "bl sym")
1061 #craftMacho("relocs.obj.macho-ppc", "powerpc-apple-darwin10", Relocs_Macho_PPC.entries(), ...)