underscore - coff vs. aout

joel@OARcorp.com joel@OARcorp.com
Tue Jul 13 07:53:00 GMT 1999

On Mon, 12 Jul 1999 Todd_Manchester@nmss.com wrote:

> I have a number of assembly files with symbols written with a underscore
> prepended so that they will link with .c files compiled for a.out format.
> I was thinking of changing to coff format, and I would like to know if
> there was a way to compile the .c files for coff so that they would still
> link correctly to the assembly files (that is, with prepended underscores).
> Changing every symbol would be a large undertaking, and I would like to
> avoid it if possible.
> Any suggestions?

Many of the gcc targets include enough information in the cpp predefines
to get this right with the help of a few macros.  This is a fragment from
newlib's m68k setjmp.S to show how:

* These are predefined by new versions of GNU cpp.  */

#define __USER_LABEL_PREFIX__ _


/* ANSI concatenation macros.  */

#define CONCAT1(a, b) CONCAT2(a, b)
#define CONCAT2(a, b) a ## b

/* Use the right prefix for global labels.  */

#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)

.global SYM (setjmp)
.global SYM (longjmp)

SYM (setjmp):

Just be careful to use SYM everywhere.  There are also macros to hide the
differences in register naming (%reg vs. reg for example). RTEMS has an
asm.h file for each port which has these macros in it.

For RTEMS, this has worked well enough that we can compile easily for
a.out, coff, and elf.  I know the m68k has gone through all 3 formats.
Many of the other ports have been compiled with 2 of the 3. 

Joel Sherrill, Ph.D.             Director of Research & Development
joel@OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985

New CrossGCC FAQ: http://www.objsw.com/CrossGCC
To remove yourself from the crossgcc list, send
mail to crossgcc-request@cygnus.com with the
text 'unsubscribe' (without the quotes) in the
body of the message.

More information about the crossgcc mailing list