Address of (&) not returning correct address
Posted: Mon Jul 24, 2023 12:36 pm
I had basic setup on 32 bit kernel setup, things worked fine there. Now when I try to do same on 64 bit mode, I am facing weird issue.
Basically whenever I am trying to print string, & is not returning correct address. Printing individual chars works fine, or if it pass address as obtained from objdump.
objdump results for ro data
Contents of section .rodata:
10020d 48656c6c 6f0a00 Hello..
printing address of string (using gdb) yield 0x1022b8. This is what gets passed if I call my write_string("Hello"...) function.
if I pass write_string((char*) 10020d, ...) it works fine.
linker configuration:
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(start)
SECTIONS
{
. = 1M;
.text BLOCK(128) : ALIGN(32)
{
*(.multiboot)
*(.text)
}
.rodata : { *(.rodata) }
.data : { *(.data) }
.bss : { *(.bss) }
}
flags:
CFLAGS = -m64 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror -g -c
LDFLAGS = -T link.ld -melf_x86_64
AS = nasm
ASFLAGS = -f elf64
Not sure how I am supposed to debug this. Any pointers will help.
Basically whenever I am trying to print string, & is not returning correct address. Printing individual chars works fine, or if it pass address as obtained from objdump.
objdump results for ro data
Contents of section .rodata:
10020d 48656c6c 6f0a00 Hello..
printing address of string (using gdb) yield 0x1022b8. This is what gets passed if I call my write_string("Hello"...) function.
if I pass write_string((char*) 10020d, ...) it works fine.
linker configuration:
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(start)
SECTIONS
{
. = 1M;
.text BLOCK(128) : ALIGN(32)
{
*(.multiboot)
*(.text)
}
.rodata : { *(.rodata) }
.data : { *(.data) }
.bss : { *(.bss) }
}
flags:
CFLAGS = -m64 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror -g -c
LDFLAGS = -T link.ld -melf_x86_64
AS = nasm
ASFLAGS = -f elf64
Not sure how I am supposed to debug this. Any pointers will help.