Discussion:
[Libpqxx-general] strange errors when using clang in C++-11
Marco Craveiro
2012-08-15 21:10:43 UTC
Permalink
Hi PQXX,

I've got all my code compiling with GCC 4.7 in C++-11, using a snapshot
from the 20th of May (obtained here http://pqxx.org/~jtv/tmp/pqxx/snapshot/).
I'm very happy with this as all my code runs perfectly. When I try to use
clang 3.1 with the same settings - e.g. using GCC's libstdc++ and exactly
the same configuration as GCC - all the code compiles just fine but I get a
lot of strange run-time errors due to segfaults. Valgrind reveals a lot of
errors like these:

==28530== Invalid read of size 4
==28530== at 0x80D912: __gnu_cxx::__exchange_and_add(int volatile*,
int) (atomicity.h:48)
==28530== by 0x80D866: __gnu_cxx::__exchange_and_add_dispatch(int*,
int) (atomicity.h:81)
==28530== by 0x818E69:
std::tr1::_Sp_counted_base<(__gnu_cxx::_Lock_policy)1>::_M_release()
(shared_ptr.h:145)
==28530== by 0x818DA1:
std::tr1::__shared_count<(__gnu_cxx::_Lock_policy)1>::~__shared_count()
(shared_ptr.h:348)
==28530== by 0x818D04:
std::tr1::__shared_count<(__gnu_cxx::_Lock_policy)1>::~__shared_count()
(shared_ptr.h:346)
==28530== by 0x818CCB:
std::tr1::__shared_ptr<pqxx::internal::result_data const,
(__gnu_cxx::_Lock_policy)1>::~__shared_ptr() (shared_ptr.h:548)
==28530== by 0x818C84:
std::tr1::shared_ptr<pqxx::internal::result_data const>::~shared_ptr()
(shared_ptr.h:992)
==28530== by 0x818C44:
std::tr1::shared_ptr<pqxx::internal::result_data const>::~shared_ptr()
(shared_ptr.h:992)
==28530== by 0x818C04:
pqxx::internal::PQAlloc<pqxx::internal::result_data const,
&(pqxx::internal::freemem_result_data(pqxx::internal::result_data
const*))>::~PQAlloc() (util.hxx:494)
==28530== by 0x818BC4: pqxx::result::~result() (result.hxx:81)
==28530==

Does this ring any bells? I've scanned the archives and bug tracker but
didn't spot anything obvious. If not I'll try to get a minimal reproduction.

Cheers

Marco
--
So young, and already so unknown -- Pauli

blog: http://mcraveiro.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/libpqxx-general/attachments/20120815/4b1ecd7b/attachment.html>
Jeroen Vermeulen
2012-08-20 10:11:05 UTC
Permalink
Post by Marco Craveiro
I've got all my code compiling with GCC 4.7 in C++-11, using a snapshot
from the 20th of May (obtained here
http://pqxx.org/~jtv/tmp/pqxx/snapshot/). I'm very happy with this as
all my code runs perfectly. When I try to use clang 3.1 with the same
settings - e.g. using GCC's libstdc++ and exactly the same configuration
as GCC - all the code compiles just fine but I get a lot of strange
run-time errors due to segfaults. Valgrind reveals a lot of errors like
Not sure it's the cause of your problems, but strange things happen when
you mix code that is compiled as C++11 with code that isn't. Some std
data structures change sizes in some compilers, or compiler versions,
depending on the option. You get no link errors, but invalid accesses
at runtime.


Jeroen
Marco Craveiro
2012-08-20 11:19:04 UTC
Permalink
Jeroen,

thanks for that. However, I am fairly convinced I'm compiling PQXX (and
indeed everything else) in C++11 - so much so that I don't see any problems
when running the entire stack with GCC. The problem is specific to
compiling my code with clang in C++11 and linking it against C++11 code
generated by GCC (these would be all libraries such as boost, PQXX, etc).
It works for all libraries except for PQXX where I get these strange errors.

I think the problem is some form of incompatibility between clang and GCC
when building C++11 that I seem to be hitting only with PQXX. One thing
that sprung to mind - probably a red herring - is that we seem to be using
std::tr1 code in pqxx in C++11 mode (at least for clang, as I can see it in
the error messages). Is this expected?

Cheers

Marco
Post by Marco Craveiro
I've got all my code compiling with GCC 4.7 in C++-11, using a snapshot
Post by Marco Craveiro
from the 20th of May (obtained here
http://pqxx.org/~jtv/tmp/pqxx/**snapshot/<http://pqxx.org/~jtv/tmp/pqxx/snapshot/>).
I'm very happy with this as
all my code runs perfectly. When I try to use clang 3.1 with the same
settings - e.g. using GCC's libstdc++ and exactly the same configuration
as GCC - all the code compiles just fine but I get a lot of strange
run-time errors due to segfaults. Valgrind reveals a lot of errors like
Not sure it's the cause of your problems, but strange things happen when
you mix code that is compiled as C++11 with code that isn't. Some std data
structures change sizes in some compilers, or compiler versions, depending
on the option. You get no link errors, but invalid accesses at runtime.
Jeroen
--
So young, and already so unknown -- Pauli

blog: http://mcraveiro.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/libpqxx-general/attachments/20120820/d3d3003a/attachment.html>
Jeroen Vermeulen
2012-08-21 00:46:23 UTC
Permalink
Post by Marco Craveiro
I think the problem is some form of incompatibility between clang and
GCC when building C++11 that I seem to be hitting only with PQXX. One
thing that sprung to mind - probably a red herring - is that we seem to
be using std::tr1 code in pqxx in C++11 mode (at least for clang, as I
can see it in the error messages). Is this expected?
That's expected, yes. I would still have a look at that change in size
of standard containers. It would affect cross-compiler linking
compatibility. Some libpqxx classes have containers as members which
seems to be somewhat unusual among C++ libraries.


Jeroen

Continue reading on narkive:
Loading...