Author Topic: Storing addresses of initialized data in other initialized data  (Read 19225 times)

Offline Banjobeni

  • Jr. Member
  • *
  • Posts: 2
Storing addresses of initialized data in other initialized data
« 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:
  • address of the base type (or 0 if it does not have a base type)
  • for every method in that type, an id of the method and the address of the code of this method
  • 0 to indicate end of methods and therefore end of type data
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.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Storing addresses of initialized data in other initialized data
« Reply #1 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


Offline Cyrill Gorcunov

  • NASM Developer
  • Full Member
  • *****
  • Posts: 179
  • Country: 00
Re: Storing addresses of initialized data in other initialized data
« Reply #2 on: November 30, 2010, 09:44:50 PM »
Thanks Frank, indeed. dd should do the trick. we don't support 16bit relocations

Offline Banjobeni

  • Jr. Member
  • *
  • Posts: 2
Re: Storing addresses of initialized data in other initialized data
« Reply #3 on: November 30, 2010, 09:52:27 PM »
Thx guys, I interpreted "dw" as doubleword and therefore didn't see the problem. dd worked.