Name mangling
Claudio Bley
bley@mail.cs.uni-magdeburg.de
Thu Sep 20 09:29:00 GMT 2001
>>>>> "Sune" == Sune Foldager <cryo@worldonline.dk> writes:
Sune> Greetings, During my work on a kernel project for x86 based PC's,
Sune> I have encountered a problem with the way the gcc compiller
Sune> mangles/formats names into symbols for the linker. First time was
Sune> when I switched from DOS djgpp, to Linux native gcc (RedHat,
Sune> later Mandrake). Second time was today when I tried to compile my
Sune> kernel under CygWin.
Sune> The problem is that I use a number of assembler files to
Sune> facilitate things like x86 instructions 'cli' and 'sti' and alot
Sune> of other lowlevel stuff. Under DOS using djgpp, whenever I made a
Sune> prototype like: void disable(); djgpp would produce a reference
Sune> to the symbol '_disable', which I then also named my label in the
Sune> assembler file (assembled using NASM). However, when I migrated
Sune> to Linux, the same prototype produced and produces the symbol
Sune> 'disable' without the underscore, requiering me to change all my
Sune> assembler files.
Sune> I have without success searched for options to change this
Sune> behaviour of GCC. The latest problem then is that under CygWin,
Sune> the gcc compiller (which is the same or close to the same version
Sune> as the one in my Linux), again mangles names like djgpp did, with
Sune> the leading underscore.
Sune> My question then is this: Is there any way to control how the
Sune> symbols are generated, and is the behaviour even documented
Sune> anywhere? I haven't been able to find either.
Sune> Thanks alot in advance, Sune Foldager.
I don't think that there is a way of controlling how gcc generates symbols
(except of changing the source code), it is OS dependent AFAIK.
But you can define a macro (see attached file) and pass '-d<gensys>' to
nasm. Just %include "csym.inc", then you only need to define C symbols with
that macro (e.g. csym disable).
Claudio
-------------- next part --------------
%ifndef __csym_include__
%define __csym_include__
%macro csym 1
%ifdef WinNT
%define %1 _%1
%endif
%ifdef Win95
%define %1 _%1
%endif
%ifdef DOS
%define %1 _%1
%endif
%ifdef Linux
%define x x
%endif
%ifdef Linux_Alpha
%define x x
%endif
%endmacro
%endif
More information about the Gcc-help
mailing list