Bug 17482 - -melf32_x86_64 IE->LE transition error
Summary: -melf32_x86_64 IE->LE transition error
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: 2.25
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-14 01:35 UTC by Alan Modra
Modified: 2014-11-12 04:51 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-linux
Build:
Last reconfirmed:


Attachments
A patch (1.10 KB, patch)
2014-10-14 23:43 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Modra 2014-10-14 01:35:05 UTC
Reported in pr17453, ld-new -o tmpdir/tlsie4 -L/var/tmp/binutils-gdb/ld/testsuite/ld-x86-64 -melf32_x86_64 tmpdir/tlsie4.o accesses one byte before start of "contents".  Here, when roff==2:

		  /* IE->LE transition:
		     Originally it can be one of:
		     movq foo@gottpoff(%rip), %reg
		     addq foo@gottpoff(%rip), %reg
		     We change it into:
		     movq $foo, %reg
		     leaq foo(%reg), %reg
		     addq $foo, %reg.  */

		  unsigned int val, type, reg;

		  val = bfd_get_8 (input_bfd, contents + roff - 3);

This is obviously wrong.  What's more, "val" (really one of the rex prefixes) affects the output insns.  If the insn wasn't at the start of a section, it is quite possible for a previous insn to end with a byte that happens to look like a rex prefix.
Comment 1 H.J. Lu 2014-10-14 19:11:30 UTC
I couldn't find a good solution for this.  I am leaning toward to encode
instructions with gottpoff relocation with a dummy REX prefix (0x40)
if there is no REX prefix.
Comment 2 H.J. Lu 2014-10-14 23:43:02 UTC
Created attachment 7832 [details]
A patch

This is the patch I am testing.  But I may not have time
to check it in for the next couple weeks.  Please feel
free to commit it for me if it is OK.  Thanks.
Comment 3 Sourceware Commits 2014-11-07 20:26:07 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  cf61b7473a8ee3b43c4f8f2776075ec8d81d7495 (commit)
      from  9de00a4aa026297eae42bafd8ab413cfc1a53e3a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cf61b7473a8ee3b43c4f8f2776075ec8d81d7495

commit cf61b7473a8ee3b43c4f8f2776075ec8d81d7495
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Nov 7 12:22:53 2014 -0800

    X32: Add REX prefix to encode R_X86_64_GOTTPOFF
    
    Structions with R_X86_64_GOTTPOFF relocation must be encoded with REX
    prefix even if it isn't required by destination register.  Otherwise
    linker can't safely perform IE -> LE optimization.
    
    bfd/
    
    	PR ld/17482
    	* elf64-x86-64.c (elf_x86_64_relocate_section): Update comments
    	for IE->LE transition.
    
    gas/
    
    	PR ld/17482
    	* config/tc-i386.c (output_insn): Add a dummy REX_OPCODE prefix
    	for structions with R_X86_64_GOTTPOFF relocation for x32 if needed.
    
    gas/testsuite/
    
    	PR ld/17482
    	* gas/i386/ilp32/x32-tls.d: New file.
    	* gas/i386/ilp32/x32-tls.s: Likewise.
    
    ld/testsuite/
    
    	PR ld/17482
    	* ld-x86-64/tlsie4.dd: Updated.

-----------------------------------------------------------------------

Summary of changes:
 bfd/ChangeLog                          |    6 ++++++
 bfd/elf64-x86-64.c                     |   22 ++++++++++++++++------
 gas/ChangeLog                          |    6 ++++++
 gas/config/tc-i386.c                   |    9 +++++++++
 gas/testsuite/ChangeLog                |    6 ++++++
 gas/testsuite/gas/i386/ilp32/x32-tls.d |   13 +++++++++++++
 gas/testsuite/gas/i386/ilp32/x32-tls.s |   13 +++++++++++++
 ld/testsuite/ChangeLog                 |    5 +++++
 ld/testsuite/ld-x86-64/tlsie4.dd       |    4 ++--
 9 files changed, 76 insertions(+), 8 deletions(-)
 create mode 100644 gas/testsuite/gas/i386/ilp32/x32-tls.d
 create mode 100644 gas/testsuite/gas/i386/ilp32/x32-tls.s
Comment 4 Sourceware Commits 2014-11-07 20:32:28 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, binutils-2_25-branch has been updated
       via  cf115d606eea814d659588953cbaa5b0b16e234c (commit)
      from  35cd712bccbb56c7705eb9cd7372b725da6152b4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cf115d606eea814d659588953cbaa5b0b16e234c

