cannot allocate memory in static TLS block

Thorsten Kukuk kukuk@suse.de
Fri Sep 5 06:02:00 GMT 2003


Hi,

compiling the appended test case on i686, gives me the following
error messages in some configurations:

# ./dlopen-tls 
dlopen() failed: './tls.so: cannot allocate memory in static TLS block'

It does not work with glibc compiled for i686 with TLS and
without NPTL (the fallback, if somebody uses an older kernel or
LD_ASSUME_KERNEL=2.4.1).

Is this a binutils/gcc problem or a bug in glibc? It seems to work
on other architectures with the same tool chain (gcc 3.3.1, 
binutils-2.14.90.0.5).

 Thanks,
  Thorsten

-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk@suse.de
SuSE Linux AG        Deutschherrnstr. 15-19        D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B
-------------- next part --------------
all:
	gcc -g dlopen-tls.c -o dlopen-tls -Wall -ldl
	gcc -g -c tls.c -o tls.o -fPIC -ftls-model=local-exec
	gcc -g -o tls.so -shared tls.o

clean:
	rm -rf *.o *~ *.so
-------------- next part --------------

#include <stdio.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdlib.h>

int main()
{
    void *handle;
    int (*func)(void);

    int i;

    for (i = 0; i < 500; i++) {

        handle = dlopen("./tls.so", RTLD_NOW);

        if (!handle) {
            fprintf(stderr, "dlopen() failed: '%s'\n", dlerror());
            exit(1);
        }

        func = dlsym(handle, "getTLSVar");
        
        if (!func) {
            fprintf(stderr, "Failed to find symbol 'getTLSVar'\n");
            exit(1);
        }
        
        func();

        if (dlclose(handle) != 0) {
            fprintf(stderr, "dlopen() failed: '%s'\n", dlerror());
            exit(1);
        }
        
        printf("success %d\n", i);

    }
    
    return 0;
}
-------------- next part --------------
static __thread int foo;

int getTLSVar(void)
{
    return foo; 
} 
 


More information about the Libc-hacker mailing list