mirror of
https://github.com/samsonjs/compiler.git
synced 2026-03-25 08:45:52 +00:00
[FIXED] compiler appends _exit code to binary output
This commit is contained in:
parent
b7a4b408bb
commit
d22e3b6306
4 changed files with 15 additions and 2 deletions
|
|
@ -277,7 +277,7 @@ main(int argc, const char *argv[])
|
|||
}
|
||||
fclose(fd);
|
||||
|
||||
printf("Writing x86 ELF binary to %s...\n", argv[1]);
|
||||
printf("Writing x86 ELF binary to %s...\n", argv[3]);
|
||||
result = elf_write(argv[3], code, code_size);
|
||||
if (result < 0) {
|
||||
printf("[error] elf_write failed.\n");
|
||||
|
|
|
|||
1
min.code
Normal file
1
min.code
Normal file
|
|
@ -0,0 +1 @@
|
|||
a=0
|
||||
4
min2.asm
Normal file
4
min2.asm
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
BITS 32
|
||||
mov ebx,eax
|
||||
mov eax,1
|
||||
int 0x80
|
||||
10
test.rb
10
test.rb
|
|
@ -1,6 +1,11 @@
|
|||
require 'compiler'
|
||||
require 'stringio'
|
||||
|
||||
X86_exit = [0x89, 0xc3, # mov ebx, eax (exit code)
|
||||
0xb8, 1, 0, 0, 0, # mov eax, 1
|
||||
0xcd, 0x80 # int 0x80
|
||||
].pack('c*')
|
||||
|
||||
def error(msg) STDERR.puts(msg) end
|
||||
|
||||
def parse(input)
|
||||
|
|
@ -33,7 +38,10 @@ def main(arg)
|
|||
template = File.read("template.asm")
|
||||
asm = interpolate(template, :data => data, :bss => bss, :code => code)
|
||||
File.open("test.asm", "w") { |f| f.puts(asm) }
|
||||
File.open("test.bin", "wb") { |f| f.write(binary) }
|
||||
File.open("test.bin", "wb") { |f|
|
||||
f.write(binary)
|
||||
f.write(X86_exit)
|
||||
}
|
||||
end
|
||||
|
||||
main(ARGV[0].to_s)
|
||||
|
|
|
|||
Loading…
Reference in a new issue