flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > 'ELF64 executable' vs 'ELF64' and address generation

Author
Thread Post new topic Reply to topic
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 18 Jan 2008, 04:07
Hi Guys,

In working on the b0 compiler, I've noticed that the Linux build no longer assemblies using fasm. Since the Linux port doesn't use ld/gcc for the final executable (unlike all the other OSes), it's the only port effected by this.

The error is that a symbol is out of range when using the following instructions: eg:
lea rax, [_B0_argp]

(the b0.asm is roughly 1.5MB, executable around 200KB, and in memory size around 500MB).

If I build using:
format ELF64 executable, fasm stops.
format ELF64, fasm assemblies the source file fine, however I suspect this is due to the GOT.

Now I could understand if the variable was outside 2GB of the point that was needed (due to offsets being limited to 32bit when using 'lea', even on 64bit systems), however the total object size in memory is a tad under 500MB. (That's code, pre-defined data, and pre-defined BSS space).

So my question is, how does fasm calculate the segment offsets in memory for ELF64 executables, and is there any way to control those offsets? (It appears that the segments are being spaced too far apart when dealing with larger asm files).

Or does fasm request that the executable by placed in memory above the 4GB mark?

PS. On smaller test files, the 'lea' instructions works fine in both 'ELF64' and 'ELF64 executable' formats, it's just when the source and executables get bigger...

PPS. Source files attached.


Description: Zip containing a ELF64 executable and ELF64 object source formats.
Download
Filename: b0_src.zip
Filesize: 204.79 KB
Downloaded: 450 Time(s)

Post 18 Jan 2008, 04:07
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 18 Jan 2008, 17:14
I get a value out of range error at
Code:
align 8
_B0_atof_clean_bcd:
        lea r0, [_B0__atof_bcd]
    


Do you get the error at a different place with the attached sources?

When I use
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End main Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


segment writeable readable
_B0__atof_bcd rb 32
    

I get _B0__atof_bcd = 00000000919943D4 which is too big to be encoded as a 32-bit immediate with sign extention. However if I do this minimal change:
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End main Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


_B0__atof_bcd rb 32
segment writeable readable    

I get _B0__atof_bcd = 00000000004293D4. So the jump added by the segment is huge and as far as I can see completely unjustified, I think there is a bug in fasm since if I use a small source with the same segments such terrible jumps does not exists.

Code:
format elf64 executable
entry main

segment readable writeable
rb 128

segment executable
main:
a = _B0__atof_bcd
repeat 16
  b = a shr 60

  if b < 10
    display b + '0'
  else
    display b - 10 + 'A'
  end if

  a = a shl 4
end repeat
display 13, 10

  lea rax, qword [_B0__atof_bcd]


segment writeable readable
_B0__atof_bcd dq ?

segment writeable readable    

Displays "0000000000402127" and has the same amount of segments in the same order.

Please confirm if you get the very same error or not because that could help in the bug tracking.
Post 18 Jan 2008, 17:14
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 18 Jan 2008, 23:23
fasm 1.66 assembles it without tweaking anything in b0_elf_executable.asm.
Post 18 Jan 2008, 23:23
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8397
Location: Kraków, Poland
Tomasz Grysztar 19 Jan 2008, 14:42
There was a small bug in resolving - it's enough to change this kind of error to be of "recoverable" type (not signalized unless happened in the final pass) to fix this - 1.67.26 is going to have this fix included.
Post 19 Jan 2008, 14:42
View user's profile Send private message Visit poster's website Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 21 Jan 2008, 00:59
@Tomasz: Cool, just glad I wasn't missing something. (I hope you're glad I'm finding these problems on larger source files?)

@Loco: I was getting the error on a 'lea' just before that one you indicated. I hadn't thought to try an earlier fasm version, so thanks for checking.
Post 21 Jan 2008, 00:59
View user's profile Send private message Visit poster's website Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Raedwulf 06 Feb 2008, 08:13
I don't know if this has been resolved - I tried compiling the latest b0 and got this:

Code:
    


Cheers xD

_________________
Raedwulf
Post 06 Feb 2008, 08:13
View user's profile Send private message MSN Messenger Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 07 Feb 2008, 01:12
Raedwulf wrote:
I don't know if this has been resolved - I tried compiling the latest b0 and got this:
Cheers xD


I've tried the latest build on mine, and got the same error, so it doesn't look like it's been resolved?

PS. I took it for granted that the issue had been solved, and didn't retest it when the new FASM release came out.
Post 07 Feb 2008, 01:12
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8397
Location: Kraków, Poland
Tomasz Grysztar 12 Feb 2008, 06:48
Right, the bug was in two places and I fixed only one of them.
Will get fixed completely in 1.67.27
Post 12 Feb 2008, 06:48
View user's profile Send private message Visit poster's website Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Raedwulf 12 Feb 2008, 08:12
Wooohooo!

_________________
Raedwulf
Post 12 Feb 2008, 08:12
View user's profile Send private message MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.