public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Threadiing Problems on AIX 4.3.3 ML-11 with gcc 3.2.3 (g++)
@ 2003-08-07 12:47 Markus.Schaeffer
  0 siblings, 0 replies; 6+ messages in thread
From: Markus.Schaeffer @ 2003-08-07 12:47 UTC (permalink / raw)
  To: gcc-help

Hello folks,

> I assume you mean that you are using the native AIX linker, but
>invoking "g++" to perform the link, not invoking "ld" directly.
>Otherwise, using "-Wl," in the LDFLAGS could not possibly work.

Yes indeed.

> Why are you adding "-fexceptions"?  The GNU C++ Compiler defaults
> to exceptions on.  This is CXXFLAGS, not CFLAGS.

At the moment I'am not shure that threads are the trouble makers.

###
Because an ldd gives the following info:
$ ldd ./server
/usr/lib/librtl.a(shr.o)
/usr/lib/libdl.a(shr.o)
/pkg/dev01/tools/compiler/gcc/lib/libgcc_s_pthread.a(shr.o) -> Is this a
static lib? Are there problems with exception handling?
/pkg/dev01/tools/compiler/gcc/lib/libgcc_s.a(shr.o)         -> "" ""
Thers's another lib in gcc libgcc_eh.a eh -> exception handling/invoked by
-shared-libgcc
/pkg/dev01/tools/compiler/gcc/lib/libstdc++.a(libstdc++.so.5)
/usr/lib/libpthreads.a(shr.o)
/usr/lib/libpthreads_compat.a(shr.o)
/usr/lib/libcrypt.a(shr.o)
/usr/lib/libc.a(shr.o)
/usr/lib/libpthreads.a(shr_comm.o)
/usr/lib/libpthreads.a(shr_xpg5.o)
/tmp/MS/0.07/libbase/aix/xerces/libxerces-c1_6_0.a
./server
$

And ldd of my shared lib gives me the following:

$ ldd ./libserviceconnectorarchive.a
/pkg/dev01/tools/compiler/gcc/lib/libgcc_s_pthread.a(shr.o)
/pkg/dev01/tools/compiler/gcc/lib/libgcc_s.a(shr.o)
/pkg/dev01/tools/compiler/gcc/lib/libstdc++.a(libstdc++.so.5)
/usr/lib/libpthreads.a(shr.o)
/usr/lib/libpthreads_compat.a(shr.o)
/usr/lib/libcrypt.a(shr.o)
/usr/lib/libc.a(shr.o)
/usr/lib/libpthreads.a(shr_comm.o)
/usr/lib/libpthreads.a(shr_xpg5.o)
/tmp/MS/0.07/libbase/aix/xerces/libxerces-c1_6_0.a
./libserviceconnectorarchive.a
$

And at least my xerces build:
$ ldd ./libxerces-c1_6_0.a
/pkg/dev01/tools/compiler/gcc/lib/libgcc_s_pthread.a(shr.o)
/pkg/dev01/tools/compiler/gcc/lib/libgcc_s.a(shr.o)
/pkg/dev01/tools/compiler/gcc/lib/libstdc++.a(libstdc++.so.5)
/usr/lib/libpthreads.a(shr.o)
/usr/lib/libpthreads_compat.a(shr.o)
/usr/lib/libcrypt.a(shr.o)
/usr/lib/libc.a(shr.o)
/usr/lib/libpthreads.a(shr_comm.o)
/usr/lib/libpthreads.a(shr_xpg5.o)
./libxerces-c1_6_0.a
###


> I assume LDFLAGS is for the application and SHARED_LDFLAGS is for
> the shared library.

Yes indeed.

> Why does LDFLAGS contain "-Wl,-brtl", but SHARED_LDFLAGS does not
> contain "-Wl,-G"?  Does the application use some other shared library
with
> System-V semantics?  Not all shared libraries need to be linked with
> "-Wl,-G", but "-Wl,-brtl" serves no purpose unless the shared library was
> linked with "-Wl,-G".  If you are using "-Wl,-brtl" for the linker to
> notice shared libraries with the file suffix ".so", don't do that.  AIX
> shared libraries normally are archives (ar command) of shared objects.
> You can use the ".a" suffix directly on the shared object instead of
> creating an archive.  Using the ".so" suffix for non-System-V semantics
> shared objects just creates confusion.

Ok, I did my homework after you told me that twice. ( See my makefile below
!)

> Also, I am concerned that you need to add "-Wl,-bh:5" to your link
> line.  If you need to change the linker halt level from the default,
> something is wrong.

