On Wed, Jul 30, 2003 at 11:19:31PM +0530, Nemo Physche wrote: > Hello, > > I'm having a problem compiling my C and ASM code using gcc on linux. > I have a set of C files calling MMX/SSE/SSE2 optimized routines that > are coded in ASM and compiled using GAS. The ASM function names are > declared as global and have a leading underscore, which I believe is > required when calling the function from my C code. It compiles and > links as expected with DJGPP, gcc 3.2.3. > > When some one else tried the compilation on a Linux machine with > gcc 3.3 it belches at the linking stage, unable to find the ASM > functions. Inspecting the C program's object files, I find that the > function calls do not have a leading underscore. The problem is solved > if I remove the leading underscore from my ASM routine name. > > Why does the code not compile in one situation and work perfectly in the > other? The NASM Manual explains: ,----[ http://home.comcast.net/~fbkotler/nasmdoc8.html ] | 8.1.1 External Symbol Names | | Most 32-bit C compilers share the convention used by 16-bit compilers, | that the names of all global symbols (functions or data) they define | are formed by prefixing an underscore to the name as it appears in the | C program. However, not all of them do: the ELF specification states | that C symbols do not have a leading underscore on their | assembly-language names. | | The older Linux a.out C compiler, all Win32 compilers, DJGPP, and | NetBSD and FreeBSD, all use the leading underscore; for these | compilers, the macros cextern and cglobal, as given in section 7.4.1, | will still work. For ELF, though, the leading underscore should not be | used. `---- ,----[ man gcc ] | | -fleading-underscore | This option and its counterpart, -fno-leading-underscore, forcibly | change the way C symbols are represented in the object file. One | use is to help link with legacy assembly code. | | Warning: the -fleading-underscore switch causes GCC to generate | code that is not binary compatible with code generated | without that switch. Use it to conform to a non-default | application binary interface. Not all targets provide | complete support for this switch. `---- -- Claudio Bley ASCII ribbon campaign (") Debian GNU/Linux user - against HTML email X http://www.cs.uni-magdeburg.de/~bley/ & vCards / \