From: Peter Johnson Date: Mon, 11 Oct 2004 04:30:08 +0000 (-0000) Subject: * elf.h: Update x86 and amd64 relocation types and associated comments. X-Git-Tag: v0.4.0~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f8d2c0cca344dd486c1cb093ef6c21e3acc5b05;p=yasm * elf.h: Update x86 and amd64 relocation types and associated comments. * elf-x86-x86.c: Add 8-bit and 16-bit relocations (GNU extensions). * tests/Makefile.inc: Rename elfreloc-err to elfreloc-ext, because relocs tested in elfreloc-err are now legal due to above changes. * elfreloc-ext.asm: Likewise. * elfreloc-ext.errwarn: Likewise. * elfreloc-ext.hex: New output file. svn path=/trunk/yasm/; revision=1161 --- diff --git a/modules/objfmts/elf/elf-x86-x86.c b/modules/objfmts/elf/elf-x86-x86.c index dd0e08aa..689622e1 100644 --- a/modules/objfmts/elf/elf-x86-x86.c +++ b/modules/objfmts/elf/elf-x86-x86.c @@ -38,7 +38,7 @@ static int elf_x86_x86_accepts_reloc_size(size_t val) { - return val == 32; + return (val&(val-1)) ? 0 : ((val & (8|16|32)) != 0); } static void @@ -119,7 +119,22 @@ elf_x86_x86_handle_reloc_addend(yasm_intnum *intn, elf_reloc_entry *reloc) static unsigned int elf_x86_x86_map_reloc_info_to_type(elf_reloc_entry *reloc) { - return (reloc->rtype_rel ? R_386_PC32 : R_386_32); + if (reloc->rtype_rel) { + switch (reloc->valsize) { + case 8: return (unsigned char) R_386_PC8; + case 16: return (unsigned char) R_386_PC16; + case 32: return (unsigned char) R_386_PC32; + default: yasm_internal_error(N_("Unsupported relocation size")); + } + } else { + switch (reloc->valsize) { + case 8: return (unsigned char) R_386_8; + case 16: return (unsigned char) R_386_16; + case 32: return (unsigned char) R_386_32; + default: yasm_internal_error(N_("Unsupported relocation size")); + } + } + return 0; } static void diff --git a/modules/objfmts/elf/elf.h b/modules/objfmts/elf/elf.h index c3cacd29..edf62f7c 100644 --- a/modules/objfmts/elf/elf.h +++ b/modules/objfmts/elf/elf.h @@ -231,38 +231,84 @@ typedef enum { #define RELOC64_ALIGN 8 -/* elf relocation type - index of semantics */ +/* elf relocation type - index of semantics + * + * A = Addend (r_addend for RELA, value at location for REL) + * B = Base address + * G = Offset into global offset table (GOT) + * GOT = Address of the global offset table (GOT) + * L = Location of procedure linkage table (PLT) + * P = Location of location being relocated (r_offset) + * S = Value of symbol + */ typedef enum { R_386_NONE = 0, /* none */ - R_386_32 = 1, /* word, S + A */ - R_386_PC32 = 2, /* word, S + A - P */ - R_386_GOT32 = 3, /* word, G + A - P */ - R_386_PLT32 = 4, /* word, L + A - P */ + R_386_32 = 1, /* word32, S + A */ + R_386_PC32 = 2, /* word32, S + A - P */ + R_386_GOT32 = 3, /* word32, G + A - P */ + R_386_PLT32 = 4, /* word32, L + A - P */ R_386_COPY = 5, /* none */ - R_386_GLOB_DAT = 6, /* word, S */ - R_386_JMP_SLOT = 7, /* word, S */ - R_386_RELATIVE = 8, /* word, B + A */ - R_386_GOTOFF = 9, /* word, S + A - GOT */ - R_386_GOTPC = 10 /* word, GOT + A - P */ + R_386_GLOB_DAT = 6, /* word32, S */ + R_386_JMP_SLOT = 7, /* word32, S */ + R_386_RELATIVE = 8, /* word32, B + A */ + R_386_GOTOFF = 9, /* word32, S + A - GOT */ + R_386_GOTPC = 10, /* word32, GOT + A - P */ + R_386_TLS_TPOFF = 14, /* Negative offset in static TLS block (GNU + version) */ + R_386_TLS_IE = 15, /* Absolute address of GOT entry for negative + static TLS block offset */ + R_386_TLS_GOTIE = 16, /* GOT entry for negative static TLS block + offset */ + R_386_TLS_LE = 17, /* Negative offset relative to static TLS + (GNU version) */ + R_386_TLS_GD = 18, /* Direct 32 bit for GNU version of GD TLS */ + R_386_TLS_LDM = 19, /* Direct 32 bit for GNU version of LD TLS + in LE code */ + R_386_16 = 20, /* word16, S + A (GNU extension) */ + R_386_PC16 = 21, /* word16, S + A - P (GNU extension) */ + R_386_8 = 22, /* word8, S + A (GNU extension) */ + R_386_PC8 = 23, /* word8, S + A - P (GNU extension) */ + R_386_TLS_GD_32 = 24, /* Direct 32 bit for GD TLS */ + R_386_TLS_GD_PUSH = 25, /* Tag for pushl in GD TLS code */ + R_386_TLS_GD_CALL = 26, /* Relocation for call to */ + R_386_TLS_GD_POP = 27, /* Tag for popl in GD TLS code */ + R_386_TLS_LDM_32 = 28, /* Direct 32 bit for local dynamic code */ + R_386_TLS_LDM_PUSH = 29, /* Tag for pushl in LDM TLS code */ + R_386_TLS_LDM_CALL = 30, /* Relocation for call to */ + R_386_TLS_LDM_POP = 31, /* Tag for popl in LDM TLS code */ + R_386_TLS_LDO_32 = 32, /* Offset relative to TLS block */ + R_386_TLS_IE_32 = 33, /* GOT entry for static TLS block */ + R_386_TLS_LE_32 = 34, /* Offset relative to static TLS block */ + R_386_TLS_DTPMOD32 = 35, /* ID of module containing symbol */ + R_386_TLS_DTPOFF32 = 36, /* Offset in TLS block */ + R_386_TLS_TPOFF32 = 37 /* Offset in static TLS block */ } elf_386_relocation_type; typedef enum { R_X86_64_NONE = 0, /* none */ - R_X86_64_64 = 1, /* add 64-bit symbol value */ - R_X86_64_PC32 = 2, /* pc-relative 32bit signed sym value */ - R_X86_64_GOT32 = 3, /* pc-relative 32bit signed GOT offset */ - R_X86_64_PLT32 = 4, /* pc-relative 32bit signed PLT offset */ - R_X86_64_COPY = 5, /* Copy data from shared object */ - R_X86_64_GLOB_DAT = 6, /* Set GOT entry to data address */ - R_X86_64_JMP_SLOT = 7, /* Set GOT entry to code address */ - R_X86_64_RELATIVE = 8, /* Add load address of shared object */ - R_X86_64_GOTPCREL = 9, /* Add 32bit signed pcrel offset to GOT */ - R_X86_64_32 = 10, /* Add 32bit zero extended (zx) symbol value */ - R_X86_64_32S = 11, /* Add 32bit sign extended (sx) symbol value */ - R_X86_64_16 = 12, /* Add 16bit zx symbol value */ - R_X86_64_PC16 = 13, /* Add 16bit sx pc relative symbol value */ - R_X86_64_8 = 14, /* Add 8bit zx symbol value */ - R_X86_64_PC8 = 15 /* Add 8bit sx pc relative symbol value */ + R_X86_64_64 = 1, /* word64, S + A */ + R_X86_64_PC32 = 2, /* word32, S + A - P */ + R_X86_64_GOT32 = 3, /* word32, G + A */ + R_X86_64_PLT32 = 4, /* word32, L + A - P */ + R_X86_64_COPY = 5, /* none */ + R_X86_64_GLOB_DAT = 6, /* word64, S, set GOT entry to data address */ + R_X86_64_JMP_SLOT = 7, /* word64, S, set GOT entry to code address */ + R_X86_64_RELATIVE = 8, /* word64, B + A */ + R_X86_64_GOTPCREL = 9, /* word32, G + GOT + A - P */ + R_X86_64_32 = 10, /* word32 (zero extend), S + A */ + R_X86_64_32S = 11, /* word32 (sign extend), S + A */ + R_X86_64_16 = 12, /* word16, S + A */ + R_X86_64_PC16 = 13, /* word16, S + A - P */ + R_X86_64_8 = 14, /* word8, S + A */ + R_X86_64_PC8 = 15, /* word8, S + A - P */ + R_X86_64_DPTMOD64 = 16, /* word64, ID of module containing symbol */ + R_X86_64_DTPOFF64 = 17, /* word64, offset in TLS block */ + R_X86_64_TPOFF64 = 18, /* word64, offset in initial TLS block */ + R_X86_64_TLSGD = 19, /* word32, PC-rel offset to GD GOT block */ + R_X86_64_TLSLD = 20, /* word32, PC-rel offset to LD GOT block */ + R_X86_64_DTPOFF32 = 21, /* word32, offset to TLS block */ + R_X86_64_GOTTPOFF = 22, /* word32, PC-rel offset to IE GOT entry */ + R_X86_64_TPOFF32 = 23 /* word32, offset in initial TLS block */ } elf_x86_64_relocation_type; struct elf_secthead { diff --git a/modules/objfmts/elf/tests/Makefile.inc b/modules/objfmts/elf/tests/Makefile.inc index 82b9ea2d..100cca0d 100644 --- a/modules/objfmts/elf/tests/Makefile.inc +++ b/modules/objfmts/elf/tests/Makefile.inc @@ -25,8 +25,9 @@ EXTRA_DIST += modules/objfmts/elf/tests/elfglobal.hex EXTRA_DIST += modules/objfmts/elf/tests/elfglobext.asm EXTRA_DIST += modules/objfmts/elf/tests/elfglobext.errwarn EXTRA_DIST += modules/objfmts/elf/tests/elfglobext.hex -EXTRA_DIST += modules/objfmts/elf/tests/elfreloc-err.asm -EXTRA_DIST += modules/objfmts/elf/tests/elfreloc-err.errwarn +EXTRA_DIST += modules/objfmts/elf/tests/elfreloc-ext.asm +EXTRA_DIST += modules/objfmts/elf/tests/elfreloc-ext.errwarn +EXTRA_DIST += modules/objfmts/elf/tests/elfreloc-ext.hex EXTRA_DIST += modules/objfmts/elf/tests/elfabssect.asm EXTRA_DIST += modules/objfmts/elf/tests/elfabssect.errwarn EXTRA_DIST += modules/objfmts/elf/tests/elfabssect.hex diff --git a/modules/objfmts/elf/tests/elfreloc-err.errwarn b/modules/objfmts/elf/tests/elfreloc-err.errwarn deleted file mode 100644 index 45779b88..00000000 --- a/modules/objfmts/elf/tests/elfreloc-err.errwarn +++ /dev/null @@ -1,2 +0,0 @@ --:3: elf: invalid relocation size --:4: elf: invalid relocation size diff --git a/modules/objfmts/elf/tests/elfreloc-err.asm b/modules/objfmts/elf/tests/elfreloc-ext.asm similarity index 100% rename from modules/objfmts/elf/tests/elfreloc-err.asm rename to modules/objfmts/elf/tests/elfreloc-ext.asm diff --git a/modules/objfmts/elf/tests/elfreloc-ext.errwarn b/modules/objfmts/elf/tests/elfreloc-ext.errwarn new file mode 100644 index 00000000..e69de29b diff --git a/modules/objfmts/elf/tests/elfreloc-ext.hex b/modules/objfmts/elf/tests/elfreloc-ext.hex new file mode 100644 index 00000000..4c1fce85 --- /dev/null +++ b/modules/objfmts/elf/tests/elfreloc-ext.hex @@ -0,0 +1,464 @@ +7f +45 +4c +46 +01 +01 +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +01 +00 +03 +00 +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +e0 +00 +00 +00 +00 +00 +00 +00 +34 +00 +00 +00 +00 +00 +28 +00 +06 +00 +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +b8 +00 +00 +00 +00 +66 +b8 +00 +00 +b0 +00 +00 +01 +00 +00 +00 +01 +03 +00 +00 +07 +00 +00 +00 +14 +03 +00 +00 +0a +00 +00 +00 +16 +03 +00 +00 +00 +2e +74 +65 +78 +74 +00 +2e +72 +65 +6c +2e +74 +65 +78 +74 +00 +2e +73 +74 +72 +74 +61 +62 +00 +2e +73 +79 +6d +74 +61 +62 +00 +2e +73 +68 +73 +74 +72 +74 +61 +62 +00 +00 +00 +2d +00 +76 +61 +72 +69 +61 +62 +6c +65 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +00 +f1 +ff +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +03 +00 +04 +00 +03 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +03 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +64 +00 +00 +00 +2b +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +11 +00 +00 +00 +03 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +90 +00 +00 +00 +0c +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +19 +00 +00 +00 +02 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +9c +00 +00 +00 +40 +00 +00 +00 +02 +00 +00 +00 +03 +00 +00 +00 +04 +00 +00 +00 +10 +00 +00 +00 +01 +00 +00 +00 +01 +00 +00 +00 +06 +00 +00 +00 +00 +00 +00 +00 +40 +00 +00 +00 +0b +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +10 +00 +00 +00 +00 +00 +00 +00 +07 +00 +00 +00 +09 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +4c +00 +00 +00 +18 +00 +00 +00 +03 +00 +00 +00 +04 +00 +00 +00 +04 +00 +00 +00 +08 +00 +00 +00