I get level 4 Warnings of duplicated symbols. (Check my makefile, it
deleted -> you are rigth this is not very clever)

> You have not mentioned what errors are produced by the AIX linker
> requiring raising the halt level and you have not mentioned what
"problem"
> you encounter if your server does many calls.

No linking problems. (Just warnings!)

> While AIX provides a thread-safe C library and GCC libstdc++-v3
> strives to be thread safe, libstdc++-v3 may not interact with AIX libc in
> a thread-safe manner.  libstdc++-v3 makes assumptions based on GNU libc
> that are not correct on all platforms.  For instance, there are known
> issues with libstdc++-v3 use of setlocale() in I/O functions.  Does your
> shared library perform threaded I/O?

Yes...!?

> User-written code interacting with libstdc++-v3 must follow the
> SGI thread-safety rule, which basically says that the direct use of any
> global library object (e.g. std::cout is global) or non-local object
> returned from the library shared amongst user threads, must be protected
> by a mutex or similar by the user.

It's a hard thing but I will check this. I got the job for 2 weeks and this
is a mess anyway.

### MAKEFILE ###
CXXFLAGS=   -c -g \
            -Wno-deprecated \
            -pthread

LDFLAGS=    -pthread \
            -Wl,-brtl \
            -Wl,-bnoquiet \
            ${XERCESC_LDFLAGS} \
            -ldl

SHARED_LDFLAGS=   -pthread -shared \
                  -Wl,-bE:symbols.exp \
                  -Wl,-binitfini:init:fini:1 \ I've changed that to "0" but
it does ot make any difference
                  -Wl,-G \
                  -Wl,-bnoquiet \
                  ${XERCESC_LDFLAGS} \
                  -ldl
####

Regards
Mattey

P.S.: Thanks for all the good and fast replys David. It's not working yet
but any advice was worth a lot to me.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Threadiing Problems on AIX 4.3.3 ML-11 with gcc 3.2.3 (g++)
  2003-08-06 13:28 Markus.Schaeffer
@ 2003-08-06 18:52 ` David Edelsohn
  0 siblings, 0 replies; 6+ messages in thread
From: David Edelsohn @ 2003-08-06 18:52 UTC (permalink / raw)
  To: Markus.Schaeffer; +Cc: gcc-help

>>>>> Mattey writes: 

> CXX:  gcc 3.2.3 (I'am using g++)
> LD:   /usr/ccs/bin/ld

	I assume you mean that you are using the native AIX linker, but
invoking "g++" to perform the link, not invoking "ld" directly.
Otherwise, using "-Wl," in the LDFLAGS could not possibly work.

> CXXFLAGS=   -c -g \
>             -Wno-deprecated \
>             -D_AIX \
>             -fpic \
>             -pthread \
>             -fexceptions

	Why are you adding "-fexceptions"?  The GNU C++ Compiler defaults
to exceptions on.  This is CXXFLAGS, not CFLAGS.

> LDFLAGS=    -pthread \
>             -Wl,-brtl \
>             -Wl,-bnoquiet \
>             -Wl,-bh:5 \
>             ${XERCESC_LDFLAGS}

> SHARED_LDFLAGS=   -pthread -shared \
>                   -Wl,-bE:symbols.exp \
>                   -Wl,-binitfini:init:fini:0 \
>                   -bM:SRE \
>                   -Wl,-bnoquiet \
>                   -Wl,-bh:5 \
>                   ${XERCESC_LDFLAGS}

	I assume LDFLAGS is for the application and SHARED_LDFLAGS is for
the shared library.

	Why does LDFLAGS contain "-Wl,-brtl", but SHARED_LDFLAGS does not
contain "-Wl,-G"?  Does the application use some other shared library with
System-V semantics?  Not all shared libraries need to be linked with
"-Wl,-G", but "-Wl,-brtl" serves no purpose unless the shared library was
linked with "-Wl,-G".  If you are using "-Wl,-brtl" for the linker to
notice shared libraries with the file suffix ".so", don't do that.  AIX
shared libraries normally are archives (ar command) of shared objects.
You can use the ".a" suffix directly on the shared object instead of
creating an archive.  Using the ".so" suffix for non-System-V semantics
shared objects just creates confusion.

	Also, I am concerned that you need to add "-Wl,-bh:5" to your link
line.  If you need to change the linker halt level from the default,
something is wrong.

	You have not mentioned what errors are produced by the AIX linker
requiring raising the halt level and you have not mentioned what "problem"
you encounter if your server does many calls.

	While AIX provides a thread-safe C library and GCC libstdc++-v3
strives to be thread safe, libstdc++-v3 may not interact with AIX libc in
a thread-safe manner.  libstdc++-v3 makes assumptions based on GNU libc
that are not correct on all platforms.  For instance, there are known
issues with libstdc++-v3 use of setlocale() in I/O functions.  Does your
shared library perform threaded I/O?

	User-written code interacting with libstdc++-v3 must follow the
SGI thread-safety rule, which basically says that the direct use of any
global library object (e.g. std::cout is global) or non-local object
returned from the library shared amongst user threads, must be protected
by a mutex or similar by the user.

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Threadiing Problems on AIX 4.3.3 ML-11 with gcc 3.2.3 (g++)
@ 2003-08-06 13:28 Markus.Schaeffer
  2003-08-06 18:52 ` David Edelsohn
  0 siblings, 1 reply; 6+ messages in thread
