casseopea2 / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Build fails on MinGW if libpthread is present #95

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Install MinGW with pthreads
2. cd google-perftools-1.0
3. ./configure && make

What is the expected output? What do you see instead?
The error message is:
--
 g++ -DHAVE_CONFIG_H -I. -I. -I./src -I./src -DNO_TCMALLOC_SAMPLES -DNDEBUG 
-Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -g -O2 -MT 
libtcmalloc_
minimal_la-tcmalloc.lo -MD -MP -MF .deps/libtcmalloc_minimal_la-
tcmalloc.Tpo -c src/tcmalloc.cc  -DDLL_EXPORT -DPIC -o 
.libs/libtcmalloc_minimal_la-tcmalloc.o
In file included from src/tcmalloc.cc:105:
c:/mingw/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/pthread.h:5
71: error: conflicting declaration 'typedef struct ptw32_handle_t 
pthread_t'
./src/windows/port.h:91: error: 'pthread_t' has a previous declaration as 
`typedef DWORD pthread_t'
--

What version of the product are you using? On what operating system?
Perftools 1.0 on MinGW/MS Vista

Please provide any additional information below.
The attached patch fixes compiler errors if pthreads is installed on MinGW.

Original issue reported on code.google.com by ndur...@googlemail.com on 9 Jan 2009 at 11:24

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report, and for your suggested patch.

I'm not sure I always want to say that we should avoid pthreads on win32 
systems that
have pthreads emulation.  If the problem is just in mingw, perhaps the best 
solution
is to modify src/windows/mingw.h, to undefine HAVE_PTHREADS? (At the end of that
file.)  It seems like that would fix the problem you're seeing.  Do you mind 
giving
it a try and seeing if it works for you?

Original comment by csilv...@gmail.com on 10 Jan 2009 at 1:44

GoogleCodeExporter commented 9 years ago

Original comment by csilv...@gmail.com on 10 Jan 2009 at 1:44

GoogleCodeExporter commented 9 years ago
No, #undef'ining HAVE_PTHREAD in mingw.h is not enough since other parts of the 
code 
include config.h directly:
--
 g++ -DHAVE_CONFIG_H -I. -I. -I./src -I./src -Wall -Wwrite-strings -Woverloaded-
virtual -Wno-sign-compare -g -O2 -MT patch_functions.lo -MD -MP -MF .deps/patch_
functions.Tpo -c src/windows/patch_functions.cc  -DDLL_EXPORT -DPIC -o 
.libs/patch_functions.o
In file included from ./src/tcmalloc.cc:105,
                 from src/windows/patch_functions.cc:629:
c:/mingw/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/pthread.h:571: 
error: 
conflicting declaration 'typedef struct ptw32_handle_t pthread_t'
./src/windows/port.h:91: error: 'pthread_t' has a previous declaration as 
`typedef 
DWORD pthread_t'
c:/mingw/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/pthread.h:571: 
error: 
declaration of `typedef struct ptw32_handle_t pthread_t'
--

I think configure.ac would the right place to completely disable HAVE_PTHREAD 
on 
MinGW. 

Original comment by ndur...@googlemail.com on 10 Jan 2009 at 11:52

GoogleCodeExporter commented 9 years ago
Actually, config.h includes mingw.h.  In theory, config.h should be the first 
include
file for everything in sparsehash, and therefore mingw.h should be included 
first
before everything else.

I don't know why an #undef of HAVE_PTHREAD in mingw.h wouldn't work on your 
system.
Can you double-check that your config.h has the #include of mingw.h at the end 
of it,
and that your mingw.h appropriately #undef's HAVE_PTHREAD at the end of it?

Original comment by csilv...@gmail.com on 12 Jan 2009 at 10:24

GoogleCodeExporter commented 9 years ago
Here's another thing to try: apply the patch below to src/windows/port.h.  I 
can't
test this well, because my mingw doesn't have pthreads support in it.  (If you 
can
tell me how to add it, I'll try to test locally too.)

I think this change should fix things, but I admit it's not well tested.

Original comment by csilv...@gmail.com on 3 Feb 2009 at 1:45

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by csilv...@gmail.com on 6 Feb 2009 at 11:57

GoogleCodeExporter commented 9 years ago
This was added in perftools 1.1, just released.  I don't know how to test on a 
mingw
without pthreads, but it should fix the problem.  Feel free to reopen the bug 
if it
does not.

Original comment by csilv...@gmail.com on 11 Mar 2009 at 9:17

GoogleCodeExporter commented 9 years ago
This bug just cropped up for me on 1.5. The attached two patches resolve it for 
me (and 
the test suite passes).

Original comment by neunon on 24 May 2010 at 3:40

Attachments:

GoogleCodeExporter commented 9 years ago
Hmm, this is strange, since mingw works for me with perftoosl 1.5.  I'd like to 
understand this better.  What breakage are you seeing with HAVE_PTHREAD on 
mingw, for 
instance?  Or I guess a better question is, how come HAVE_PTHREAD is being 
#defined 
in your mingw system at all?  I didn't think mingw had pthreads support, and 
the 
configure script should have properly detected that, no?  Maybe you can attach 
your 
config.log file.

As for 
   #define _WIN32_WINNT 0x500
this makes sense to me (we already do it in the msvc config.h file).  I wonder 
why 
this worked before.  Shrug.  I'll fix that up for the next release.

Original comment by csilv...@gmail.com on 24 May 2010 at 7:06

GoogleCodeExporter commented 9 years ago
There is a pthreads API wrapper for Windows, which my, erm, "distribution" of 
MinGW seems to come with: 
http://sourceware.org/pthreads-win32/

Configure detects it, and then marks HAVE_PTHREAD. This unfortunately breaks:

Makefile:2509: warning: overriding commands for target 
`heap-checker_debug_unittest.sh.exe'
Makefile:2506: warning: ignoring old commands for target 
`heap-checker_debug_unittest.sh.exe'
Makefile:2524: warning: overriding commands for target 
`heap-profiler_debug_unittest.sh.exe'
Makefile:2521: warning: ignoring old commands for target 
`heap-profiler_debug_unittest.sh.exe'
Makefile:2551: warning: overriding commands for target 
`maybe_threads_unittest.sh.exe'
Makefile:2548: warning: ignoring old commands for target 
`maybe_threads_unittest.sh.exe'
Makefile:2611: warning: overriding commands for target 
`sampling_debug_test.sh.exe'
Makefile:2608: warning: ignoring old commands for target 
`sampling_debug_test.sh.exe'
if /bin/sh ./libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I. 
-I./src  -I./src -
DNO_TCMALLOC_SAMPLES  -DNO_TCMALLOC_SAMPLES -DNO_HEAP_CHECK  -DNDEBUG -Wall 
-Wwrite-
strings -Woverloaded-virtual -Wno-sign-compare   -fno-exceptions -g -O2 -MT 
libtcmalloc_minimal_internal_la-thread_cache.lo -MD -MP -MF 
".deps/libtcmalloc_minimal_internal_la-
thread_cache.Tpo" -c -o libtcmalloc_minimal_internal_la-thread_cache.lo `test 
-f 'src/thread_cache.cc' || echo 
'./'`src/thread_cache.cc; \
 then mv -f ".deps/libtcmalloc_minimal_internal_la-thread_cache.Tpo" ".deps/libtcmalloc_minimal_internal_la-
thread_cache.Plo"; else rm -f 
".deps/libtcmalloc_minimal_internal_la-thread_cache.Tpo"; exit 1; fi
 g++ -DHAVE_CONFIG_H -I. -I. -I./src -I./src -DNO_TCMALLOC_SAMPLES -DNO_TCMALLOC_SAMPLES -
DNO_HEAP_CHECK -DNDEBUG -Wall -Wwrite-strings -Woverloaded-virtual 
-Wno-sign-compare -fno-
exceptions -g -O2 -MT libtcmalloc_minimal_internal_la-thread_cache.lo -MD -MP 
-MF 
.deps/libtcmalloc_minimal_internal_la-thread_cache.Tpo -c src/thread_cache.cc 
 -DDLL_EXPORT -DPIC -o 
.libs/libtcmalloc_minimal_internal_la-thread_cache.o
In file included from src/thread_cache.h:38,
                 from src/thread_cache.cc:38:
c:\msysgit\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/pthread.h:307:
 error: redefinition of 'struct 
timespec'
./src/windows/port.h:297: error: previous definition of 'struct timespec'
In file included from src/thread_cache.cc:38:
src/thread_cache.h:262: warning: 'thread' attribute directive ignored
src/thread_cache.h:262: warning: 'tls_model' attribute ignored
src/thread_cache.h: In static member function 'static tcmalloc::ThreadCache* 
tcmalloc::ThreadCache::GetThreadHeap()':
src/thread_cache.h:378: error: 'perftools_pthread_getspecific' was not declared 
in this scope
src/thread_cache.cc: At global scope:
src/thread_cache.cc:64: warning: 'tls_model' attribute ignored
src/thread_cache.cc:64: warning: 'thread' attribute directive ignored
src/thread_cache.cc: In static member function 'static void 
tcmalloc::ThreadCache::InitTSD()':
src/thread_cache.cc:312: error: 'perftools_pthread_key_create' was not declared 
in this scope
src/thread_cache.cc:320: error: no match for 'operator==' in 
'h->tcmalloc::ThreadCache::tid_ == zero'
src/thread_cache.cc: In static member function 'static tcmalloc::ThreadCache* 
tcmalloc::ThreadCache::CreateCacheIfNecessary()':
src/thread_cache.cc:344: error: no match for 'operator==' in 
'h->tcmalloc::ThreadCache::tid_ == me'
src/thread_cache.cc:359: error: 'perftools_pthread_setspecific' was not 
declared in this scope
src/thread_cache.cc: In static member function 'static void 
tcmalloc::ThreadCache::BecomeIdle()':
src/thread_cache.cc:394: error: 'perftools_pthread_setspecific' was not 
declared in this scope
src/thread_cache.cc: In static member function 'static void 
tcmalloc::ThreadCache::PrintThreads(TCMalloc_Printer*)':
src/thread_cache.cc:484: warning: format '%u' expects type 'unsigned int', but 
argument 4 has type 'ssize_t'
make: *** [libtcmalloc_minimal_internal_la-thread_cache.lo] Error 1

By the way, I think the Makefile warnings that show up first in the log above 
are harmless, but irritating. 
Perhaps those should be fixed too at some point.

Original comment by neunon on 24 May 2010 at 7:13

GoogleCodeExporter commented 9 years ago
Also, I don't think there's any MinGW out there that has a pthreads 
implementation that won't break like this. So 
this isn't just a "please hack your code to work around my system's crap" kind 
of patch.

Original comment by neunon on 24 May 2010 at 7:15

GoogleCodeExporter commented 9 years ago
} By the way, I think the Makefile warnings that show up first in the log above 
are
} harmless, but irritating. 

Yes, I agree.  They're part of a bigger hack to get autoconf to treat 
shell-script 
tests like executable tests (ie continue executing on failure, rather than 
aborting 
'make check').  One day I may figure out a more principled way to accomplish 
this 
same goal.

} Also, I don't think there's any MinGW out there that has a pthreads 
implementation
} that won't break like this.

Yes, I agree, it's better to have mingw use native windows spinlocks rather 
than 
pthreads.  I'll fix this up for the next release.

Original comment by csilv...@gmail.com on 24 May 2010 at 7:52

GoogleCodeExporter commented 9 years ago
This should be fixed in perftools 1.6, just released.

Original comment by csilv...@gmail.com on 5 Aug 2010 at 8:44