flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [bug] Unable to use negative 32-bit offsets with extrn

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 11 Jul 2023, 13:15
Code:
format elf64
extrn foo
dd foo+1  ;  this is fine
dd foo+0  ;  this is fine
dd foo-1  ;  <--- error: value out of range.    
This can be tracked to a change at version 1.69.41 (Mar 01, 2012).

In exprcalc.inc line 1330:
Code:
get_dword_value:
        mov     [value_size],4
        or      [operand_flags],1
        call    calculate_value
        cmp     al,4
        jne     check_dword_value
        mov     [value_type],2
        mov     eax,[edi]
        cdq
        cmp     edx,[edi+4]
        jne     range_exceeded
        mov     ecx,edx
        shr     ecx,31       ; <--- using sar fixes the bug
        cmp     cl,[value_sign]
        jne     range_exceeded
        ret    
The relocation table is correct for positive offsets.
Code:
Relocation section '.rela.flat' at offset 0x48 contains 1 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000000  00020000000b R_X86_64_32S      0000000000000000 foo + 1    
But is impossible to generate for negative offsets.
Post 11 Jul 2023, 13:15
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 12 Jul 2023, 16:17
Fixed in 1.73.31
Code:
Relocation section '.rela.flat' at offset 0x50 contains 3 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000000  00020000000b R_X86_64_32S      0000000000000000 foo + 1
000000000004  00020000000b R_X86_64_32S      0000000000000000 foo + 0
000000000008  00020000000b R_X86_64_32S      0000000000000000 foo - 1    
Post 12 Jul 2023, 16:17
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.