1

What does callq 400b90 <signal@plt> do?

How would it look line in C?

4013a2:       48 83 ec 08             sub    $0x8,%rsp
4013a6:       be a0 12 40 00          mov    $0x4012a0,%esi
4013ab:       bf 02 00 00 00          mov    $0x2,%edi
4013b0:       e8 db f7 ff ff          callq  400b90 <signal@plt>
4013b5:       48 83 c4 08             add    $0x8,%rsp
4013b9:       c3                      retq
dud3
  • 409
  • 1
  • 6
  • 16

1 Answers1

3

What does callq 400b90 <signal@plt> do?

Call the signal function via the PLT (procedure linkage table). So more technical: It pushes the current instruction pointer onto the stack and jumps to signal@plt.

How would it look line in C?

void* foo(void) {
    return signal(2, (void *) 0x4012a0);
}

Let's look at your code line-by-line:

sub    $0x8,%rsp

This reserves some stack space. You can ignore this (the stack space is unused).

mov    $0x4012a0,%esi
mov    $0x2,%edi

Put the value 0x4012a0 and 0x2 in the registers ESI and EDI. By the ABI, this is how arguments are passed to a function.

callq  400b90 <signal@plt>

Call the function signal through the PLT. The PLT has something to do with the dynamic linker since we cannot be sure where the signal function will end up in memory whenthis is built. Basically, this just finds the final memory location and calls signal.

add    $0x8,%rsp
retq

Undo the sub from earlier and return to the caller.

Uli Schlachter
  • 9,337
  • 1
  • 23
  • 39