public inbox for c++-embedded@sourceware.org
 help / color / mirror / Atom feed
From: "C. M. Heard/VVNET, Inc." <heard@vvnet.com>
To: Chris Howard <choward@intellistor.com>
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	[thread overview]
Message-ID: <Pine.BSF.3.96.980625194955.21282A-100000@shell16.ba.best.com> (raw)
In-Reply-To: <35926CEF.9F0E576F@intellistor.com>

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


  reply	other threads:[~1998-06-25 20:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-06-25  8:32 Chris Howard
1998-06-25 20:20 ` C. M. Heard/VVNET, Inc. [this message]
1998-06-25 23:03 ` Stephen Williams
1998-06-26  0:59 ` Robert J. Brown
1998-06-25  9:21 Dave Hansen
     [not found] <s5923122.008@btree.com>
1998-06-25 10:53 ` Chris Howard
1998-06-25 11:26 Gary Mussar
1998-06-25 11:36 Gary Mussar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.BSF.3.96.980625194955.21282A-100000@shell16.ba.best.com \
    --to=heard@vvnet.com \
    --cc=c++-embedded@cygnus.com \
    --cc=choward@intellistor.com \
    --cc=crossgcc@cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).