Skip to content

Commit 29a8766

Browse files
committed
Fix some compatibility issues with newer systems.
Fix #24 Fix #21
1 parent 2a2a872 commit 29a8766

File tree

8 files changed

+64
-57
lines changed

8 files changed

+64
-57
lines changed

Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,13 @@ tool.debug: e9tool.o
5454

5555
loader_elf:
5656
$(CXX) -std=c++11 -Wall -fno-stack-protector -Wno-unused-function -fPIC \
57-
-mno-mmx -mno-sse -mno-avx -mno-avx2 -mno-avx512f -msoft-float \
5857
-Os -c src/e9patch/e9loader_elf.cpp
5958
$(CXX) -pie -nostdlib -o e9loader_elf.bin e9loader_elf.o -T e9loader.ld
6059
xxd -i e9loader_elf.bin > src/e9patch/e9loader_elf.c
6160

6261
loader_pe:
6362
$(CXX) -std=c++11 -Wall -fno-stack-protector -Wno-unused-function -fPIC \
6463
-mabi=ms -fshort-wchar \
65-
-mno-mmx -mno-sse -mno-avx -mno-avx2 -mno-avx512f -msoft-float \
6664
-Os -c src/e9patch/e9loader_pe.cpp
6765
$(CXX) -pie -nostdlib -o e9loader_pe.bin e9loader_pe.o -T e9loader.ld
6866
xxd -i e9loader_pe.bin > src/e9patch/e9loader_pe.c

e9loader.ld

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
SECTIONS
22
{
3-
.text : { *(.text .rodata .rodata.* .data .data.*) }
3+
.text : { *(.text.entry)
4+
*(.text .rodata .rodata.* .data .data.*) }
5+
/DISCARD/ : { *(*) }
46
}
57
OUTPUT_FORMAT(binary)

