patchGNU Autoconf Archive - Patches: patch #7666, ax_pthread macro fails for C++ on...

 
 

patch #7666: ax_pthread macro fails for C++ on Solaris

Submitted by:  None
Submitted on:  Thu 17 Nov 2011 12:57:22 AM UTC  
 
Priority: 5 - NormalStatus: Done
Assigned to: Peter Simons <simons>Originator Email: -unavailable-
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Mon 05 Dec 2011 11:50:18 PM UTC, comment #9:

Solaris is SunOS 5, so no, it's not a SunOS 4 thing, and I doubt threading was the same going back that far (and I think we can safely consider that going back farther than necessary).

I have not personally had any problems putting it only in PTHREAD_CFLAGS, but I may have thought libtool included CFLAGS in that link step.

-- Scott

Anonymous
Fri 02 Dec 2011 08:17:07 PM UTC, comment #8:

My concern is the redundancy of specifying -D_REENTRANT with cc+"-mt" or gcc+"-pthreads", as well as cc+"-lpthread", and the lack of "-mt" in PTHREAD_LIBS.

There is this note in the macro:

# On Solaris (at least, for some versions), libc contains stubbed
# (non-functional) versions of the pthreads routines, so link-based
# tests will erroneously succeed. [...] So,
# we'll just look for -pthreads and -lpthread first:

Does anyone here know what versions of Solaris this applies to? Is this a SunOS4 thing?

Daniel Richard G. <iskunk>
Fri 02 Dec 2011 03:32:37 PM UTC, comment #7:

I've used the patch for years in my software packages without any trouble, but I would say the only possible improvement is detecting that it's "that" compiler on Solaris. I don't know what the convention is for that or if you have one. Maybe just checking for "CC" is enough. I use the "if gcc" check because I haven't encountered anything there but gcc and Sun's.

-- Scott Cantor

Anonymous
Fri 02 Dec 2011 03:15:44 PM UTC, comment #6:

I'm wondering about the state of this patch, because I'd like to release a new version of the archive soon. Is that change to AX_PTHREAD considered all right the way it is, or does anyone object?

Peter Simons <simons>
Project AdministratorIn charge of this item.
Tue 22 Nov 2011 01:08:46 AM UTC, comment #5:

Sounds about right. From the (Solaris 8) CC(1) man page...

-mt Compile and link for multithreaded code.

This option:

o Passes -D_REENTRANT to the preprocessor

o Passes -lthread in the correct order to ld

o Ensures that, for standard mode (the default
mode), libthread is linked before libCrun

o Ensures that, for compability mode (-compat),
libthread is linked before libC

The -mt option is required if the application or
libraries are multithreaded.

Warnings:

You must use this option, rather than -lthread.

If you are using POSIX threads, you must link with
the options -mt -lpthread. The -mt option is
necessary because libC (compatibility mode) and
libCrun (standard mode) need libthread for a mul-
tithreaded application.

Daniel Richard G. <iskunk>
Tue 22 Nov 2011 12:22:48 AM UTC, comment #4:

Usually omitting -mt doesn't matter that much for C applications, but it triggers different startup code for C++ applications that ensures the right ordering of static constructors and so forth in conjunction with the threading routines.

If you have a preferred test for which compiler is involved, that's fine, as long as -mt is added for Solaris Studio.

Anonymous
Mon 21 Nov 2011 11:33:57 PM UTC, comment #3:

> What does PTHREAD_CFLAGS and PTHREAD_LIBS return without this patch?


On both a 64-bit Solaris 8 system, and a 64-bit/AMD64 Solaris 10 system here:

PTHREAD_CC = cc
PTHREAD_CFLAGS = -D_REENTRANT
PTHREAD_LIBS = -lpthread

But then, things aren't as simple as they seem. From the cc(1) man page:

-mt Passes D_REENTRANT to preprocessor. Appends -lthread.
If you are doing your own multithread coding, you must
use this option in the compile and link steps. To
obtain faster execution, this option requires a mul-
tiprocessor system. On a single-processor system, the
resulting executable usually runs more slowly with this
option.

So potentially, for the Solaris compiler, -D_REENTRANT is redundant and -mt is also needed in PTHREAD_LIBS...

Daniel Richard G. <iskunk>
Mon 21 Nov 2011 10:52:23 PM UTC, comment #2:

Pushed to the Git repository in commit 6c8eddf2606e768cea66e49fc746330ba88de18e. Thank you very much!

Peter Simons <simons>
Project AdministratorIn charge of this item.
Mon 21 Nov 2011 06:35:21 PM UTC, comment #1:

Thank you very much for pointing out that problem. If you have the chance, could you please attach a proper diff/patch file to this bug report to fix the problem?

Peter Simons <simons>
Project AdministratorIn charge of this item.
Thu 17 Nov 2011 12:57:22 AM UTC, original submission:

The section that adds "extra" flags for Solaris is missing the addition of the -mt option for Oracle/Sun CC. It's used at the top in the detection code, but never gets added. _RENTRANT alone is not sufficient when using that compiler with C++, you get improper safety for object startup and shutdown.

I use this in place of the existing code for special flags:

solaris)
if test "$GCC" = "yes"; then
flag="-D_REENTRANT"
else
flag="-mt -D_REENTRANT"
fi

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #24417:  axthreadpatch.txt added by None (715B - text/plain - My working patch is attached.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by iskunk (Posted a comment)
  • -unavailable- added by simons (Posted a comment)
  • -unavailable- added by simons
  • -unavailable- added by simons
  • -unavailable- added by None (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 21 Dec 2011 10:59:10 AM UTCsimonsStatusReady For Test=>Done
      Open/ClosedOpen=>Closed
    Mon 21 Nov 2011 10:52:23 PM UTCsimonsStatusNeed Info=>Ready For Test
    Mon 21 Nov 2011 07:47:57 PM UTCNoneAttached File-=>Added axthreadpatch.txt, #24417
    Mon 21 Nov 2011 06:35:21 PM UTCsimonsStatusNone=>Need Info
      Assigned toNone=>simons
      Carbon-Copy-=>Added steven g. johnson
      Carbon-Copy-=>Added daniel richard g.

    Back to the top


    Powered by Savane 3.1-cleanup1