1

i am reading the asm code below,but i do not know what's the meaning of statement

finish(%rip)

the part of asm below:

    /* compute abs address of label finish */
    leaq  finish(%rip), %rcx
    /* save address of finish as return-address for context-function */
    /* will be entered after context-function returns */
    movq  %rcx, 0x40(%rax)

    ret /* return pointer to context-data */

finish:
    /* exit code is zero */
    xorq  %rdi, %rdi
    /* exit application */
    call  _exit@PLT
    hlt

i have search many answer ,the most likely answer is below:

lea eax, msg

makes no sense -- the source is the label (address) msg, which is a (link time) constant and is not in memory anywhere. answer from

question:

i still do not know what's meaning of finish(%rip).
i know finish is label , rip is register ,but what's meaning of finish(%rip)?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Mattia Dinosaur
  • 891
  • 10
  • 29
  • 3
    It's just a syntax for getting the address of `finish` in a rip-relative position independent way. See also the [manual](https://sourceware.org/binutils/docs/as/i386_002dMemory.html). – Jester Jan 22 '19 at 16:04
  • RIP-relative is a special case: instead of adding the absolute address of the symbol with the register like in `lea foo(%rax), %rdi`, `foo(%rip)` addresses `foo` relative to RIP. – Peter Cordes Jan 22 '19 at 17:23
  • `lea eax, msg` is Intel syntax, not AT&T. You can tell because the destination is on the left, and the register has no `%`. It's an inefficient choice vs. `mov $msg, %eax`, though; only ever use LEA for static addresses if you're using RIP-relative. – Peter Cordes Jan 22 '19 at 17:25

0 Answers0