NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: Banjobeni on November 30, 2010, 09:05:03 PM

Title: Storing addresses of initialized data in other initialized data
Post by: Banjobeni on November 30, 2010, 09:05:03 PM
Hi,

I need to embed some type information in my assembly program for a simple Object-Oriented language. I need to embed a virtual method table and information about the base class of an object.

I tried to embed it in the .data section of my assembly program, for each type in the following format:
I end up with the following, actual code replaced by nops:

Code: [Select]
section .data
type_Object dw 0, 0
type_Object_array dw type_Object, 0
type_A dw type_Object, 1, method_A_override, 2, method_A_base, 0
type_A_array dw type_Object, 0
type_B dw type_A, 1, method_B_override, 3, method_B_sub, 0
type_B_array dw type_Object, 0
type_Main dw type_Object, 4, method_Main_main, 0
type_Main_array dw type_Object, 0

section .text

method_A_override:
nop
method_A_base:
nop
method_B_override:
nop
method_B_sub:
nop
method_Main_main:
nop

I compile using -f win32, and I get:

Code: [Select]
VirtualMethod.javali.s:3: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:4: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:4: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:4: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:5: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:6: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:6: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:6: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:7: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:8: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:8: error: COFF format does not support non-32-bit relocations
VirtualMethod.javali.s:9: error: COFF format does not support non-32-bit relocations

I don't understand why these error messages are generated and am thankful for any explanations.
Title: Re: Storing addresses of initialized data in other initialized data
Post by: Frank Kotler on November 30, 2010, 09:41:47 PM
Code: [Select]
type_Object dw 0, 0
type_Object_array dw type_Object, 0
        ...

The first line stores two words (16-bit values). This line doesn't cause an error, but may not be what you want. Remaining lines attempt to store the address of "type_Object" in a word - but the address (pointer) is 32 bits, in 32-bit code. Won't fit. Change it to "dd" and it'll work. You may want "dd" throughout...

"dw" looks like it might mean "dword", but it means "data word" - you want "dd", "data dword". An easy mistake to make (ask me how I know). :)

Best,
Frank

Title: Re: Storing addresses of initialized data in other initialized data
Post by: Cyrill Gorcunov on November 30, 2010, 09:44:50 PM
Thanks Frank, indeed. dd should do the trick. we don't support 16bit relocations
Title: Re: Storing addresses of initialized data in other initialized data
Post by: Banjobeni on November 30, 2010, 09:52:27 PM
Thx guys, I interpreted "dw" as doubleword and therefore didn't see the problem. dd worked.