OSDev.org

The Place to Start for Operating System Developers
It is currently Mon May 20, 2024 8:28 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Getting an address (offset) of a segment (PIE)
PostPosted: Sun Dec 11, 2016 8:15 am 
Offline

Joined: Mon Nov 14, 2016 2:42 am
Posts: 11
Good day!

I'm trying to use PIE on ARM (STM32F4DISCOVERY, GCC ARM Embedded Toolchain).

Here is linker script:
Code:
MEMORY {
    rom (rx):  ORIGIN = 0x08000000, LENGTH = 1M
    ram (rw):  ORIGIN = 0x20000000, LENGTH = 128k
}

_vector_table_size = 0x400;
_stack_size = 2048;

SECTIONS {
    .vec : {
        KEEP(startup.o(vector_table))
        . = ALIGN(4);
    } > rom

    .text : {
        *(.text*)
    } > rom

    .rodata : {
        *(.rodata*)
    } > rom

    .bss (NOLOAD) : {
        *(.bss*)
        . = ALIGN(4);
    } > ram

    .data : {
        *(.data*)
        . = ALIGN(4);
    } > ram AT > rom

    .stack (NOLOAD) : {
        _sstack = .;
        . = . + _stack_size;
        . = ALIGN(4);
        _estack = .;
    } > ram
}


Here is vector table initialization:
Code:
__attribute__ (( noinline )) void start void() { }

__attribute__ (( section("vector_table") )) static uint32_t *vectors[] = {
    (uint32_t *) &_estack,
    (uint32_t *) start,
    <...>
};


Without PIE options, I have:
Code:
(gdb) print *(uint32_t*)0x8000000
0x20005000

(gdb) print *(uint32_t*)0x8000004
0x8000d39

(gdb) print &_estack
0x20005000


With PIE options
Code:
CFLAGS += -fpie -msingle-pic-base -mpic-register=r9 -mno-pic-data-is-text-relative
LDFLAGS += -pie

I have:
Code:
(gdb) print $r9
0x8004400

(gdb) print *(uint32_t*)0x8000000
0x0

(gdb) print *(uint32_t*)0x8000004
0x8000d39

(gdb) print &_estack
0x20005000


Help me, please, to understand:
  • Why element 0 (start) initialized with address, but element 1 (&_estack) with 0x0? What's the difference between (pointer to) uint32_t and (pointer to) function here?
  • Why element 0 initialized by 0x0 but print &_estack prints a value?
  • Is there some way to get it working? So get offset/etc. of .stack segment into vectors[0] at compile/linking time?
  • Why (even with PIE) start initialized with absolute address (0x8004d39) but not offset by GOT/PLT? (btw, GOT or PLT?)

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 37 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group