This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Support STT_GNU_IFUNC in executables


On Tue, May 26, 2009 at 2:25 PM, Ulrich Drepper <drepper@redhat.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> H.J. Lu wrote:
>> We have STT_GNU_IFUNC symbol definitions in executables, which leads
>> to DT_TEXTREL. We need to turn on PROT_EXEC during relocation.
>
> What? ?No, this mustn't happen. ?Why should there be text relocations?
> Is this your R_*_IRELATIVE implementation? ?It should not need text
> relocations because it should use a GOT slot and an indirect jump.
>
> It's absolutely impossible to introduce anything that requires
> executable text.

Here is a test case:

[hjl@gnu-34 ifunc-2]$ cat foo.c
#include <stdio.h>

int global = 1;

static int
minus_one (int x)
{
  printf ("Hello minus_one: %d\n", x);
  return -1;
}

static int
zero (int x)
{
  printf ("Hello zero: %d\n", x);
  return 0;
}

void * foo_ifunc (void) __asm__ ("foo");
void * foo_ifunc (void) { return global ? minus_one : zero ; }
__asm__(".type foo, %gnu_indirect_function");
[hjl@gnu-34 ifunc-2]$ cat prog.c
extern int foo (int);

int
main (void)
{
  foo (-3);
  return 0;
}
[hjl@gnu-34 ifunc-2]$ make
cc -g   -c -o prog.o prog.c
cc -g   -c -o foo.o foo.c
cc -L. -nostdlib -nostartfiles -o dynamic \
	-Wl,-dynamic-linker=/export/build/gnu/glibc-sse/build-x86_64-linux/elf/ld-linux-x86-64.so.2
\
	-Wl,-z,combreloc \
	/export/build/gnu/glibc-sse/build-x86_64-linux/csu/crt1.o
/export/build/gnu/glibc-sse/build-x86_64-linux/csu/crti.o \
	`cc --print-file-name=crtbegin.o` \
	prog.o foo.o  -Wl,-rpath,. \
	-Wl,-rpath=/export/build/gnu/glibc-sse/build-x86_64-linux:/export/build/gnu/glibc-sse/build-x86_64-linux/math
\
	/export/build/gnu/glibc-sse/build-x86_64-linux/elf/ld-linux-x86-64.so.2 \
	/export/build/gnu/glibc-sse/build-x86_64-linux/libc.so.6
/export/build/gnu/glibc-sse/build-x86_64-linux/libc_nonshared.a \
	-lgcc -lgcc_eh `gcc --print-file-name=crtend.o` \
	/export/build/gnu/glibc-sse/build-x86_64-linux/csu/crtn.o
./dynamic
Hello minus_one: -3
[hjl@gnu-34 ifunc-2]$

Static linker can detect such case and issue an error.

-- 
H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]