From: Markus.Schaeffer @ 2003-08-06 13:28 UTC (permalink / raw)
  To: gcc-help

Hello Folks,
      I still have problems if my server does many calls (threading) on a
"Service" function
that is placed in a in a SharedLib.

Is there a possibility that exceptions do not work in this scenario ?
Bug in g++ ?
Again wrong copile / link options ?

 Thanks
Mattey

Environment:
OS:   AIX 4.3.3 ML-11
CXX:  gcc 3.2.3 (I'am using g++)
LD:   /usr/ccs/bin/ld

### MAKEFILE ###
CXXFLAGS=   -c -g \
            -Wno-deprecated \
            -D_AIX \
            -fpic \
            -pthread \
            -fexceptions

LDFLAGS=    -pthread \
            -Wl,-brtl \
            -Wl,-bnoquiet \
            -Wl,-bh:5 \
            ${XERCESC_LDFLAGS}

SHARED_LDFLAGS=   -pthread -shared \
                  -Wl,-bE:symbols.exp \
                  -Wl,-binitfini:init:fini:0 \
                  -bM:SRE \
                  -Wl,-bnoquiet \
                  -Wl,-bh:5 \
                  ${XERCESC_LDFLAGS}
### MAKEFILE END ###

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Threadiing Problems on AIX 4.3.3 ML-11 with gcc 3.2.3 (g++)
  2003-08-05 15:55 Markus.Schaeffer
  2003-08-05 17:41 ` David Edelsohn
@ 2003-08-05 17:44 ` David Edelsohn
  1 sibling, 0 replies; 6+ messages in thread
From: David Edelsohn @ 2003-08-05 17:44 UTC (permalink / raw)
  To: Markus.Schaeffer; +Cc: gcc-help

	One more comment: you may need the -fpic option on the compilation
step if you are overriding symbols.  Otherwise, all AIX object files are
PIC by default.  AIX normally uses tight binding within a shared module,
unless the -Wl,-G option is used for System-V semantics.  The compiler
optimizes for tight binding as well, unless -fpic is specified.

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Threadiing Problems on AIX 4.3.3 ML-11 with gcc 3.2.3 (g++)
  2003-08-05 15:55 Markus.Schaeffer
@ 2003-08-05 17:41 ` David Edelsohn
  2003-08-05 17:44 ` David Edelsohn
  1 sibling, 0 replies; 6+ messages in thread
From: David Edelsohn @ 2003-08-05 17:41 UTC (permalink / raw)
  To: Markus.Schaeffer; +Cc: gcc-help

>>>>> Markus writes:

> I guess the linking options are wrong (too much!?).

> LDFLAGS=    -Wl,-brtl \
>  -Wl,-bnoipath \
>  -Wl,-bnoquiet \
>  -Wl,-bh:5 \
> -pthread \
> ${XERCESC_LDFLAGS} \
>  -lc_r -lC_r -lm_r -lpthreads -lpthreads_compat \
>  -lgcc -lstdc++ -lstdc++ \
>  -ldl -lnsl -lintl

> SHARED_LDFLAGS=   -Wl,-brtl \
>  -Wl,-bE:symbols.exp \
> -Wl,-binitfini:init:fini:1 \
>  -Wl,-bM:SRE \
>  -Wl,-bdynamic \
>  -Wl,-bnoquiet \
>  -Wl,-bh:5 \
>  -Wl,-bbigtoc \
>  -nostartfiles \
>  -pthread \
>  ${XERCESC_LDFLAGS} \
>   -lc_r -lC_r -lm_r -lpthreads -lpthreads_compat \
>   -lgcc -lstdc++ -lstdc++ \
>   -ldl -lnsl -lintl

	These options contain both "-Wl," to pass options through g++ to
the linker and libraries automatically linked by g++ like "-lc_r".  This
does not make any sense.  And "-lC_r" is the AIX VisualAge C++ library
that is completely incompatible with G++.

	Similarly the CXXFLAGS define too much.

	The only CXXFLAGS you should need to compile the source code for a
pthread application are

CXXFLAGS= -pthread

"-D_THREAD_SAFE" is defined implicitly by the -pthread commandline option,
"-D_REENTRANT" and "-D_LIBC_REENTRANT" do not have any meaning on AIX.  If
your application needs "-D_POSIX_SOURCE", that is your own issue.

	The only LDFLAGS you should need to link a shared object are

LDFLAGS= -pthread -shared -Wl,-bE:symbols.exp ${XERCESC_LDFLAGS}

and use "g++" to perform the link.

If you need System V-style runtime linking, you can add "-Wl,-G".
"-Wl,-brtl" is used in the application link step, not the shared libary
link step.

If you need the "-ldl -lnsl -lintl" libraries, that is your own issue, but
the rest of the libraries are redundant or wrong.

Only use "-Wl,-binitfini:init:fini:1" if you really have your own
initialization method that needs to be run at load-time.  The priority (1)
may conflict with G++ constructor priorities, if you are using G++
services in your initialization.

Only use "-Wl,-bbigtoc" if your shared library overflows the TOC. And it
would be better to recompile the source code with the -mminimal-toc option
instead of using the bigtoc linker option.

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Threadiing Problems on AIX 4.3.3 ML-11 with gcc 3.2.3 (g++)
@ 2003-08-05 15:55 Markus.Schaeffer
  2003-08-05 17:41 ` David Edelsohn
  2003-08-05 17:44 ` David Edelsohn
  0 siblings, 2 replies; 6+ messages in thread
From: Markus.Schaeffer @ 2003-08-05 15:55 UTC (permalink / raw)
  To: gcc-help

Hello all,
      I've got some strange problems on AIX 4.3.3 ML-11 / gcc 3.2.3 (I'am
using g++) / And /usr/ccs/bin/ld is used for linking.

