Bug 13880 - -Bsymbolic fails to handle protected function pointer
Summary: -Bsymbolic fails to handle protected function pointer
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-20 17:38 UTC by H.J. Lu
Modified: 2012-08-08 16:30 UTC (History)
0 users

See Also:
Host:
Target:
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 2012-03-20 17:38:43 UTC
[hjl@gnu-6 protected-1]$ cat shared.c 
typedef int (*protected_t) (void);

int protected (void) __attribute__ ((visibility ("protected")));

int
protected ()
{
  return 20;
}

protected_t
protected_p ()
{
  return protected;
}
[hjl@gnu-6 protected-1]$ cat main.c 
#include <stdio.h>

typedef int (*protected_t) (void);

int protected (void);
extern protected_t protected_p (void);

void
foo (protected_t f)
{
  printf ("%p\n", f);
  printf ("%d\n", f ());
}

int main()
{
  protected_t f = protected_p ();
  foo (f);
  foo (protected);

  return 0;
}
[hjl@gnu-6 protected-1]$ make
gcc -B./  -O -c main.c
gcc -B./  -O -fPIC -mcmodel=large -c shared.c
./ld -shared -Bsymbolic -o libfoo.so shared.o
./ld: shared.o: relocation R_X86_64_GOTOFF64 against protected function `protected' can not be used when making a shared object
./ld: final link failed: Bad value
make: *** [libfoo.so] Error 1
[hjl@gnu-6 protected-1]$
Comment 1 Sourceware Commits 2012-03-20 18:16:50 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2012-03-20 18:16:39

Modified files:
	bfd            : ChangeLog elf32-i386.c elf64-x86-64.c 
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-i386: i386.exp 
	ld/testsuite/ld-x86-64: x86-64.exp 
Added files:
	ld/testsuite/ld-i386: protected4.d protected4.s protected5.d 
	                      protected5.s 
	ld/testsuite/ld-x86-64: protected4.d protected4.s protected5.d 
	                        protected5.s 

Log message:
	Handle relocation against protected function for -Bsymbolic
	
	bfd/
	
	2012-03-20  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/13880
	* elf32-i386.c (elf_i386_relocate_section): Don't issue an error
	for R_386_GOTOFF relocation against protected function if
	SYMBOLIC_BIND is true.
	
	* elf64-x86-64.c (elf_x86_64_relocate_section): Don't issue an
	error for R_X86_64_GOTOFF64 relocation against protected function
	when building executable or SYMBOLIC_BIND is true.
	
	ld/testsuite/
	
	2012-03-20  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/13880
	* ld-i386/i386.exp: Run protected4 and protected5.
	* ld-x86-64/x86-64.exp: Likewise.
	
	* ld-i386/protected4.d: New.
	* ld-i386/protected4.s: Likewise.
	* ld-i386/protected5.d: Likewise.
	* ld-i386/protected5.s: Likewise.
	* ld-x86-64/protected4.d: Likewise.
	* ld-x86-64/protected4.s: Likewise.
	* ld-x86-64/protected5.d: Likewise.
	* ld-x86-64/protected5.s: Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5632&r2=1.5633
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-i386.c.diff?cvsroot=src&r1=1.268&r2=1.269
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-x86-64.c.diff?cvsroot=src&r1=1.253&r2=1.254
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1505&r2=1.1506
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-i386/protected4.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-i386/protected4.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-i386/protected5.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-i386/protected5.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-i386/i386.exp.diff?cvsroot=src&r1=1.41&r2=1.42
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/protected4.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/protected4.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/protected5.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/protected5.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/x86-64.exp.diff?cvsroot=src&r1=1.39&r2=1.40
Comment 2 H.J. Lu 2012-08-08 16:30:50 UTC
Fixed.