src/e9patch/e9elf.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ bool parseElf(Binary *B)
150150
{
151151
intptr_t vstart = (intptr_t)phdr->p_vaddr;
152152
intptr_t vend = vstart + phdr->p_memsz;
153-
if (!reserve(B, vstart, vend))
153+
if (vend - vstart > 0 && !reserve(B, vstart, vend))
154154
error("failed to reserve address space range %p..%p",
155155
vstart, vend);
156156
break;

src/e9patch/e9loader_elf.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ asm (
5050
*/
5151
".globl _entry\n"
5252
".type _entry,@function\n"
53+
".section .text.entry,\"x\",@progbits\n"
5354
"_entry:\n"
5455
"\tcallq e9loader\n"
5556
"\tpop %rdx\n"
@@ -59,6 +60,7 @@ asm (
5960

6061
".globl e9syscall\n"
6162
".type e9syscall,@function\n"
63+
".section .text\n"
6264
"e9syscall:\n"
6365
"\tmov %edi, %eax\n"
6466
"\tmov %rsi, %rdi\n"

test/regtest/example_5.exp

+52-52
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 48 8b 05 5e 00 00 00 movq 0x5e(%rip), %rax
2-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 48 bb 11 22 33 44 55 66 mov $0x8877665544332211, %rbx
1+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 48 8b 05 5e 00 00 00 movq 0x5e(%rip), %rax
2+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 48 bb 11 22 33 44 55 66 mov $0x8877665544332211, %rbx
33
77 88
4-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 48 39 c3 cmp %rax, %rbx
5-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 0f 1f 00 nopl %eax, (%rax)
6-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 83 fb 33 cmp $0x33, %ebx
7-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 4c 8b 05 28 00 00 00 movq 0x28(%rip), %r8
8-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 48 8b 0d 9a 01 00 00 movq 0x19a(%rip), %rcx
9-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 4c 39 c1 cmp %r8, %rcx
10-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 0f 1f 40 00 nopl %eax, (%rax)
11-
0000000094949494:00000000a5a5a5a5:00000000b6b6b6b6: 4c 8d 15 14 00 00 00 lea 0x14(%rip), %r10
12-
000000000a000192:00000000a5a5a5a5:00000000b6b6b6b6: 48 c7 c1 89 88 ff ff mov $-0x7777, %rcx
13-
000000000a000192:00000000a5a5a5a5:00000000b6b6b6b6: 48 83 c4 08 add $0x8, %rsp
14-
000000000a000192:00000000a5a5a5a5:00000000b6b6b6b6: 48 8d 15 02 00 00 00 lea 0x2(%rip), %rdx
15-
000000000a000192:00000000a5a5a5a5:00000000b6b6b6b6: 49 83 c1 06 add $0x6, %r9
16-
000000000a000192:00000000a5a5a5a5:00000000b6b6b6b6: 4d 01 ca add %r9, %r10
17-
000000008d83851b:00000000a5a5a5a5:00000000b6b6b6b6: 49 83 e8 08 sub $0x8, %r8
18-
000000008d83851b:00000000a5a5a5a5:00000000b6b6b6b6: 4d 29 c2 sub %r8, %r10
19-
778899ab49506312:00000000a5a5a5a5:00000000b6b6b6b6: 4d 0f af d3 imul %r11, %r10
20-
87bd82518544749a:00000000a5a5a5a5:00000000b6b6b6b6: 4d 6b d3 77 imul $0x77, %r11, %r10
21-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 25 fe 00 00 00 and $0xfe, %rax
22-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 21 c3 and %rax, %rbx
23-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 83 cb 13 or $0x13, %rbx
24-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 09 cb or %rcx, %rbx
25-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 c1 e7 07 shl $0x7, %rdi
26-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 c1 ff 03 sar $0x3, %rdi
27-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 c7 c0 19 45 00 00 mov $0x4519, %rax
28-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 66 0f ef c0 pxor %xmm0, %xmm0
29-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: f3 48 0f 2a c0 cvtsi2ss %rax, %xmm0
30-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: f3 0f 51 c8 sqrtss %xmm0, %xmm1
31-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 0f 2f c8 comiss %xmm0, %xmm1
32-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: f3 48 0f 2c c1 cvttss2si %xmm1, %rax
33-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 3d 85 00 00 00 cmp $0x85, %rax
34-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 8b 84 24 00 ff ff ff movq -0x100(%rsp), %rax
35-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 85 c0 test %rax, %rax
36-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 31 f6 xor %esi, %esi
37-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 8b 84 f4 00 ff ff ff movq -0x100(%rsp,%rsi,8), %rax
38-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 85 c0 test %rax, %rax
39-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 2e 48 8b 84 f4 00 ff ff movq %cs:-0x100(%rsp,%rsi,8), %rax
4+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 48 39 c3 cmp %rax, %rbx
5+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 0f 1f 00 nopl %eax, (%rax)
6+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 83 fb 33 cmp $0x33, %ebx
7+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 4c 8b 05 28 00 00 00 movq 0x28(%rip), %r8
8+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 48 8b 0d 9a 01 00 00 movq 0x19a(%rip), %rcx
9+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 4c 39 c1 cmp %r8, %rcx
10+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 0f 1f 40 00 nopl %eax, (%rax)
11+
0000000094949494:00000000c7c7c7c7:00000000b6b6b6b6: 4c 8d 15 14 00 00 00 lea 0x14(%rip), %r10
12+
000000000a000192:00000000c7c7c7c7:00000000b6b6b6b6: 48 c7 c1 89 88 ff ff mov $-0x7777, %rcx
13+
000000000a000192:00000000c7c7c7c7:00000000b6b6b6b6: 48 83 c4 08 add $0x8, %rsp
14+
000000000a000192:00000000c7c7c7c7:00000000b6b6b6b6: 48 8d 15 02 00 00 00 lea 0x2(%rip), %rdx
15+
000000000a000192:00000000c7c7c7c7:00000000b6b6b6b6: 49 83 c1 06 add $0x6, %r9
16+
000000000a000192:00000000c7c7c7c7:00000000b6b6b6b6: 4d 01 ca add %r9, %r10
17+
000000008d83851b:00000000c7c7c7c7:00000000b6b6b6b6: 49 83 e8 08 sub $0x8, %r8
18+
000000008d83851b:00000000c7c7c7c7:00000000b6b6b6b6: 4d 29 c2 sub %r8, %r10
19+
778899ab49506312:00000000c7c7c7c7:00000000b6b6b6b6: 4d 0f af d3 imul %r11, %r10
20+
87bd82518544749a:00000000c7c7c7c7:00000000b6b6b6b6: 4d 6b d3 77 imul $0x77, %r11, %r10
21+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 25 fe 00 00 00 and $0xfe, %rax
22+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 21 c3 and %rax, %rbx
23+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 83 cb 13 or $0x13, %rbx
24+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 09 cb or %rcx, %rbx
25+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 c1 e7 07 shl $0x7, %rdi
26+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 c1 ff 03 sar $0x3, %rdi
27+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 c7 c0 19 45 00 00 mov $0x4519, %rax
28+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 66 0f ef c0 pxor %xmm0, %xmm0
29+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: f3 48 0f 2a c0 cvtsi2ss %rax, %xmm0
30+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: f3 0f 51 c8 sqrtss %xmm0, %xmm1
31+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 0f 2f c8 comiss %xmm0, %xmm1
32+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: f3 48 0f 2c c1 cvttss2si %xmm1, %rax
33+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 3d 85 00 00 00 cmp $0x85, %rax
34+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 8b 84 24 00 ff ff ff movq -0x100(%rsp), %rax
35+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 85 c0 test %rax, %rax
36+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 31 f6 xor %esi, %esi
37+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 8b 84 f4 00 ff ff ff movq -0x100(%rsp,%rsi,8), %rax
38+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 85 c0 test %rax, %rax
39+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 2e 48 8b 84 f4 00 ff ff movq %cs:-0x100(%rsp,%rsi,8), %rax
4040
ff
41-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 3e 48 8b 8c f4 00 ff ff movq %ds:-0x100(%rsp,%rsi,8), %rcx
41+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 3e 48 8b 8c f4 00 ff ff movq %ds:-0x100(%rsp,%rsi,8), %rcx
4242
ff
43-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 39 c1 cmp %rax, %rcx
44-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 8b 0c 25 00 00 00 0a movl 0xa000000, %ecx
45-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 8b 8c f0 00 00 00 0a movq 0xa000000(%rax,%rsi,8), %rcx
46-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 8b 14 f5 00 00 00 0a movq 0xa000000(,%rsi,8), %rdx
47-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 39 ca cmp %rcx, %rdx
48-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 8b 14 25 08 00 00 0a movq 0xa000008, %rdx
49-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 39 ca cmp %rcx, %rdx
50-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 31 c0 xor %eax, %eax
51-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 89 c7 mov %eax, %edi
52-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 8d 35 54 00 00 00 lea 0x54(%rip), %rsi
53-
0000004cffffffb3:00000000a5a5a5a5:00000000b6b6b6b6: 48 c7 c2 07 00 00 00 mov $0x7, %rdx
43+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 39 c1 cmp %rax, %rcx
44+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 8b 0c 25 00 00 00 0a movl 0xa000000, %ecx
45+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 8b 8c f0 00 00 00 0a movq 0xa000000(%rax,%rsi,8), %rcx
46+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 8b 14 f5 00 00 00 0a movq 0xa000000(,%rsi,8), %rdx
47+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 39 ca cmp %rcx, %rdx
48+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 8b 14 25 08 00 00 0a movq 0xa000008, %rdx
49+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 39 ca cmp %rcx, %rdx
50+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 31 c0 xor %eax, %eax
51+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 89 c7 mov %eax, %edi
52+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 8d 35 54 00 00 00 lea 0x54(%rip), %rsi
53+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 48 c7 c2 07 00 00 00 mov $0x7, %rdx
5454
PASSED
55-
0000004cffffffb3:0000000000000202:00000000b6b6b6b6: b8 3c 00 00 00 mov $0x3c, %eax
56-
0000004cffffffb3:0000000000000202:00000000b6b6b6b6: 31 ff xor %edi, %edi
55+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: b8 3c 00 00 00 mov $0x3c, %eax
56+
0000004cffffffb3:00000000c7c7c7c7:00000000b6b6b6b6: 31 ff xor %edi, %edi

test/regtest/example_5.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./test -M 'op.size > 1' -A 'call entry(r10,r11,r12,instr,size,asm)@inst'
1+
./test -M 'op.size > 1' -A 'call entry(r10,r13,r12,instr,size,asm)@inst'

test/regtest/regtest.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ static bool runTest(const struct dirent *test, const std::string &options)
123123
r, out.c_str());
124124
return false;
125125
}
126+
command.clear();
127+
command = "sed -i 's/ (core dumped)//g' ";
128+
command += out;
129+
system(command.c_str());
126130

127131
// Step (3): compare the output
128132
FILE *OUT = fopen(out.c_str(), "r");

test/regtest/test.s

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ data_END:
237237
lea .Lstring(%rip),%rsi
238238
mov $7, %rdx
239239
syscall
240+
# Note: %r11 is undefined after syscall
240241

241242
mov $60,%eax # SYS_exit
242243
xor %edi,%edi

0 commit comments

Comments
 (0)