Assembly calls are called twice without even calling them from the main

I am trying to define some routines that have printf calls in it. A very trivial example:

extern printf
LINUX        equ     80H
EXIT         equ     60

section .data
    intfmt: db "%ld", 10, 0

segment .text
    global  main

main:
    call os_return      ; return to operating system

os_return:
    mov  rax, EXIT      ; Linux system call 60 i.e. exit ()
    mov  rdi, 0     ; Error code 0 i.e. no errors
    int  LINUX      ; Interrupt Linux kernel

test:
    push rdi
    push rsi
    mov rsi, 10
    mov rdi, intfmt
    xor rax, rax
    call printf
    pop rdi
    pop rsi
    ret

Here, the test call has only the printf call, which displays the number 10 on the screen. I would not expect this to be triggered since I am not calling him.

However, when compiling and running:

nasm -f elf64 test.asm
gcc -m64 -o test test.o

I get the output:

10
10

I am completely puzzled and wonder if anyone can explain why this is happening.

+5
source share
2 answers

int 80H 32- , : a) 32- b) 32- , 64- . umask .

64- syscall:

...
os_return:
    mov  rax, EXIT      ; Linux system call 60 i.e. exit ()
    mov  rdi, 0     ; Error code 0 i.e. no errors
    syscall         ; Interrupt Linux kernel
...
+3

, exit , , , test, 10.

, ret, call os_return, os_return. test. ret main .

, exit , , 64- . exit libc , . , int LINUX 32-, 64- Linux .

+2

All Articles