剥离标签但不是二进制函数调用

时间:2013-12-15 18:32:32

标签: assembly x86-64 nasm strip

所以最近我一直在用NASM程序集编写程序,每当我为一些跳转/循环添加标签时,我注意到objdump和gdb会将它视为一个单独的部分,如下所示:

hello.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <_start>:
   0:   48 31 c0                xor    rax,rax

0000000000000003 <_start_loop>:
   3:   50                      push   rax
   4:   48 83 e0 01             and    rax,0x1
   8:   75 0c                   jne    16 <_start_nope>
   a:   68 00 00 00 00          push   0x0
   f:   e8 22 00 00 00          call   36 <print>
  14:   eb 0a                   jmp    20 <_start_check>

0000000000000016 <_start_nope>:
  16:   68 00 00 00 00          push   0x0
  1b:   e8 16 00 00 00          call   36 <print>

0000000000000020 <_start_check>:
  20:   58                      pop    rax
  21:   48 ff c0                inc    rax
  24:   48 83 f8 0a             cmp    rax,0xa
  28:   75 d9                   jne    3 <_start_loop>
  2a:   b8 3c 00 00 00          mov    eax,0x3c
  2f:   bf 00 00 00 00          mov    edi,0x0
  34:   0f 05                   syscall 

0000000000000036 <print>:
  36:   48 8b 74 24 08          mov    rsi,QWORD PTR [rsp+0x8]
  3b:   56                      push   rsi
  3c:   e8 12 00 00 00          call   53 <strlen>
  41:   48 89 c2                mov    rdx,rax
  44:   bf 01 00 00 00          mov    edi,0x1
  49:   b8 01 00 00 00          mov    eax,0x1
  4e:   0f 05                   syscall 
  50:   c2 08 00                ret    0x8

0000000000000053 <strlen>:
  53:   48 8b 5c 24 08          mov    rbx,QWORD PTR [rsp+0x8]
  58:   48 31 c0                xor    rax,rax

000000000000005b <strlen_begin>:
  5b:   8a 0c 03                mov    cl,BYTE PTR [rbx+rax*1]
  5e:   84 c9                   test   cl,cl
  60:   74 05                   je     67 <strlen_done>
  62:   48 ff c0                inc    rax
  65:   eb f4                   jmp    5b <strlen_begin>

0000000000000067 <strlen_done>:
  67:   c2 08 00                ret    0x8

我希望能够有效地删除_start_nope等标签,但保留功能标签,例如_startprintstrlen。我有什么方法可以做到这一点吗?

所以基本上我最终希望hello.o看起来像

hello.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <_start>:
   0:   48 31 c0                xor    rax,rax
   3:   50                      push   rax
   4:   48 83 e0 01             and    rax,0x1
   8:   75 0c                   jne    0x16
   a:   68 00 00 00 00          push   0x0
   f:   e8 22 00 00 00          call   0x36 <print>
  14:   eb 0a                   jmp    0x20
  16:   68 00 00 00 00          push   0x0
  1b:   e8 16 00 00 00          call   0x36 <print>
  20:   58                      pop    rax
  21:   48 ff c0                inc    rax
  24:   48 83 f8 0a             cmp    rax,0xa
  28:   75 d9                   jne    0x3
  2a:   b8 3c 00 00 00          mov    eax,0x3c
  2f:   bf 00 00 00 00          mov    edi,0x0
  34:   0f 05                   syscall 

0000000000000036 <print>:
  36:   48 8b 74 24 08          mov    rsi,QWORD PTR [rsp+0x8]
  3b:   56                      push   rsi
  3c:   e8 12 00 00 00          call   0x53 <strlen>
  41:   48 89 c2                mov    rdx,rax
  44:   bf 01 00 00 00          mov    edi,0x1
  49:   b8 01 00 00 00          mov    eax,0x1
  4e:   0f 05                   syscall 
  50:   c2 08 00                ret    0x8

0000000000000053 <strlen>:
  53:   48 8b 5c 24 08          mov    rbx,QWORD PTR [rsp+0x8]
  58:   48 31 c0                xor    rax,rax
  5b:   8a 0c 03                mov    cl,BYTE PTR [rbx+rax*1]
  5e:   84 c9                   test   cl,cl
  60:   74 05                   je     0x67
  62:   48 ff c0                inc    rax
  65:   eb f4                   jmp    0x5b
  67:   c2 08 00                ret    0x8

1 个答案:

答案 0 :(得分:0)

NAMS还支持以..@开头的“特殊本地标签”,例如

..@lbl:  nop
         jmp ..@lbl

here。不幸的是,我找不到任何关于匿名符号的内容,我认为这就是你要求的内容。