Skip to content

Confused by text at page 307 #36

Closed
@yeah-boi

Description

@yeah-boi

I'm confused by the following text at page 307:

When the variable is declared as global with its size and type (:data), it will live in the .data section of the executable file rather than the library! Because of this, you will always have to access it through GOT, even in the same file.

Is this really true? Lets modify ex2-main.asm like this:

extern _GLOBAL_OFFSET_TABLE_

global _start

extern sofun

global msg:data (msg.end - msg)

section .rodata

    msg: db "SO function called -- message is stored in 'main'", 10
    .end:

section .text
    
    _start:
        call sofun  wrt ..plt

        mov rax, 1
        mov rdi, 1
        mov rsi, msg ; No need to access via GOT.
        mov rdx, 50
        syscall

        mov rdi, 0
        mov rax, 60
        syscall

Here we are accessing msg directly without GOT and things seem to work fine (the string is printed twice).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions