Last active
July 4, 2019 07:03
-
-
Save kawakami-o3/ae0325c1d666b3b467cf0df988ec5750 to your computer and use it in GitHub Desktop.
print without libc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just an example. | |
#include<unistd.h> | |
int main() { | |
write(1, "hello\n", 6); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.section .rodata | |
.LC0: | |
.string "hello\n" | |
.text | |
.globl main | |
.type main, @function | |
main: | |
.LFB0: | |
.cfi_startproc | |
pushq %rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset 6, -16 | |
movq %rsp, %rbp | |
.cfi_def_cfa_register 6 | |
movl $6, %edx | |
movl $.LC0, %esi | |
movl $1, %edi | |
movl $1, %eax | |
syscall | |
movl $0, %eax | |
popq %rbp | |
.cfi_def_cfa 7, 8 | |
ret | |
.cfi_endproc |
$ as main.s -o main.o && ld main.o && ./a.out
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000
hello
fish: './a.out' terminated by signal SIGSEGV (Address boundary error)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
as -> ld -> a.out
https://kaworu.jpn.org/kaworu/2011-11-10-1.php#2011-11-10-1-ea19956fd16d4bbfd5c71de263cd2ace