[Mesa-dev] [Bug 33440] New: _gl_DispatchTSD in glapi_x86_64.S has incorrect relocation type

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Mon Jan 24 15:18:17 PST 2011


           Summary: _gl_DispatchTSD in glapi_x86_64.S has incorrect
                    relocation type
           Product: Mesa
           Version: git
          Platform: x86-64 (AMD64)
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: medium
         Component: Mesa core
        AssignedTo: mesa-dev at lists.freedesktop.org
        ReportedBy: dimitry at andric.com

Created an attachment (id=42416)
 --> (https://bugs.freedesktop.org/attachment.cgi?id=42416)
Change relocation type of _gl_DispatchTSD to GOTPCREL

While building Mesa on FreeBSD, with recent binutils (>2.17), libGL.so.1
will fail to link with a misleading error:

mklib: Making FreeBSD shared library:  libGL.so.1
/usr/bin/ld: ../../../src/mesa/x86-64/glapi_x86-64.o: relocation R_X86_64_PC32
against `_gl_DispatchTSD' can not be used when making a shared object;
recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

But of course, the glapi_x86-64.o file is already compiled with -fPIC,
the actual command line used is:

cc -c -I. -I../../../include -I../../../include/GL/internal -I../../../src/mesa
-I../../../src/mesa/glapi -I/usr/local/include -I/usr/local/include/drm
-I/usr/local/include -D_THREAD_SAFE -I/usr/local/include -I/usr/local/include
-O2 -pipe -fno-strict-aliasing -Wall -Wmissing-prototypes -std=c99 -ffast-math
-fno-strict-aliasing -fPIC -DUSE_X86_64_ASM -DHAVE_POSIX_MEMALIGN -DUSE_XCB
-UIN_DRI_DRIVER -DDEFAULT_DRIVER_DIR=\"/usr/local/lib/dri\"
../../../src/mesa/x86-64/glapi_x86-64.S -o

The problem in glapi_x86-64.S is that if PTHREADS is defined,
_gl_DispatchTSD is declared as .extern, but is then accessed directly
with _gl_DispatchTSD(%rip), which is only applicable to locally defined

#elif defined(PTHREADS)

        .extern _glapi_Dispatch
        .extern _gl_DispatchTSD            # If this is extern...
        .extern pthread_getspecific

        .p2align        4,,15
        movq    _gl_DispatchTSD(%rip), %rdi    # ...this is incorrect
        jmp     pthread_getspecific at PLT

Instead, this access to _gl_DispatchTSD needs to be qualified with
@GOTPCREL, to indicate the symbol is relative to the Global Offset
Table, e.g.:

        movq    _gl_DispatchTSD at GOTPCREL(%rip), %rdi

(This was also found out by José Fonseca in one of his side branches,
commit b09d1ef60dae3b3c44f1370fd2f726c7044bc17)

As an example, consider the following small piece of C code:

extern int foo;

int bar(void)
        return foo + 42;

If you compile this on x86-64 with "gcc -O2 -fPIC -S", so for use in a
shared library, it will result in (approximately);

.globl bar
        .type   bar, @function
        movq    foo at GOTPCREL(%rip), %rax
        movl    (%rax), %eax
        addl    $42, %eax

Again, since the glapi_x86-64.S file is generated from gl_x86-64_asm.py,
I changed both.

Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

More information about the mesa-dev mailing list