Bug 11791 - Garbage collection for STT_GNU_IFUNC symbols
Summary: Garbage collection for STT_GNU_IFUNC symbols
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks: 12371
  Show dependency treegraph
 
Reported: 2010-07-05 16:15 UTC by Stephen Clarke
Modified: 2011-01-06 15:56 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen Clarke 2010-07-05 16:15:26 UTC
$ cat test.s
        .section .text.foo,"ax",@progbits
        .type foo, @function
foo:
        .global foo
        movl ifunc@GOT(%ecx), %eax
        ret

        .section .text.bar,"ax",@progbits
        .type bar, @function
bar:
        .global bar
        ret

        .section .text.ifunc,"ax",@progbits
        .type ifunc, @gnu_indirect_function
ifunc:
        ret

$ as -o test.o test.s
$ ld -e bar --gc-sections test.o

If I use a recent version of binutils:
$ ld -v
GNU ld (GNU Binutils) 2.20.51.20100702

then for the ld command I get segv, i.e.
$ ld -e bar --gc-sections test.o
Segmentation fault

but if I hack out the cause of that, then I get an executable in
which garbage collection has removed all the original sections that
refer to the ifunc symbol, but there is still a plt entry, got entry
and  dynamic relocation for the ifunc symbol.

$ objdump -h -d a.out

a.out:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .rel.plt      00000008  08048074  08048074  00000074  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .plt          00000010  0804807c  0804807c  0000007c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .text         00000001  0804808c  0804808c  0000008c  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  3 .got.plt      00000010  08049090  08049090  00000090  2**2
                  CONTENTS, ALLOC, LOAD, DATA

Disassembly of section .plt:

0804807c <.plt>:
 804807c:       ff 25 9c 90 04 08       jmp    *0x804909c
 8048082:       68 00 00 00 00          push   $0x0
 8048087:       e9 00 00 00 00          jmp    804808c <bar>

Disassembly of section .text:

0804808c <bar>:
 804808c:       c3                      ret
Comment 1 Sourceware Commits 2010-07-13 16:59:40 UTC
Subject: Bug 11791

CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2010-07-13 16:59:14

Modified files:
	bfd            : ChangeLog elf-ifunc.c elf32-i386.c 
	                 elf64-x86-64.c 
	ld/testsuite   : ChangeLog 
Added files:
	ld/testsuite/ld-ifunc: ifunc-10-i386.d ifunc-10-i386.s 
	                       ifunc-10-x86-64.d ifunc-10-x86-64.s 
	                       ifunc-11-i386.d ifunc-11-i386.s 
	                       ifunc-11-x86-64.d ifunc-11-x86-64.s 

Log message:
	Support garbage collection against STT_GNU_IFUNC symbols.
	
	bfd/
	
	2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/11791
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Support
	garbage collection against STT_GNU_IFUNC symbols.
	
	* elf32-i386.c (elf_i386_get_local_sym_hash): Don't set
	elf.plt.offset/elf.got.offset to -1.
	(elf_i386_tls_transition): Skip TLS transition for functions.
	(elf_i386_gc_sweep_hook): Support STT_GNU_IFUNC symbols.
	
	* elf64-x86-64.c (elf64_x86_64_get_local_sym_hash): Don't set
	elf.plt.offset/elf.got.offset to -1.
	(elf64_x86_64_tls_transition): Skip TLS transition for functions.
	(elf64_x86_64_gc_sweep_hook): Support STT_GNU_IFUNC symbols.
	
	ld/testsuite/
	
	2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/11791
	* ld-ifunc/ifunc-10-i386.d: New.
	* ld-ifunc/ifunc-10-i386.s: Likewise.
	* ld-ifunc/ifunc-10-x86-64.d: Likewise.
	* ld-ifunc/ifunc-10-x86-64.s: Likewise.
	* ld-ifunc/ifunc-11-i386.d: Likewise.
	* ld-ifunc/ifunc-11-i386.s: Likewise.
	* ld-ifunc/ifunc-11-x86-64.d: Likewise.
	* ld-ifunc/ifunc-11-x86-64.s: Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5071&r2=1.5072
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf-ifunc.c.diff?cvsroot=src&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-i386.c.diff?cvsroot=src&r1=1.234&r2=1.235
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-x86-64.c.diff?cvsroot=src&r1=1.195&r2=1.196
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1259&r2=1.1260
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-10-i386.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-10-i386.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-10-x86-64.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-10-x86-64.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-11-i386.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-11-i386.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-11-x86-64.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-11-x86-64.s.diff?cvsroot=src&r1=NONE&r2=1.1

Comment 2 H.J. Lu 2010-07-13 17:32:03 UTC
Fixed.