From mboxrd@z Thu Jan 1 00:00:00 1970 From: "C. M. Heard/VVNET, Inc." To: Chris Howard Cc: c++-embedded@cygnus.com, crossgcc@cygnus.com Subject: Re: gcc vs g++ and linking with as Date: Thu, 25 Jun 1998 20:20:00 -0000 Message-id: References: <35926CEF.9F0E576F@intellistor.com> X-SW-Source: 1998/msg00006.html On Thu, 25 Jun 1998, Chris Howard wrote: > binutils 2.9 > gcc/g++ 2.8.0 > > Host Sun Sparc Solaris 2.5 > Target Motorola Coldfire (-m5200) a.out object format > > --- > > Not using stdlib (-nostdlib) > > We have some code in assembler, and some in C. > Compiling with as,gcc and linking with ld works fine. > Compiling with as,g++ and linking with ld does not work, > undefined symbols for those things written in assembler. > > The .o files output from g++ compilation have exported symbols that > end in '__Fv' whereas the assembler output .o files don't have > '__Fv' on the symbols. Is that the problem? Is there > some way to make it work? What is __Fv? The C++ compiler "mangles" the names of functions in order to encode the type and number of arguments and the return type. You can turn that off by declaring that the function uses C linkage conventions (as you will see if you look at the system header files on your Solaris host): extern "C" { } I always do that in my own embedded work when I write functions or define data structures in assembler language that I wish to use in C or C++ programs. I also do that when I want to write a function in C++ that I can call from C or assembler language programs. In these cases I make one header file that can be included in modules written in any of these languages. Here is an actual example: /* * jobqueue.h - kernel entry points for job queue maintenance * * Copyright (c) 1996 VVNET, Inc. * All Rights Reserved. */ #ifndef _JOBQUEUE_H #define _JOBQUEUE_H #include "jqe.h" #ifndef __ASSEMBLER__ #ifdef __cplusplus extern "C" { #endif void jobqueue_init (void); int get_jqe (JQE_PTR p); #ifdef __cplusplus } #endif #else /* ifdef __ASSEMBLER__ */ .globl jobqueue_init .globl get_jqe #endif /* __ASSEMBLER__ */ #endif /* _JOBQUEUE_H */ As it happens, both of these functions are implemented in assembler language, but the same header file would work if one or both was written in C or C++. > An alternative might be to put the assembly code in > C/C++ wrapper functions. Any hints/comments that > would be appreciated also. By that I presume you mean using in-line assembler. That does have certain advantages if you take the time to learn how use extended inline asembler to let gcc automatically select free scratch registers, bind registers to calling parameters, etc. I do this for certain macros I want to inline but as a rule I prefer to use the assembler when I am writing straight assembler code. For more info read the gcc info files (search for the string "Extended Asm"). > Chris Howard Mike -- C. M. Heard/VVNET, Inc. heard@vvnet.com