public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* AIX xlc and gcc/g++ Question
@ 2000-04-26 10:51 Fang-Pin Chang
  2000-04-26 11:15 ` Martin v. Loewis
  2000-04-26 11:41 ` David Edelsohn
  0 siblings, 2 replies; 4+ messages in thread
From: Fang-Pin Chang @ 2000-04-26 10:51 UTC (permalink / raw)
  To: gcc

Hi!  I am trying to use a library (archive) that was built with GNU C/C++
with a C program that is built using AIX's xlc compiler.

The library has C interfaces that manipulates C++ objects declared within
the library as either static and/or global variables, and the C program
will be calling these C interface functions.

While the C program compiles and links fine, it core dumps upon execution.
The reason seems to be that the constructors for these static and/or global
C++ objects aren't being called.  I wrote a simple test library plus some
test code, and these seem to bear out my reasoning for the aforementioned
core dump.

However, the C program I am trying to write will run just fine if I compile
it with the gcc compiler.  But, I need it to work with the xlc compiler.

To get the C program to compile/link using xlc, I am linking in the
libgcc.a and libstc++.a as well.

What am I not doing or doing incorrectly?

My system is as follows:

	AIX RS/6000 OS level v4.2.0.0
	GNU C/C++ 2.8.1
	xlc 4.3 (I think)

Any advice/help would be appreciated.  Thanks!


--
Fang-Pin Chang
Qualcomm Incorporated
http://www.qualcomm.com

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

* Re: AIX xlc and gcc/g++ Question
  2000-04-26 10:51 AIX xlc and gcc/g++ Question Fang-Pin Chang
@ 2000-04-26 11:15 ` Martin v. Loewis
  2000-04-26 11:41 ` David Edelsohn
  1 sibling, 0 replies; 4+ messages in thread
From: Martin v. Loewis @ 2000-04-26 11:15 UTC (permalink / raw)
  To: fchang; +Cc: gcc

> What am I not doing or doing incorrectly?

I'm not sure about the specifics of AIX, but it could be that what you
want to do is not supported. g++ requires on some systems that main is
compiled with either gcc or g++, and that collect2 is used to link the
object files, to support construction of global objects.

Regards,
Martin

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

* Re: AIX xlc and gcc/g++ Question
  2000-04-26 10:51 AIX xlc and gcc/g++ Question Fang-Pin Chang
  2000-04-26 11:15 ` Martin v. Loewis
@ 2000-04-26 11:41 ` David Edelsohn
  2000-04-28 13:40   ` Fang-Pin Chang
  1 sibling, 1 reply; 4+ messages in thread
From: David Edelsohn @ 2000-04-26 11:41 UTC (permalink / raw)
  To: Fang-Pin Chang; +Cc: gcc

	gcc (not just g++) automatically generates calls to invoke the
static constructors produced by G++ that it finds at link time.  The list
of constructors is generated at link time by collect2, so it is not easy
to manually have your program perform the same functionality when linked
by XLC.

	Is it possible to perform the final link with gcc (or g++) instead
of XLC although you compile the C code with XLC?

	The next release should allow you to create a shared library of
the G++ code more easily and that will use the AIX runtime initialization
functionality, but that primarily is intended for AIX 4.3 and not
available with gcc-2.8.1 (or gcc-2.95.2).

	If you really need this to work with XLC as linker and do not need
the C++ statically constructed objects before the application gets
control, I think that you could generate the list of constructors manually
and call them first-thing at the beginning of main().

	If you perform a link phase using G++ and enable debugging in
collect2, the extra files generated will be printed on the screen as well
as preserved in /tmp (use "g++ -Wl,-debug ..." which passed the
commandline option "-debug" to collect2 front-end of the linker).  An
extra C file is generated and compiled containing a function which is
invoked by __main() in libgcc.a called before main().  The detail with
which you need to reproduce all of those steps depends on whether you need
static destructors, etc.  You might be able to run the list of
constructors directly.

David

	P.S. I would suggest that you use gcc-2.95.2 as well.

===============================================================================
David Edelsohn                                      T.J. Watson Research Center
dje@watson.ibm.com                                  P.O. Box 218
+1 914 945 4364 (TL 862)                            Yorktown Heights, NY 10598

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

* Re: AIX xlc and gcc/g++ Question
  2000-04-26 11:41 ` David Edelsohn
@ 2000-04-28 13:40   ` Fang-Pin Chang
  0 siblings, 0 replies; 4+ messages in thread
From: Fang-Pin Chang @ 2000-04-28 13:40 UTC (permalink / raw)
  To: David Edelsohn, Fang-Pin Chang; +Cc: gcc

David,

Thank you for an excellent and insightful reply.  For my program, I need to
link with the xlc linker.  However, as a workaround, I am employing a
first-use rule on initializing global objects.  That is, I am turning these
global objects into pointers, initializing them to null when they are
declared.  This seems to work.  Then, just before they are first
referenced/used, I am adding code to let the progarm allocate memory for
them.  Of course I am then relying on the OS to release the application
heap when the program exits.  This should be all right so long as the
destructors fo these objects don't do much, which they currently do not.

I will look into your suggestion about generating the list of constructors
manually as well as gcc 2.95.2.  As for deploying the code using the next
release of gcc under AIX 4.3, that will probably happen later this year.  I
will revisit this issue then.

Thanks again!

--

At 02:41 PM 4/26/00 -0400, David Edelsohn wrote:
>	gcc (not just g++) automatically generates calls to invoke the
>static constructors produced by G++ that it finds at link time.  The list
>of constructors is generated at link time by collect2, so it is not easy
>to manually have your program perform the same functionality when linked
>by XLC.
>
>	Is it possible to perform the final link with gcc (or g++) instead
>of XLC although you compile the C code with XLC?
>
>	The next release should allow you to create a shared library of
>the G++ code more easily and that will use the AIX runtime initialization
>functionality, but that primarily is intended for AIX 4.3 and not
>available with gcc-2.8.1 (or gcc-2.95.2).
>
>	If you really need this to work with XLC as linker and do not need
>the C++ statically constructed objects before the application gets
>control, I think that you could generate the list of constructors manually
>and call them first-thing at the beginning of main().
>
>	If you perform a link phase using G++ and enable debugging in
>collect2, the extra files generated will be printed on the screen as well
>as preserved in /tmp (use "g++ -Wl,-debug ..." which passed the
>commandline option "-debug" to collect2 front-end of the linker).  An
>extra C file is generated and compiled containing a function which is
>invoked by __main() in libgcc.a called before main().  The detail with
>which you need to reproduce all of those steps depends on whether you need
>static destructors, etc.  You might be able to run the list of
>constructors directly.
>
>David
>
>	P.S. I would suggest that you use gcc-2.95.2 as well.
>
>===========================================================================
====
>David Edelsohn                                      T.J. Watson Research
Center
>dje@watson.ibm.com                                  P.O. Box 218
>+1 914 945 4364 (TL 862)                            Yorktown Heights, NY 10598


--
Fang-Pin Chang
Qualcomm Incorporated
http://www.qualcomm.com

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

end of thread, other threads:[~2000-04-28 13:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-26 10:51 AIX xlc and gcc/g++ Question Fang-Pin Chang
2000-04-26 11:15 ` Martin v. Loewis
2000-04-26 11:41 ` David Edelsohn
2000-04-28 13:40   ` Fang-Pin Chang

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).