bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/19252] New: ld rewrites instructions even when asked not to, in


From: srk31 at srcf dot ucam.org
Subject: [Bug ld/19252] New: ld rewrites instructions even when asked not to, in x86-64
Date: Mon, 16 Nov 2015 16:11:21 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=19252

            Bug ID: 19252
           Summary: ld rewrites instructions even when asked not to, in
                    x86-64
           Product: binutils
           Version: 2.25
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: srk31 at srcf dot ucam.org
  Target Milestone: ---

Created attachment 8785
  --> https://sourceware.org/bugzilla/attachment.cgi?id=8785&action=edit
Test case

To reduce use of the GOT, ld sometimes simplifies GOT- into non-GOT relocs on
x86-64. It does so by (perhaps among others) turning R_X86_64_GOTPCREL to
R_X86_64_PC32, and changing the relocated instruction from mov to lea.

I think it should either

- only do this when --relax is passed, or

- only do this when -O is passed, or

- not do this if --no-relax is passed, or

- not do this if -O0 is passed.

It should also have something in the manual to say when it does this.

(Rationale: building a tool that checks correctness properties of a link output
is much more difficult if ld futzes around with instructions. A naive user
would not expect ld to change instructions at all, except as directed by
relocs. Ideally ld would document every additional instruction-level
transformation it makes, in the "Machine Dependent" chapter, and would provide
a way to turn them off.)

The attached tarball illustrates. The first few instructions of __uClibc_main
in the input libc.a are as follows.


00000000000000d2 <__uClibc_main>:
  d2:   41 55                   push   %r13
  d4:   41 54                   push   %r12
  d6:   4d 89 c4                mov    %r8,%r12
  d9:   55                      push   %rbp
  da:   53                      push   %rbx
  db:   48 89 cd                mov    %rcx,%rbp
  de:   48 81 ec 88 01 00 00    sub    $0x188,%rsp
  e5:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax
                        e8: R_X86_64_GOTPCREL   __libc_stack_end-0x4

... whereas in the output (linked with ld -q --no-relax -O0) we see the
following.

0000000000400349 <__uClibc_main>:
  400349:       41 55                   push   %r13
  40034b:       41 54                   push   %r12
  40034d:       4d 89 c4                mov    %r8,%r12
  400350:       55                      push   %rbp
  400351:       53                      push   %rbx
  400352:       48 89 cd                mov    %rcx,%rbp
  400355:       48 81 ec 88 01 00 00    sub    $0x188,%rsp
  40035c:       48 8d 05 3d 1e 20 00    lea    0x201e3d(%rip),%rax
                        40035f: R_X86_64_PC32   __libc_stack_end-0x4

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]