https://sourceware.org/bugzilla/show_bug.cgi?id=18841

            Bug ID: 18841
           Summary: Data relocations with IFUNC symbols can lead to
                    segfault
           Product: binutils
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: amonakov at gmail dot com
                CC: hjl.tools at gmail dot com
  Target Milestone: ---

In the following testcase, libfoo.so is compiled so that it has GLOB_DAT
relocations against 'foo' and 'zoo', in that order (with BFD linker), which
leads to failure at dynamic linking time.  Renaming 'zoo' to 'z' with the
preprocessor avoids the segfault (the relocations happen to be emitted in the
opposite order).  Gold linker appears to always sort the relocations
"properly".

cat <<EOF >foo.c
void foo() __attribute__((ifunc("resolve_foo")));

static void foo_impl() {}

void test()
{
  void (*pg)(void) = foo;
  pg();
}

static void* resolve_foo()
{
  extern void zoo(void);

  void (*pz)(void) = zoo;
  pz();
  return foo_impl;
}
EOF

cat <<EOF >main.c
void zoo(){}

void test(void);

int main()
{
  test();
  return 0;
}
EOF

cat <<'EOF' >Makefile
test: main; ./main

main: libfoo.so

lib%.so: %.c; $(CC) $(CFLAGS) -fPIC -shared -o $@ $<

main: LDLIBS=-L. -lfoo

main: LDFLAGS=-Wl,-rpath,.
EOF

$ make -B CFLAGS=-fuse-ld=gold
cc -fuse-ld=gold -fPIC -shared -o libfoo.so foo.c
cc -fuse-ld=gold  -Wl,-rpath,.  main.c libfoo.so  -L. -lfoo -o main
./main
$ make -B CFLAGS=-fuse-ld=bfd
cc -fuse-ld=bfd -fPIC -shared -o libfoo.so foo.c
cc -fuse-ld=bfd  -Wl,-rpath,.  main.c libfoo.so  -L. -lfoo -o main
./main
Makefile:2: recipe for target 'test' failed
make: *** [test] Segmentation fault
$ make -B CFLAGS=-fuse-ld=bfd\ -Dzoo=z
cc -fuse-ld=bfd -Dzoo=z -fPIC -shared -o libfoo.so foo.c
cc -fuse-ld=bfd -Dzoo=z  -Wl,-rpath,.  main.c libfoo.so  -L. -lfoo -o main
./main
$

-- 
You are receiving this mail because:
You are on the CC list for the bug.

_______________________________________________
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils

Reply via email to