commit cf115d606eea814d659588953cbaa5b0b16e234c
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Nov 7 12:22:53 2014 -0800

    X32: Add REX prefix to encode R_X86_64_GOTTPOFF
    
    Structions with R_X86_64_GOTTPOFF relocation must be encoded with REX
    prefix even if it isn't required by destination register.  Otherwise
    linker can't safely perform IE -> LE optimization.
    
    bfd/
    
    	PR ld/17482
    	* elf64-x86-64.c (elf_x86_64_relocate_section): Update comments
    	for IE->LE transition.
    
    gas/
    
    	PR ld/17482
    	* config/tc-i386.c (output_insn): Add a dummy REX_OPCODE prefix
    	for structions with R_X86_64_GOTTPOFF relocation for x32 if needed.
    
    gas/testsuite/
    
    	PR ld/17482
    	* gas/i386/ilp32/x32-tls.d: New file.
    	* gas/i386/ilp32/x32-tls.s: Likewise.
    
    ld/testsuite/
    
    	PR ld/17482
    	* ld-x86-64/tlsie4.dd: Updated.

-----------------------------------------------------------------------

Summary of changes:
 bfd/ChangeLog                          |    9 +++++++++
 bfd/elf64-x86-64.c                     |   22 ++++++++++++++++------
 gas/ChangeLog                          |    9 +++++++++
 gas/config/tc-i386.c                   |    9 +++++++++
 gas/testsuite/ChangeLog                |    9 +++++++++
 gas/testsuite/gas/i386/ilp32/x32-tls.d |   13 +++++++++++++
 gas/testsuite/gas/i386/ilp32/x32-tls.s |   13 +++++++++++++
 ld/testsuite/ChangeLog                 |    8 ++++++++
 ld/testsuite/ld-x86-64/tlsie4.dd       |    4 ++--
 9 files changed, 88 insertions(+), 8 deletions(-)
 create mode 100644 gas/testsuite/gas/i386/ilp32/x32-tls.d
 create mode 100644 gas/testsuite/gas/i386/ilp32/x32-tls.s
Comment 5 H.J. Lu 2014-11-07 20:36:07 UTC
Fixed for 2.25.
Comment 6 Sourceware Commits 2014-11-12 04:47:05 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  abd58633c1985c879a84249650172da639773730 (commit)
       via  6d19a37a8f3be44fb006c7854a12f9edcb74080d (commit)
      from  d50abe23863b5bbb40fab2b785f0df8917b1b7dd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=abd58633c1985c879a84249650172da639773730

commit abd58633c1985c879a84249650172da639773730
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Nov 12 15:00:01 2014 +1030

    Fix z80-coff build breakage
    
    	* config/tc-z80.c (parse_exp_not_indexed, parse_exp): Warning fixes.

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6d19a37a8f3be44fb006c7854a12f9edcb74080d

commit 6d19a37a8f3be44fb006c7854a12f9edcb74080d
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Nov 12 14:54:23 2014 +1030

    Fix x86 non-ELF build breakage
    
    	PR ld/17482
    	* config/tc-i386.c (output_insn): Don't test x86_elf_abi when
    	not ELF.

-----------------------------------------------------------------------

Summary of changes:
 gas/ChangeLog        |   10 ++++++++++
 gas/config/tc-i386.c |    2 ++
 gas/config/tc-z80.c  |    4 ++++
 3 files changed, 16 insertions(+), 0 deletions(-)
Comment 7 Sourceware Commits 2014-11-12 04:51:10 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, binutils-2_25-branch has been updated
       via  10153947d78f6ead12735a2d9198cf46c19449dd (commit)
      from  b02026e71aeb7fab4fb3f0466dca83c73515132d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=10153947d78f6ead12735a2d9198cf46c19449dd

commit 10153947d78f6ead12735a2d9198cf46c19449dd
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Nov 12 14:54:23 2014 +1030

    Fix x86 non-ELF build breakage
    
    	PR ld/17482
    	* config/tc-i386.c (output_insn): Don't test x86_elf_abi when
    	not ELF.

-----------------------------------------------------------------------

Summary of changes:
 gas/ChangeLog        |    6 ++++++
 gas/config/tc-i386.c |    2 ++
 2 files changed, 8 insertions(+), 0 deletions(-)