Recent

Author Topic: How to create a linkable .obj file (COFF)?  (Read 43651 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8819
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #30 on: March 05, 2011, 05:26:30 pm »
Quote
The generated .s doesn't contain neither PASCALMAIN nor the other 4 unresolved symbols
Are you still compiling a library? It should be there. Even an empty library:
Code: Delphi  [Select][+][-]
  1. library test;
  2.  
  3. end.
  4.  
produces this:
Quote
   .file "test.pas"
# Begin asmlist al_begin
# End asmlist al_begin
# Begin asmlist al_stabs
# End asmlist al_stabs
# Begin asmlist al_procedures

.section .text.n__p$test_main
   .balign 16,0x90
.globl   PASCALMAIN
PASCALMAIN:
.globl   _P$TEST_main
_P$TEST_main:
# Temps allocated between ebp+0 and ebp+0
   # Register ebp allocated
# [test.pas]
# [3] end.
   pushl   %ebp
   movl   %esp,%ebp
   # Register eax,ecx,edx allocated
   call   FPC_LIBINITIALIZEUNITS
   # Register eax,ecx,edx released
   leave
   # Register ebp released
   ret
# End asmlist al_procedures
# Begin asmlist al_globals

.section .data.n_THREADVARLIST_P$TEST
   .balign 4
.globl   THREADVARLIST_P$TEST
THREADVARLIST_P$TEST:
   .long   0

.section .data.n_INITFINAL
   .balign 4
.globl   INITFINAL
INITFINAL:
   .long   2,0
   .long   INIT$_SYSTEM
   .long   0
   .long   INIT$_FPINTRES
   .long   0

.section .data.n_FPC_THREADVARTABLES
   .balign 4
.globl   FPC_THREADVARTABLES
FPC_THREADVARTABLES:
   .long   4
   .long   THREADVARLIST_SYSTEM
   .long   THREADVARLIST_FPINTRES
   .long   THREADVARLIST_SYSINITPAS
   .long   THREADVARLIST_P$TEST

.section .data.n_FPC_RESOURCESTRINGTABLES
   .balign 4
.globl   FPC_RESOURCESTRINGTABLES
FPC_RESOURCESTRINGTABLES:
   .long   0

.section .data.n_FPC_WIDEINITTABLES
   .balign 4
.globl   FPC_WIDEINITTABLES
FPC_WIDEINITTABLES:
   .long   0

.section .fpc.n_version
   .balign 16
   .ascii   "FPC 2.5.1 [2011/02/15] for i386 - Win32"

.section .data.n___heapsize
   .balign 4
.globl   __heapsize
__heapsize:
   .long   0

.section .data.n___fpc_valgrind
.globl   __fpc_valgrind
__fpc_valgrind:
   .byte   0
# End asmlist al_globals
# Begin asmlist al_const
# End asmlist al_const
# Begin asmlist al_typedconsts
# End asmlist al_typedconsts
# Begin asmlist al_rotypedconsts
# End asmlist al_rotypedconsts
# Begin asmlist al_threadvars
# End asmlist al_threadvars
# Begin asmlist al_imports
# End asmlist al_imports
# Begin asmlist al_exports
# End asmlist al_exports
# Begin asmlist al_resources
# End asmlist al_resources
# Begin asmlist al_rtti
# End asmlist al_rtti
# Begin asmlist al_dwarf_frame
# End asmlist al_dwarf_frame
# Begin asmlist al_dwarf_info
# End asmlist al_dwarf_info
# Begin asmlist al_dwarf_abbrev
# End asmlist al_dwarf_abbrev
# Begin asmlist al_dwarf_line
# End asmlist al_dwarf_line
# Begin asmlist al_picdata
# End asmlist al_picdata
# Begin asmlist al_resourcestrings
# End asmlist al_resourcestrings
# Begin asmlist al_objc_data
# End asmlist al_objc_data
# Begin asmlist al_objc_pools
# End asmlist al_objc_pools
# Begin asmlist al_end
# End asmlist al_end

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #31 on: March 05, 2011, 05:33:17 pm »
After your example here I changed the project from a library to an exe. I thought that was part of the solution (in the end I only need that symbol, regardless of whether it comes from an exe or dll project). I'll change it back now and try again.

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #32 on: March 05, 2011, 06:17:33 pm »
OK, now after changing back to a library the unresolved-messages changed a little bit, but after linking fpintres.o and objpas.o as well I'm now only left with 2 errors:
Code: [Select]
system.o : error LNK2001: unresolved external symbol __data_start__
system.o : error LNK2001: unresolved external symbol __data_end__
Please tell me I'm only one file-to-be-linked away from the final result!? :)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8819
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #33 on: March 06, 2011, 03:05:51 am »
Quote
Please tell me I'm only one file-to-be-linked away from the final result!?
Maybe... but now I don't know about the two. I'll try grep-ing my fpc source.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8819
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #34 on: March 06, 2011, 03:08:49 am »
Those two symbols come from heaptrc unit. Are you using -gh?

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #35 on: March 06, 2011, 03:14:38 am »
Are you using -gh?
No, shall I? (I compile without any parameters by command line ... well I used -a lately as you suggested, but that's all)

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #36 on: March 08, 2011, 09:18:10 pm »
Accordning to the output the reference to thw two missing symbols is in system.o:
Code: [Select]
system.o : error LNK2001: unresolved external symbol __data_start__
system.o : error LNK2001: unresolved external symbol __data_end__
So I don't think it has something to do with other units like heaptrc that you mentioned.

Well, I actually don't even know if I need those two symbols or if they're only just there in the system.o.
Can't I just define them in my unit? If you think that might be possible and you know the correct definition for them, please let me know!

Leledumbo

  • Hero Member
  • *****
  • Posts: 8819
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #37 on: March 09, 2011, 05:07:25 am »
Quote
Accordning to the output the reference to thw two missing symbols is in system.o
So I don't think it has something to do with other units like heaptrc that you mentioned
No, those are two missing symbols used by your system.o.

My grep result only found them in heaptrc unit, so you might want to try linking it.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12304
  • FPC developer.
Re: How to create a linkable .obj file (COFF)?
« Reply #38 on: March 09, 2011, 09:35:25 am »
64-bit I assume? These symbols are defined by the startup code of the binary. See rtl/linux/x86_64/*.as

Leledumbo

  • Hero Member
  • *****
  • Posts: 8819
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #39 on: March 09, 2011, 05:04:02 pm »
Quote
These symbols are defined by the startup code of the binary. See rtl/linux/x86_64/*.as
Hmm... something wrong with my grep then.

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #40 on: March 09, 2011, 05:14:42 pm »
My grep result only found them in heaptrc unit, so you might want to try linking it.
Using heaptrc by -gh doesn't help. It's causing even more unresolved messaged:
Code: [Select]
Unit1.o : error LNK2001: unresolved external symbol INIT$_HEAPTRC
Unit1.o : error LNK2001: unresolved external symbol FINALIZE$_HEAPTRC
Unit1.o : error LNK2001: unresolved external symbol THREADVARLIST_HEAPTRC
system.o : error LNK2001: unresolved external symbol __data_start__
system.o : error LNK2001: unresolved external symbol __data_end__

64-bit I assume? These symbols are defined by the startup code of the binary. See rtl/linux/x86_64/*.as
Yes, 64-bit, but Windows not Linux. Those *.as files only seem to be in the linux folder, but not in the Windows folder. But even if, I don't know what to do with them. Also notice that they include "__data_start" and not "__data_start__".

I ran a content-search over all files in the lazarus folder and __data_start__ is included in:
rtl\inc: heaptrc.pp, wstrings.inc and wustring22.inc
rtl: heaptrc.o, heaptrc.ppu, system.o, system.ppu
and also in several *.exe files

However, I don't know what to do with this information. Can I include the wstrings.inc file for example somehow? Or extract the declaration? It should somehow be possible to solve this whole mystery...

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #41 on: March 18, 2011, 10:02:41 pm »
I didn't get any further. Still searching for a solution for
Code: [Select]
system.o : error LNK2001: unresolved external symbol __data_start__
system.o : error LNK2001: unresolved external symbol __data_end__
Any other ideas? I mean, somebody has to know...  :-\

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12304
  • FPC developer.
Re: How to create a linkable .obj file (COFF)?
« Reply #42 on: March 18, 2011, 10:50:27 pm »
Quote
These symbols are defined by the startup code of the binary. See rtl/linux/x86_64/*.as
Hmm... something wrong with my grep then.

[Turtle] </home/marcov/src/fpc/rtl/linux/x86_64> grep data_start *
cprt0.as:       .globl __data_start
cprt0.as:__data_start:
cprt0.as:       .weak data_start
cprt0.as:       data_start = __data_start
dllprt0.as:     .globl __data_start
dllprt0.as:__data_start:
dllprt0.as:     .weak data_start
dllprt0.as:        data_start = __data_start
gprt0.as:       .globl __data_start
gprt0.as:__data_start:
gprt0.as:       .weak data_start
gprt0.as:       data_start = __data_start
prt0.as:        .globl __data_start
prt0.as:__data_start:
prt0.as:        .weak data_start
prt0.as:        data_start = __data_start

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #43 on: March 18, 2011, 11:07:43 pm »
Hi marcov, thanks for your quick reply!
Actually I already replied to that statement:

64-bit I assume? These symbols are defined by the startup code of the binary. See rtl/linux/x86_64/*.as
Yes, 64-bit, but Windows not Linux. Those *.as files only seem to be in the linux folder, but not in the Windows folder. But even if, I don't know what to do with them. Also notice that they include "__data_start" and not "__data_start__".

If I didn't understand it correctly, please explain it to me what exactly I can do. Thanks!

 

TinyPortal © 2005-2018