This is the mail archive of the c++-embedded@sourceware.cygnus.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc vs g++ and linking with as


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" {
<declarations of stuff that uses C linkage>
}

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]