Bug 21038 - Incorrect unwind info for BND PLT
Summary: Incorrect unwind info for BND PLT
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: 2.29
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-11 16:45 UTC by H.J. Lu
Modified: 2017-01-13 16:55 UTC (History)
0 users

See Also:
Host:
Target: x86-64
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2017-01-11 16:45:46 UTC
[hjl@gnu-6 mpx-6]$ cat y.S 
	.text
	.globl foo
	.type foo, @function
foo:
	.cfi_startproc
	call	func@plt
	.cfi_endproc
[hjl@gnu-6 mpx-6]$ make LD=ld
gcc -B./    -c -o y.o y.S
ld -z bndplt -shared -o y.so y.o
./objdump -Wf -dw y.so

y.so:     file format elf64-x86-64

Contents of the .eh_frame section:

00000000 0000000000000014 00000000 CIE
  Version:               1
  Augmentation:          "zR"
  Code alignment factor: 1
  Data alignment factor: -8
  Return address column: 16
  Augmentation data:     1b

  DW_CFA_def_cfa: r7 (rsp) ofs 8
  DW_CFA_offset: r16 (rip) at cfa-8
  DW_CFA_nop
  DW_CFA_nop

00000018 0000000000000014 0000001c FDE cie=00000000 pc=0000000000000248..000000000000024d
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop

00000030 0000000000000024 00000034 FDE cie=00000000 pc=0000000000000220..0000000000000240
  DW_CFA_def_cfa_offset: 16
  DW_CFA_advance_loc: 6 to 0000000000000226
  DW_CFA_def_cfa_offset: 24
  DW_CFA_advance_loc: 10 to 0000000000000230
  DW_CFA_def_cfa_expression (DW_OP_breg7 (rsp): 8; DW_OP_breg16 (rip): 0; DW_OP_lit15; DW_OP_and; DW_OP_lit11; DW_OP_ge; DW_OP_lit3; DW_OP_shl; DW_OP_plus)
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop


Disassembly of section .plt:

0000000000000220 <.plt>:
 220:	ff 35 e2 0d 20 00    	pushq  0x200de2(%rip)        # 201008 <_GLOBAL_OFFSET_TABLE_+0x8>
 226:	f2 ff 25 e3 0d 20 00 	bnd jmpq *0x200de3(%rip)        # 201010 <_GLOBAL_OFFSET_TABLE_+0x10>
 22d:	0f 1f 00             	nopl   (%rax)
 230:	68 00 00 00 00       	pushq  $0x0
 235:	f2 e9 e5 ff ff ff    	bnd jmpq 220 <.plt>
 23b:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)

Disassembly of section .plt.bnd:

0000000000000240 <func@plt>:
 240:	f2 ff 25 d1 0d 20 00 	bnd jmpq *0x200dd1(%rip)        # 201018 <func>
 247:	90                   	nop

Disassembly of section .text:

0000000000000248 <foo>:
 248:	e8 f3 ff ff ff       	callq  240 <func@plt>
[hjl@gnu-6 mpx-6]$ 

Since the BND PLT has

 230:	68 00 00 00 00       	pushq  $0x0
 235:	f2 e9 e5 ff ff ff    	bnd jmpq 220 <.plt>
 23b:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)

instead of

 230:	ff 25 e2 0d 20 00    	jmpq   *0x200de2(%rip)        # 201018 <func>
 236:	68 00 00 00 00       	pushq  $0x0
 23b:	e9 e0 ff ff ff       	jmpq   220 <.plt>

Its unwind info should be

  DW_CFA_def_cfa_expression (DW_OP_breg7 (rsp): 8; DW_OP_breg16 (rip): 0; DW_OP_lit15; DW_OP_and; DW_OP_lit5; DW_OP_ge; DW_OP_lit3; DW_OP_shl; DW_OP_plus)
Comment 1 cvs-commit@gcc.gnu.org 2017-01-11 17:18:18 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit 9e65917652e994b0864b344bfa47014155d93100
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jan 11 09:16:44 2017 -0800

    x86-64: Correct unwind info for the BND PLT
    
    Since the BND PLT has
    
     230:	68 00 00 00 00       	pushq  $0x0
     235:	f2 e9 e5 ff ff ff    	bnd jmpq 220 <.plt>
     23b:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)
    
    instead of
    
     230:	ff 25 e2 0d 20 00    	jmpq   *0x200de2(%rip)        # 201018
    <func>
     236:	68 00 00 00 00       	pushq  $0x0
     23b:	e9 e0 ff ff ff       	jmpq   220 <.plt>
    
    its unwind info should be
    
    DW_CFA_def_cfa_expression (DW_OP_breg7 (rsp): 8; DW_OP_breg16 (rip): 0;
    DW_OP_lit15; DW_OP_and; DW_OP_lit5; DW_OP_ge; DW_OP_lit3; DW_OP_shl;
    DW_OP_plus)
    
    bfd/
    
    	PR ld/21038
    	* elf64-x86-64.c (elf_x86_64_eh_frame_bnd_plt): New.
    	(elf_x86_64_bnd_arch_bed): Use elf_x86_64_eh_frame_bnd_plt and
    	elf_x86_64_eh_frame_plt_got.
    	(elf_x86_64_size_dynamic_sections): Get unwind info from
    	elf_x86_64_bnd_arch_bed for the BND PLT.
    
    ld/
    
    	PR ld/21038
    	* testsuite/ld-x86-64/pr21038a.d: New file.
    	* testsuite/ld-x86-64/pr21038a.s: Likewise.
    	* testsuite/ld-x86-64/pr21038b.d: Likewise.
    	* testsuite/ld-x86-64/pr21038b.s: Likewise.
    	* testsuite/ld-x86-64/x86-64.exp: Run pr21038a and pr21038b.
