链接器将部分移动到不应该的位置

时间:2015-12-24 23:46:03

标签: c linker kernel osdev

我的elf可执行文件有这个链接器脚本:

ENTRY(_start)

SECTIONS
{
    . = 0x500;

    .mboot BLOCK(4K) : ALIGN(4K)
    {
        *(.mboot)
    }

    . = 0x7E00;

    .ap_stack BLOCK(48K) : ALIGN(4K)
    {
        *(.ap_stack)
    }

    .mp_entry BLOCK(4K) : ALIGN(4K)
    {
        *(.mp_entry)
    }

    _mp_entry_end = .;

    . = 1M;

    .init BLOCK(4K) : ALIGN(4K)
    {
        *(.init)
    }

    _init_end = .;

    . =  0xFFFFFFFF80000000 + _init_end;

    .text : AT(ADDR(.text) - 0xFFFFFFFF80000000)
    {
        _code = .;
        *(.text)
        *(.rodata*)
        *(.stack)
        . = ALIGN(4096);
    }

   .data : AT(ADDR(.data) - 0xFFFFFFFF80000000)
   {
        _data = .;
        *(.data)
        . = ALIGN(4096);
   }

   .eh_frame : AT(ADDR(.eh_frame) - 0xFFFFFFFF80000000)
   {
       _ehframe = .;
       *(.eh_frame)
       . = ALIGN(4096);
   }

   .bss : AT(ADDR(.bss) - 0xFFFFFFFF80000000)
   {
       _bss = .;
       *(.bss)
       *(.rodata)
       *(COMMON)
       . = ALIGN(4096);
   }

   _end = .;

   /DISCARD/ :
   {
        *(.comment)
   }

}

哪个部分应该将.ap_stack放在物理/虚拟地址0x8000处。在集会中,我有:

[BITS 32]
section .ap_stack, nobits
align 16
ap_stack:
resb 0x48000
ap_stack_top:

这应该在那个时候留空,但是,如果我检查最后的精灵,我得到:

Idx Name          Size      VMA               LMA               File off  Algn
  0 .mboot        0000000c  0000000000001000  0000000000001000  00001000  2**12
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .mp_entry     00000001  000000000000c000  000000000000c000  00002000  2**12
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .init         00006054  0000000000100000  0000000000100000  00003000  2**12
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .text         0000efa0  ffffffff80106060  0000000000106060  00009060  2**5
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  4 .data         00001000  ffffffff80115000  0000000000115000  00018000  2**5
                  CONTENTS, ALLOC, LOAD, DATA
  5 .eh_frame     00002000  ffffffff80116000  0000000000116000  00019000  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .bss          00012000  ffffffff80118000  0000000000118000  0001b000  2**5
                  ALLOC
  7 .stack,       00005000  ffffffff8012a000  000000000012a000  0001b000  2**4
                  ALLOC, READONLY
  8 .ap_stack,    00048000  ffffffff8012f000  000000000012f000  0001b000  2**4
                  ALLOC, READONLY
  9 .debug_info   000097b8  0000000000000000  0000000000000000  0001b000  2**0
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_abbrev 0000210d  0000000000000000  0000000000000000  000247b8  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_aranges 00000560  0000000000000000  0000000000000000  000268c5  2**0
                  CONTENTS, READONLY, DEBUGGING
 12 .debug_line   000030e7  0000000000000000  0000000000000000  00026e25  2**0
                  CONTENTS, READONLY, DEBUGGING
 13 .debug_str    000026a5  0000000000000000  0000000000000000  00029f0c  2**0
                  CONTENTS, READONLY, DEBUGGING
 14 .debug_ranges 000001b0  0000000000000000  0000000000000000  0002c5b1  2**0
                  CONTENTS, READONLY, DEBUGGING

因为链接器已将我的ap_stack移动到堆栈,这绝对是我不想要的。我有什么原因以及如何阻止这种行为?

0 个答案:

没有答案