flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Why @Gpm_Open=nil

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 339
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
Someone sign the reason why Gpm_Open = nil after (libgpmptr <> nil)? (on x64 Linux)
Code:
const
    libgpm = 'libgpm.so.2'; {/usr/lib}
    ....
    libgpmptr:= dlopen (libgpm, RTLD_LAZY);
    if libgpmptr = nil then exit;
    @Gpm_Open:= dlsym (libgpmptr, pchar ('Gpm_Open'));    

_________________
smaller is better
Post 12 Aug 2021, 16:01
View user's profile Send private message Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 373
Location: Australia
redsock
I wrote a quick test with my own HeavyThing library to test, and it output:

Code:
# ./test
dlopen returned: 0x65d2c0
dlsym returned: 0x7f6bf8eaaa10
    



Program source:
Code:
include '../../ht_defaults.inc'
include '../../ht.inc'

extrn   dlopen
extrn   dlsym
extrn   dlerror

public main
falign
main:
        call    ht$init

        ; stack needs to be align 16 before libc
        and     rsp, not 0xf

        mov     edi, .msg1
        call    string$to_stdout

macro hexprint {
        mov     rdi, rax
        mov     esi, 16
        call    string$from_unsigned
        push    rax
        mov     rdi, rax
        call    string$to_stdoutln
        pop     rdi
        call    heap$free
}

        mov     edi, .libgpm
        mov     esi, 1          ; RTLD_LAZY
        call    PLT dlopen
        mov     rbx, rax
        hexprint

        mov     edi, .msg2
        call    string$to_stdout

        mov     rdi, rbx
        mov     esi, .gdmopen
        call    PLT dlsym
        mov     r12, rax
        hexprint

        test    r12, r12
        jnz     .doexit
        call    PLT dlerror
        mov     r12, rax
        mov     rdi, rax
        call    strlen_latin1
        mov     edx, eax
        mov     eax, syscall_write
        mov     edi, 1
        mov     rsi, r12
        syscall
        
        
.doexit:
        mov     eax, syscall_exit
        xor     edi, edi
        syscall
cleartext .msg1, 'dlopen returned: 0x'
cleartext .msg2, 'dlsym returned: 0x'
align 8
.libgpm         db      'libgpm.so.2',0
.gdmopen        db      'Gpm_Open',0

include '../../ht_data.inc'
    


Compiled with:
Code:
fasm -m 524288 test.asm && gcc -o test test.o -ldl    

_________________
2 Ton Digital - https://2ton.com.au/
Post 12 Aug 2021, 21:10
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.