how to access glibc data types from an assembly program using got?

97 views Asked by At

I'm trying to access the stdin C FILE* type so i can call fgets to get input and echo it back. I can use plt section to access C functions but can't use .got section (which if i understand right is like plt but for data) in the same way for for stdin as a segmentation fault always result from mov instruction after lea

section .bss 
    BUFFERLEN equ 100
    BUFFER: resb BUFFERLEN
section .text
global main
extern stdin, fgets
main: 
default rel
    push rbp             
    mov rbp, rsp          
        ; First get input to print
    
    mov rdi, [rel BUFFER]
    mov rsi, BUFFERLEN
   
    mov rdx, [rel stdin wrt ..gotpc] 
    
    call fgets wrt ..plt
    
    pop rbp
    ret         ; return back to caller   

built and linked with makefile as

proj13: proj13.o
    gcc -pie -fpie -o proj13 proj13.o
proj13.o: proj13.asm
    nasm -g -F DWARF -f elf64 -o proj13.o proj13.asm
0

There are 0 answers