1 BITS 64 2 3 global x86ident 4 global __savident 5 extern foobar ; :proc 6 extern foobar2 ; :abs 7 extern foobar3 ; :qword 8 extern foobar4 ; :byte 9 10 [SECTION .data] 11 __savident dd 0 12 savidentptr dd __savident 13 savidentptr2 dq __savident 14 x86identptr dd x86ident 15 x86identptr2 dq x86ident 16 foobarptr dd foobar 17 foobarptr2 dq foobar 18 foobar2ptr dd foobar2 19 foobar2ptr2 dq foobar2 20 foobar3ptr dd foobar3 21 foobar3ptr2 dq foobar3 22 xptr dd x 23 xptr2 dq x 24 25 [SECTION .bss] 26 x resq 1 27 y resq 1 28 29 [SECTION .text] 30 x86ident: 31 ; extern with :proc 32 ; This instruction generates a different relocation than 33 ; MASM does at present. 34 mov ebx, foobar ; WTF ML64.. this had [] 35 mov rcx, qword foobar 36 lea rdx, [foobar wrt rip] 37 mov rax, [foobar+rcx] 38 mov rax, qword foobar 39 mov rbx, qword foobar 40 movzx rax, byte [foobar wrt rip] 41 movzx rax, byte [foobar+rax] 42 43 ; local "proc" 44 ; See note above 45 mov ebx, trap 46 mov rcx, qword trap 47 ; MASM generates a REL32 reloc for this even though it's in 48 ; the same section. I don't know why, as the call instruction 49 ; below doesn't cause a reloc, so the linker can't be moving 50 ; functions around within an object! 51 lea rdx, [trap wrt rip] 52 mov rax, [trap+rcx] 53 mov rax, qword trap 54 mov rbx, qword trap 55 ; MASM generates a REL32 reloc for this even though it's in 56 ; the same section. I don't know why, as the call instruction 57 ; below doesn't cause a reloc, so the linker can't be moving 58 ; functions around within an object! 59 movzx rax, byte [trap wrt rip] 60 movzx rax, byte [trap+rax] 61 62 ; with :abs 63 ;mov ebx,[foobar2] 64 ;mov rcx,offset foobar2 65 ;lea rdx, foobar2 66 ;mov rax, qword ptr foobar2[rcx] 67 ;mov rax, foobar2 68 ;mov rbx, foobar2 69 ;movzx rax, byte ptr foobar2 70 ;movzx rax, byte ptr foobar2[rax] 71 72 ; with :qword 73 ; See note above 74 mov ebx, foobar3 75 mov ebx, [foobar3 wrt rip] 76 mov rcx, qword foobar3 77 lea rdx, [foobar3 wrt rip] 78 mov rax, [foobar3+rcx] 79 mov rax, [foobar3 wrt rip] 80 mov rbx, [foobar3 wrt rip] 81 movzx rax, byte [foobar3 wrt rip] 82 movzx rax, byte [foobar3+rax] 83 84 ; local var (dword) 85 ; See note above 86 mov ebx, __savident 87 mov ebx,[__savident wrt rip] 88 mov rcx, qword __savident 89 lea rdx, [__savident wrt rip] 90 mov rax, [__savident+rcx] 91 mov rax, [__savident wrt rip] 92 mov rbx, [__savident wrt rip] 93 movzx rax, byte [__savident wrt rip] 94 movzx rax, byte [__savident+rax] 95 96 ; local var (qword) 97 ; See note above 98 mov ebx, savidentptr2 99 mov ebx, [savidentptr2 wrt rip] 100 mov rcx, qword savidentptr2 101 lea rdx, [savidentptr2 wrt rip] 102 mov rax, [savidentptr2+rcx] 103 mov rax, [savidentptr2 wrt rip] 104 mov rbx, [savidentptr2 wrt rip] 105 movzx rax, byte [savidentptr2 wrt rip] 106 movzx rax, byte [savidentptr2+rax] 107 108 ; bss local var (qword) 109 ; See note above 110 mov ebx, y 111 mov ebx, [y wrt rip] 112 mov rcx, qword y 113 lea rdx, [y wrt rip] 114 mov rax, [y+rcx] 115 mov rax, [y wrt rip] 116 mov rbx, [y wrt rip] 117 movzx rax, byte [y wrt rip] 118 movzx rax, byte [y+rax] 119 120 call foobar 121 122 call trap 123 124 ret 125 126 trap: sub rsp, 256 127 int3 128 add rsp, 256 129 .end 130 131 [SECTION .pdata] 132 dd trap 133 dd trap.end wrt trap 134 dd $$xdatasym 135 136 [SECTION .xdata] 137 $$xdatasym: 138 db 1, 7, 2, 0, 7, 1, 0x20, 0 139 140 [SECTION _FOO] 141 foo_foobar3ptr dd foobar3 142 foo_foobar3ptr2 dq foobar3 143 mov ebx, [foobar3 wrt rip] 144 mov rcx, qword foobar3 145 lea rdx, [foobar3 wrt rip] 146 mov rax, [foobar3+rcx] 147 mov rax, [foobar3 wrt rip] 148 mov rbx, [foobar3 wrt rip] 149 movzx rax, byte [foobar3 wrt rip] 150 movzx rax, byte [foobar3+rax] 151 152