www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - NASM + DMC Headache

reply Tristan Ward <tristan wytraven.com> writes:
I have assembled a file using NASM with the following config:

nasm -f obj mmx.asm

which spits out a file named mmx.obj (NASM describes this switch as 
producing: "MS-DOS 16-bit/32-bit OMF object files")

I have linked this succesfully into a lib compiled by DMC++ which 
includes the following header to provide access to the asm stuff:

void __cdecl mmx_memcpy(void *d,void *s,int bytes);
void __cdecl mmx_convert_32_to_32_bgr888(void *d,void *s,int pixels);
void __cdecl mmx_convert_32_to_24_rgb888(void *d,void *s,int pixels);
void __cdecl mmx_convert_32_to_24_bgr888(void *d,void *s,int pixels);
void __cdecl mmx_convert_32_to_16_rgb565(void *d,void *s,int pixels);
void __cdecl mmx_convert_32_to_16_bgr565(void *d,void *s,int pixels);
void __cdecl mmx_convert_32_to_16_rgb555(void *d,void *s,int pixels);
void __cdecl mmx_convert_32_to_16_bgr555(void *d,void *s,int pixels);

The lib builds fine but when I then goto to use it in a project I get 
the following upon attempting to build it:

   Building Blit.exe
	link /SILENT /DELEXECUTABLE /EXET:NT /SU:WINDOWS main.obj 
,Blit.exe,,tinyptc.lib,,

OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

G:\Libraries\TinyPTC\lib\tinyptc.lib(convert)
  Error 42: Symbol Undefined ?mmx_convert_32_to_16_rgb555  YAXPAX0H Z 
(void cdecl mmx_convert_32_to_16_rgb555(void *,void *,int ))
G:\Libraries\TinyPTC\lib\tinyptc.lib(convert)
  Error 42: Symbol Undefined ?mmx_convert_32_to_16_bgr565  YAXPAX0H Z 
(void cdecl mmx_convert_32_to_16_bgr565(void *,void *,int ))
G:\Libraries\TinyPTC\lib\tinyptc.lib(convert)
  Error 42: Symbol Undefined ?mmx_convert_32_to_16_rgb565  YAXPAX0H Z 
(void cdecl mmx_convert_32_to_16_rgb565(void *,void *,int ))
G:\Libraries\TinyPTC\lib\tinyptc.lib(convert)
  Error 42: Symbol Undefined ?mmx_convert_32_to_24_rgb888  YAXPAX0H Z 
(void cdecl mmx_convert_32_to_24_rgb888(void *,void *,int ))
G:\Libraries\TinyPTC\lib\tinyptc.lib(convert)
  Error 42: Symbol Undefined ?mmx_memcpy  YAXPAX0H Z (void cdecl 
mmx_memcpy(void *,void *,int ))
SMAKE fatal error: command "link" returned with error code 5
Stopping.

OK so I'm confused...  Why doesn't it spit erros when I build the lib in 
the first place if there's a problem??  It's 6:36AM and I haven't slept 
yet trying figure this out so please ease my pain.

Regards,
Tristan Ward
Jan 29 2004
parent reply -scooter- <scottm cs.ucla.edu> writes:
Tristan Ward wrote:

 I have assembled a file using NASM with the following config:
 
 nasm -f obj mmx.asm
 
 which spits out a file named mmx.obj (NASM describes this switch as 
 producing: "MS-DOS 16-bit/32-bit OMF object files")
 
 I have linked this succesfully into a lib compiled by DMC++ which 
 includes the following header to provide access to the asm stuff:
 
