[Xcb] Thread safety of XCB.

John Found johnfound at evrocom.net
Wed Oct 3 12:44:46 PDT 2012


On Wed, 3 Oct 2012 08:32:50 -0700
Josh Triplett <josh at joshtriplett.org> wrote:

> On Wed, Oct 03, 2012 at 01:08:42PM +0300, John Found wrote:
> > On Wed, 3 Oct 2012 00:18:51 -0700
> > Josh Triplett <josh at joshtriplett.org> wrote:
> > 
> > > On Wed, Oct 03, 2012 at 08:55:25AM +0300, John Found wrote:
> > > > I am using XLib as a shared library, so I am sure it does calls the proper 
> > > > pthread functions, not the stubs in the glibc.
> > > 
> > > Not true.  Neither Xlib nor XCB links to libpthread directly; they link
> > > to the weak symbols provided in glibc, overridden by libpthread if
> > > available, but they won't actually pull in libpthread themselves. 
> > 
> > Ah, this makes things more clear.
> > 
> > > Try linking your program with -pthread and attempting to reproduce the
> > > bug.
> > 
> > I am writing in assembly language (FASM). There is no link stage and such an option.
> 
> FASM has the option of producing an object you can then link with GCC.

Creating object files and then linking is not an option for this project.

> > What option -pthread actually do? Should I simply import some functions from libpthread.so or
> > I must call some of them? Some initialization function maybe? 
> > Or it means some flags in the interpreter segment set?
> 
> Anything that causes your final ELF executable to have a direct
> dependency ("NEEDED" in objdump -x output) on libpthread.so should
> suffice; I think on most platforms -pthread does nothing more than
> -lpthread, though on some platforms it does have some added semantics.
> 
> - Josh Triplett

There is no NEEDED dynamic sections in FASM generated ELF binaries.
Regardless of this absence, the version that uses libpthread for thread 
management still works fine with XLib and the version that uses sys_clone,
crashes miserably. 
So, the conclusion is that this NEEDED section is not the cause of the
problem.
Here is what "objdump -x FreshProgram" returns:

>************************************************************************
FreshProgram:     file format elf32-i386
FreshProgram
architecture: i386, flags 0x00000102:
EXEC_P, D_PAGED
start address 0x0804bbe8

Program Header:
    LOAD off    0x000000d4 vaddr 0x080480d4 paddr 0x080480d4 align 2**12
         filesz 0x00003b65 memsz 0x00003b65 flags rwx
  INTERP off    0x00003c39 vaddr 0x0804cc39 paddr 0x0804cc39 align 2**0
         filesz 0x00000013 memsz 0x00000013 flags r--
 DYNAMIC off    0x00003c4c vaddr 0x0804cc4c paddr 0x0804cc4c align 2**0
         filesz 0x00000068 memsz 0x00000068 flags r--
    LOAD off    0x00003cb4 vaddr 0x0804ccb4 paddr 0x0804ccb4 align 2**12
         filesz 0x00000b8d memsz 0x00000b8d flags rw-
    LOAD off    0x00004841 vaddr 0x0804e841 paddr 0x0804e841 align 2**12
         filesz 0x00001885 memsz 0x0000193b flags rw-

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
SYMBOL TABLE:
no symbols
>************************************************************************

-- 
John Found 
http://asm32.hopto.org


More information about the Xcb mailing list