如何防止ld添加.note.gnu.property? [英] How do I prevent ld from adding .note.gnu.property?

查看:60
本文介绍了如何防止ld添加.note.gnu.property?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个玩具x86汇编程序,我正在用 as ld 编写和编译:

I've got a toy x86 assembly program that I'm writing and compiling with as and ld:

.text

    .global _start

_start:
    movq    $1, %rax
    movq    $0x7FFFFFFF, %rbx
L1:
    cmp     %rbx, %rax          
    je      L2
    addq    $1, %rax
    jmp     L1
L2:

    movq    %rax, %rbx
    movq    $1, %rax
    int     $0x80

然后构建:

as -o test.o test.S
ld -s -o test test.o

第二步- ld -产生附加注释:

The second step of this -- ld -- generates an additional note:

$ objdump -D test

test:     file format elf64-x86-64


Disassembly of section .note.gnu.property:

00000000004000e8 <.note.gnu.property>:
  4000e8:       04 00                   add    $0x0,%al
  4000ea:       00 00                   add    %al,(%rax)
  4000ec:       10 00                   adc    %al,(%rax)
  4000ee:       00 00                   add    %al,(%rax)
  4000f0:       05 00 00 00 47          add    $0x47000000,%eax
  4000f5:       4e 55                   rex.WRX push %rbp
  4000f7:       00 01                   add    %al,(%rcx)
  4000f9:       00 00                   add    %al,(%rax)
  4000fb:       c0 04 00 00             rolb   $0x0,(%rax,%rax,1)
  4000ff:       00 01                   add    %al,(%rcx)
  400101:       00 00                   add    %al,(%rax)
  400103:       00 00                   add    %al,(%rax)
  400105:       00 00                   add    %al,(%rax)
        ...

Disassembly of section .text:

0000000000401000 <.text>:
  401000:       48 c7 c0 01 00 00 00    mov    $0x1,%rax
  401007:       48 c7 c3 ff ff ff 7f    mov    $0x7fffffff,%rbx
  40100e:       48 39 d8                cmp    %rbx,%rax
  401011:       74 06                   je     0x401019
  401013:       48 83 c0 01             add    $0x1,%rax
  401017:       eb f5                   jmp    0x40100e
  401019:       48 89 c3                mov    %rax,%rbx
  40101c:       48 c7 c0 01 00 00 00    mov    $0x1,%rax
  401023:       cd 80                   int    $0x80

是否有消除或阻止生成.note.gnu.property部分的方法?

Is there a way to eliminate or prevent generation of the .note.gnu.property section?

推荐答案

我没有找到传递给ld的直接标志来阻止该节的生成(-s或-s -x都无法工作),甚至没有调用 strip --strip-all 不会删除此部分,但是, strip --remove-section = .note.gnu.property test 确实删除了该部分:

I didn't find a direct flag to pass to ld to prevent this section's generation (neither -s nor -s -x work), even calling strip --strip-all doesn't remove this section, however, strip --remove-section=.note.gnu.property test did remove the section:

$ as -o test.o test.s 
$ ld -o test test.o 
$ objdump -D test

test:     file format elf64-x86-64


Disassembly of section .note.gnu.property:

00000000004000e8 <.note.gnu.property>:
  4000e8:   04 00                   add    $0x0,%al
  4000ea:   00 00                   add    %al,(%rax)
  4000ec:   10 00                   adc    %al,(%rax)
  4000ee:   00 00                   add    %al,(%rax)
  4000f0:   05 00 00 00 47          add    $0x47000000,%eax
  4000f5:   4e 55                   rex.WRX push %rbp
  4000f7:   00 01                   add    %al,(%rcx)
  4000f9:   00 00                   add    %al,(%rax)
  4000fb:   c0 04 00 00             rolb   $0x0,(%rax,%rax,1)
  4000ff:   00 01                   add    %al,(%rcx)
  400101:   00 00                   add    %al,(%rax)
  400103:   00 00                   add    %al,(%rax)
  400105:   00 00                   add    %al,(%rax)
    ...

Disassembly of section .text:

0000000000401000 <_start>:
  401000:   48 c7 c0 01 00 00 00    mov    $0x1,%rax
  401007:   48 c7 c3 ff ff ff 7f    mov    $0x7fffffff,%rbx

000000000040100e <L1>:
  40100e:   48 39 d8                cmp    %rbx,%rax
  401011:   74 06                   je     401019 <L2>
  401013:   48 83 c0 01             add    $0x1,%rax
  401017:   eb f5                   jmp    40100e <L1>

0000000000401019 <L2>:
  401019:   48 89 c3                mov    %rax,%rbx
  40101c:   48 c7 c0 01 00 00 00    mov    $0x1,%rax
  401023:   cd 80                   int    $0x80

$ strip --remove-section=.note.gnu.property test
strip: test: warning: empty loadable segment detected at vaddr=0x400000, is this intentional?
$ objdump -D test

test:     file format elf64-x86-64


Disassembly of section .text:

0000000000401000 <.text>:
  401000:   48 c7 c0 01 00 00 00    mov    $0x1,%rax
  401007:   48 c7 c3 ff ff ff 7f    mov    $0x7fffffff,%rbx
  40100e:   48 39 d8                cmp    %rbx,%rax
  401011:   74 06                   je     0x401019
  401013:   48 83 c0 01             add    $0x1,%rax
  401017:   eb f5                   jmp    0x40100e
  401019:   48 89 c3                mov    %rax,%rbx
  40101c:   48 c7 c0 01 00 00 00    mov    $0x1,%rax
  401023:   cd 80                   int    $0x80

这篇关于如何防止ld添加.note.gnu.property?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