#ifdef __cplusplus extern "C" { #endif
 void __cdecl mmx_memcpy(void *d,void *s,int bytes);
 void __cdecl mmx_convert_32_to_32_bgr888(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_24_rgb888(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_24_bgr888(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_16_rgb565(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_16_bgr565(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_16_rgb555(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_16_bgr555(void *d,void *s,int pixels);
#ifdef __cplusplus } #endif
 The lib builds fine but when I then goto to use it in a project I get 
 the following upon attempting to build it:
 
   Building Blit.exe
     link /SILENT /DELEXECUTABLE /EXET:NT /SU:WINDOWS main.obj 
 ,Blit.exe,,tinyptc.lib,,
 
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
 
 G:\Libraries\TinyPTC\lib\tinyptc.lib(convert)
  Error 42: Symbol Undefined ?mmx_convert_32_to_16_rgb555  YAXPAX0H Z 
 (void cdecl mmx_convert_32_to_16_rgb555(void *,void *,int ))
Looks like a mangled C++ name. Put the extern "C" bracketing around your functions and rebuild. -scooter
Jan 29 2004
parent reply Tristan Ward <tristan wytraven.com> writes:
Thanks for your reply scooter.

I tried what you sugested and that at least made the 'Symbol Undefined' 
errors go away however, I now get a whole stack of these errors instead:

G:\Libraries\TinyPTC\lib\tinyptc.lib(mmx)
  Error 41: Unrecognized FIXUPP Type at Relative 000C9H  from
  Segment text
  FRAME  = Frame of TARGET 00000H
  TARGET = Segment data 08074H
  FIXUPP Type = 16-bit Offset
...

I checked the OPTLINK section of the manual and found this most helpful 
description:

Unrecognized FIXUPP Type
Most likely cause is the object file has been corrupted, or a translator 
error has occurred.

I'm afraid that this doesn't tell me much.  I'm teaching myself about 
all this stuff and so messages like that which may of course mean plenty 
to a seasoned pro mean next to nothing to me.  What the hell is a FIXUP? ;)

OK so I figured I would pull on my powers of deduction...  'object file 
corrupted' if thats refering to the .obj that I got nasm to spit out 
then I can understand that, nasm is the unkown quantity here for me so 
maybe I need to use different switches or something for it, I don't know 
yet.  As for 'translator error'...what the translator?

What really confuses me is why the .lib that the mmx.obj is linked into 
builds fine...surely if there was something wrong with the .obj that 
nasm is spitting out then the library itself wouldnt build...

Here's an example of some of the asm.  I have taken what looks like 
relevant information about 1 of the asm functions and stuck it together:

bits 32

global _mmx_memcpy
...
...

section .text

align 16

_mmx_memcpy:

     push ebp
     mov ebp,esp

     pushad

     mov edi,[ebp+8]       ; destination
...
...

If I take out the mmx asm section then all works fine, lib builds, and 
my prog using the lib build.  But I would really like to make use of the 
optimised asm routines as they offer quite a significant performance boost.

Anyway, thanks for taking a shot at helping me.

Regards,
Tristan Ward
-scooter- wrote:
 Tristan Ward wrote:
 
 I have assembled a file using NASM with the following config:

 nasm -f obj mmx.asm

 which spits out a file named mmx.obj (NASM describes this switch as 
 producing: "MS-DOS 16-bit/32-bit OMF object files")

 I have linked this succesfully into a lib compiled by DMC++ which 
 includes the following header to provide access to the asm stuff:
#ifdef __cplusplus extern "C" { #endif
 void __cdecl mmx_memcpy(void *d,void *s,int bytes);
 void __cdecl mmx_convert_32_to_32_bgr888(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_24_rgb888(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_24_bgr888(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_16_rgb565(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_16_bgr565(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_16_rgb555(void *d,void *s,int pixels);
 void __cdecl mmx_convert_32_to_16_bgr555(void *d,void *s,int pixels);
#ifdef __cplusplus } #endif
 The lib builds fine but when I then goto to use it in a project I get 
 the following upon attempting to build it:

   Building Blit.exe
     link /SILENT /DELEXECUTABLE /EXET:NT /SU:WINDOWS main.obj 
 ,Blit.exe,,tinyptc.lib,,

 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 G:\Libraries\TinyPTC\lib\tinyptc.lib(convert)
  Error 42: Symbol Undefined ?mmx_convert_32_to_16_rgb555  YAXPAX0H Z 
 (void cdecl mmx_convert_32_to_16_rgb555(void *,void *,int ))
Looks like a mangled C++ name. Put the extern "C" bracketing around your functions and rebuild. -scooter
Jan 29 2004
parent "Walter" <walter digitalmars.com> writes:
It probably means you're mixing 16 and 32 bit code. In your asm code, make
sure it is set to generate 32 bit code, not 16 bit code.
Feb 01 2004