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

Bug#691371: Broken COPY relocation with UNIQUE symbols (upstream #12510)



Package: libc6
Version: 2.13-35

I just rediscovered http://sourceware.org/bugzilla/show_bug.cgi?id=12510 in my application. Fixed by http://sourceware.org/git/?p=glibc.git;a=commit;h=028478fa40d85a73b19638dbe3f83b1acebf370c

Attached is the test-case I came up with before I found the commit that fixes it, and then the upstream bug.

This is a regression in wheezy vs squeeze; gcc in squeeze didn't generate UNIQUE symbols (at least for this case), AND the old dynamic linker seems to not have this bug.

The actual code part of that upstream patch applies cleanly to wheezy's libc and fixes the problem. ISTM that it'd be a good idea to backport, given that wheezy isn't going to upgrade to a new upstream release.

==== test.h ====
template<typename X>
class Foo {
public:
    static const char foo[];
};

==== test1.cpp ====
#include "test.h"

// Creates a UNIQUE symbol (and thus hits dynamic linker bug), used to
// create a WEAK symbol instead.
template<typename X>
const char Foo<X>::foo[] = "string";
template class Foo<int>;

const char * getone() {
    // Creates a R_X86_64_GLOB_DAT relocation
    return Foo<int>::foo;
}

==== test2.cpp ====
#include "test.h"
#include <stdio.h>
#include <string.h>

int main() {
    // Reference creates a R_X86_64_COPY relocation
    if (strcmp(Foo<int>::foo, "string")) {
	printf("'%s'\n", Foo<int>::foo);
        return 1;
    }
    return 0;
}


==== test.sh ====
g++ -fPIC -shared -o test.so test1.cpp
g++ -o test test2.cpp ./test.so
./test


Reply to: