bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gas/660] New: Segmentation fault with big shared libraries


From: klaas dot de dot waal at philips dot com
Subject: [Bug gas/660] New: Segmentation fault with big shared libraries
Date: 14 Jan 2005 13:15:16 -0000

Context:
cross-compiler built with crosstools-0.38-rc37
gcc-3.4.2 and glibc-2.3.2 with binutils-2.15
Problem:
Application running on the mipsel gives "Segmentation fault" when calling a 
function in a big shared library. This happens for instance with the Qt-
Embedded example applications when the Qt code is built into a shared library.
I can reproduce the problem with a small example application. The code for this 
application is added at the end of this description.
The test result is:
- when you call a function in a shared library which has less than about 32000 
functions it works OK.
- when you call a function in a shared library with more than 32k functions, 
for example 40k functions then you get the "Segmentation fault".
BUT
If the toolchain is built with binutils-2.14 this problem does NOT happen; 
calling a function in a shared library with 40k functions then is OK (toolchain 
built with same gcc and same glibc version, the only difference is the binutils 
version).
AND
If the toolchain is built with the binutils of today (binutils-050114) I also 
get the "Segmentation fault".

I do not know if this is a problem in gas or in ld.

Maybe useful observation:
The example applications creates a shared library "libhello.so".
The result of "readelf -a libhello.so" on the libhello.so created with the 
binutils-1.14 toolchain is that the "Flags" has "pic" attribute set.
The result of "readelf -a libhello.so" on the libhello.so created with the 
binutils-1.15 toolchain is that the "Flags" has both the "pic" and the "cpic" 
attribute set.

The example application consists of Makefile, gen_hello.c and main.c
Type "make NUM=1000" creates a shared library with 1000 functions; this always 
works OK.
Type "make NUM=40000" creates a shared library with 40000 functions; this goes 
OK with the binutils-2.14 toolchain but fails with the binutils-2.15 toolchain.
Type "make NUM=32767" creates a shared library with 32767 functions; only with 
this number of functions in the shared library you get the error message 
"./a.out: relocation error: libhello.so: undefined symbol:"
With one function more or one function less in the shared library you get 
the "Segmentation fault".


--- Makefile---

CC_BUILD=gcc
CC_CROSS=mipsel-linux-gcc

NUM=40000

a.out:  main.o libhello.so
        $(CC_CROSS) -o $@ $< -Wl,-rpath,./ -L. -lhello

main.o: main.c
        $(CC_CROSS) -c $<

libhello.so:    hello.o
        $(CC_CROSS) -shared -Wl,-soname,libhello.so -o $@ $<

hello.o:        hello.c
        $(CC_CROSS) -fPIC -Wall -O2 -c hello.c

hello.c:        gen_hello
        ./$< $(NUM) > $@

gen_hello:      gen_hello.c Makefile
        $(CC_BUILD) -o $@ $<

clean::
        \rm -f hello.c a.out libhello.so main.o hello.o gen_hello


--- gen-hello.c ---

// Generate "hello.c" with a large number of functions
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv)
{
        printf("#include <stdio.h>\n");
        printf("\n");
        int n = argc > 1 ? atoi(argv[1]) : 10;
        int i;
        for (i=0; i<n; i++) {
                printf("void hello_%d() {\n", i);
                printf("\tprintf(\"hello_%d\\n\");\n", i);
                printf("}\n");
        }
        return 0;
}
        
--- main.c ---

// main.c
#include <stdio.h>

int hello_0();
int hello_999();

int main(void) {
        printf("Call functions in big shared library\n");
        printf("Calling hello_0...");
        hello_0();
        printf("Calling hello_999...");
        hello_999();
        return 0;
}

-- 
           Summary: Segmentation fault with big shared libraries
           Product: binutils
           Version: 2.15
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gas
        AssignedTo: unassigned at sources dot redhat dot com
        ReportedBy: klaas dot de dot waal at philips dot com
                CC: bug-binutils at gnu dot org
 GCC build triplet: gcc-3.4.2-glibc-2.3.2 with binutils-2.15
  GCC host triplet: FC3 on P4
GCC target triplet: mipsel-linux kernel 2.4.18


http://sources.redhat.com/bugzilla/show_bug.cgi?id=660

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]