Comment 2 H.J. Lu 2017-01-11 17:18:45 UTC
Fixed.
Comment 3 cvs-commit@gcc.gnu.org 2017-01-12 18:34:41 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit 8361ed4d6b7049264153434e8dc15e6dc2200ebf
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Jan 12 10:30:56 2017 -0800

    x86-64: Also generate unwind info for .plt.bnd
    
    Also generate unwind info for the .plt.bnd section.  Sine it is the same
    as unwind info for the .plt.got section, we use unwind info for the
    .plt.got section to cover the the .plt.bnd section.
    
    bfd/
    
    	PR ld/21038
    	* elf64-x86-64.c (elf_x86_64_link_hash_table): Add
    	plt_bnd_eh_frame.
    	(elf_x86_64_check_relocs): Create .eh_frame section for the
    	.plt.bnd section.
    	(elf_x86_64_size_dynamic_sections): Allocate and initialize
    	.eh_frame section for the .plt.bnd section.
    	(elf_x86_64_finish_dynamic_sections): Adjust .eh_frame section
    	for the .plt.bnd section.
    
    ld/
    
    	PR ld/21038
    	* testsuite/ld-x86-64/pr21038b.d: Updated.
    	* testsuite/ld-x86-64/pr21038c.d: New file.
    	* testsuite/ld-x86-64/pr21038c.s: Likewise.
    	* testsuite/ld-x86-64/x86-64.exp: Run pr21038c.
Comment 4 cvs-commit@gcc.gnu.org 2017-01-13 16:55:02 UTC
The binutils-2_28-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit 7d5f076b451a51d31540350a69e96a02da1033ac
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jan 11 09:16:44 2017 -0800

    x86-64: Correct unwind info for the BND PLT and .plt.bnd
    
    Since the BND PLT has
    
     230:	68 00 00 00 00       	pushq  $0x0
     235:	f2 e9 e5 ff ff ff    	bnd jmpq 220 <.plt>
     23b:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)
    
    instead of
    
     230:	ff 25 e2 0d 20 00    	jmpq   *0x200de2(%rip)        # 201018
    <func>
     236:	68 00 00 00 00       	pushq  $0x0
     23b:	e9 e0 ff ff ff       	jmpq   220 <.plt>
    
    its unwind info should be
    
    DW_CFA_def_cfa_expression (DW_OP_breg7 (rsp): 8; DW_OP_breg16 (rip): 0;
    DW_OP_lit15; DW_OP_and; DW_OP_lit5; DW_OP_ge; DW_OP_lit3; DW_OP_shl;
    DW_OP_plus)
    
    Also generate unwind info for the .plt.bnd section.  Sine it is the same
    as unwind info for the .plt.got section, we use unwind info for the
    .plt.got section to cover the the .plt.bnd section.
    
    bfd/
    
    2017-01-13  H.J. Lu  <hongjiu.lu@intel.com>
    
    	Backport from master
    	2017-01-12  H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR ld/21038
    	* elf64-x86-64.c (elf_x86_64_link_hash_table): Add
    	plt_bnd_eh_frame.
    	(elf_x86_64_check_relocs): Create .eh_frame section for the
    	.plt.bnd section.
    	(elf_x86_64_size_dynamic_sections): Allocate and initialize
    	.eh_frame section for the .plt.bnd section.
    	(elf_x86_64_finish_dynamic_sections): Adjust .eh_frame section
    	for the .plt.bnd section.
    
    	2017-01-11  H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR ld/21038
    	* elf64-x86-64.c (elf_x86_64_eh_frame_bnd_plt): New.
    	(elf_x86_64_bnd_arch_bed): Use elf_x86_64_eh_frame_bnd_plt and
    	elf_x86_64_eh_frame_plt_got.
    	(elf_x86_64_size_dynamic_sections): Get unwind info from
    	elf_x86_64_bnd_arch_bed for the BND PLT.
    
    ld/
    
    2017-01-13  H.J. Lu  <hongjiu.lu@intel.com>
    
    	Backport from master
    	2017-01-12  H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR ld/21038
    	* testsuite/ld-x86-64/pr21038b.d: Updated.
    	* testsuite/ld-x86-64/pr21038c.d: New file.
    	* testsuite/ld-x86-64/pr21038c.s: Likewise.
    	* testsuite/ld-x86-64/x86-64.exp: Run pr21038c.
    
    	2017-01-11  H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR ld/21038
    	* testsuite/ld-x86-64/pr21038a.d: New file.
    	* testsuite/ld-x86-64/pr21038a.s: Likewise.
    	* testsuite/ld-x86-64/pr21038b.d: Likewise.
    	* testsuite/ld-x86-64/pr21038b.s: Likewise.
    	* testsuite/ld-x86-64/x86-64.exp: Run pr21038a and pr21038b.