开发者

GAS: jmp to label results in wrong jump?

开发者 https://www.devze.com 2023-03-25 10:02 出处:网络
I am trying to assembly following program: .text .globl _search2 _se开发者_JAVA百科arch2: pushq%rbp movq%rsp, %rbp

I am trying to assembly following program:

    .text
.globl _search2
_se开发者_JAVA百科arch2:
    pushq   %rbp
    movq    %rsp, %rbp
    movq    %rax, -8(%rbp)
go_again:
    cmpl    $0x90909090, (%rax)
    je  go_out
    addq    $0x8, %rax
    jmp     go_again
go_out: 
    leave
    ret

by doing this: "gcc -o test test.s main.c" and I get this:

otool -v -t test

_search2:
0000000100000d0c    pushq   %rbp
0000000100000d0d    movq    %rsp,%rbp
0000000100000d10    movq    %rax,0xf8(%rbp)
go_again:
0000000100000d14    cmpl    $0x90909090,(%rax)
0000000100000d1a    je  0x100000d29
0000000100000d20    addq    $0x08,%rax
0000000100000d24    jmp 0x200000d14
go_out:
0000000100000d29    leave
0000000100000d2a    ret

The jmp is trying to jump to address 0x200000d14 which is totally wrong instead of 0x100000d29 which is marked with go_out label.

Please help.


Try objdump -D test > test.list

00000000004004c4 <_search2>:
  4004c4:   55                      push   %rbp
  4004c5:   48 89 e5                mov    %rsp,%rbp
  4004c8:   48 89 45 f8             mov    %rax,-0x8(%rbp)

00000000004004cc <go_again>:
  4004cc:   81 38 90 90 90 90       cmpl   $0x90909090,(%rax)
  4004d2:   74 06                   je     4004da <go_out>
  4004d4:   48 83 c0 08             add    $0x8,%rax
  4004d8:   eb f2                   jmp    4004cc <go_again>

00000000004004da <go_out>:
  4004da:   c9                      leaveq 
  4004db:   c3                      retq   

See if the tool you are using can display the instructions, if the instructions are the (somewhat the) same then the relative address is correct and you can ignore the address the tool is displaying, or just not use that tool.

If the branches are direct and dont match the target, then there is a gcc/gnu tools problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消