--> Multithreading is not working.

Our application has as core a server that does dynamic loading of
sharedlibs
to call some methods like init/doWork/deinit.

The sharedlib is reintrant, so many threads (server) should be able to call
the doPost in the sharedlib.
But thread safe.....

I guess the linking options are wrong (too much!?).
Coul somebody tell me how to compile/link applications like this!

### Makefile ###
CXXFLAGS=   -c -g \
 -Wno-deprecated \
 -D_REENTRANT -D_LIBC_REENTRANT \
 -D_THREAD_SAFE -D_POSIX_SOURCE \
 -pthread -fexceptions \
 -fpic

LDFLAGS=    -Wl,-brtl \
 -Wl,-bnoipath \
 -Wl,-bnoquiet \
 -Wl,-bh:5 \
-pthread \
${XERCESC_LDFLAGS} \
 -lc_r -lC_r -lm_r -lpthreads -lpthreads_compat \
 -lgcc -lstdc++ -lstdc++ \
 -ldl -lnsl -lintl

SHARED_LDFLAGS=   -Wl,-brtl \
 -Wl,-bE:symbols.exp \
-Wl,-binitfini:init:fini:1 \
 -Wl,-bM:SRE \
 -Wl,-bdynamic \
 -Wl,-bnoquiet \
 -Wl,-bh:5 \
 -Wl,-bbigtoc \
 -nostartfiles \
 -pthread \
 ${XERCESC_LDFLAGS} \
  -lc_r -lC_r -lm_r -lpthreads -lpthreads_compat \
  -lgcc -lstdc++ -lstdc++ \
  -ldl -lnsl -lintl
### Makefile END ###

Regards
Markus

P.S.: Sorry David for interrupt you at work.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-08-07 12:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-07 12:47 Threadiing Problems on AIX 4.3.3 ML-11 with gcc 3.2.3 (g++) Markus.Schaeffer
  -- strict thread matches above, loose matches on Subject: below --
2003-08-06 13:28 Markus.Schaeffer
2003-08-06 18:52 ` David Edelsohn
2003-08-05 15:55 Markus.Schaeffer
2003-08-05 17:41 ` David Edelsohn
2003-08-05 17:44 ` David Edelsohn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).