tech-toolchain archive

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

Re: Mixing clang and gcc



Joerg Sonnenberger <joerg%bec.de@localhost> wrote:
>On Sat, Aug 31, 2019 at 12:23:19PM -0400, Greg Troxel wrote:
>> Kamil Rytarowski <n54%gmx.com@localhost> writes:
>> 
>> > On 31.08.2019 15:25, Robert Swindells wrote:
>> >> 
>> >> Is linking code compiled with pkgsrc clang against system libpthread
>> >> built by gcc supposed to work ?
>> >> 
>> >> I'm getting a core dump that seems to be caused by an incorrect value
>> >> returned by pthread_self().
>> >> 
>> >> This is on aarch64.
>> >
>> > They have to use a compatible ABI. If this is not the case, speak up.
>> 
>> My impression, worth not much except as a data point about expectations,
>> is the programs written in C should have a compatible ABI and mixing
>> compilers should be ok, but that C++ does not really have a defined ABI
>> and one needs to use the same compiler for all C++ portions and the
>> final link.
>
>C++ has had a well defined ABI for over a decade now. The main issue is
>that there are different implementations of the standard library and
>those are typically not ABI compatible.

What counts as using C++ ?

I'm finding it hard to work out how calling this function from C++ can
return a value of -99890304.

int
pthread_attr_init(pthread_attr_t *attr)
{

        attr->pta_magic = PT_ATTR_MAGIC;
        attr->pta_flags = 0;
        attr->pta_private = NULL;

        return 0;
}

The calling function was compiled by clang, the called one is in
libpthread.so built by gcc.

Using gdb, the first two members of the pthread_attr_t struct have been
correctly initialized, the third one not.

The calling method just does this:

  pthread_attr_t attr;

  int rslt = pthread_attr_init(&attr);

A thought just now is whether the attr struct is maybe mis-aligned on
the stack and a trap is really being signalled when writing to pta_private.


Home | Main Index | Thread Index | Old Index