前提・実現したいこと
ラズベリーパイ3でのベアメタルプログラミングを勉強しています.
作成したELFファイル内で.textセクションが0x10000番地以降に置かれ,ELFファイルのサイズが大きくなってしまい困っています.そこで,以下の質問があります.
質問1.0x10000という値はどこから来ているのか?
質問2.その値をリンカスクリプト等で変えることができるのか?(.textセクションをプログラムヘッダテーブルの直後に置きたい)
ご教授いただければ幸いです.
該当のソースコード
使用しているリンカスクリプトは以下の通りです.
SECTIONS { . = 0x80000; .text : { *(.text) } .rodata : { *(.rodata) *(.rodata.*) } .data : { *(.data) } .bss : { . = ALIGN(16); __bss_start = .; *(.bss) *(COMMON) __bss_end = .; } _end = .; } __bss_size = (__bss_end - __bss_start)>>3;
試したこと
作成したELFファイルをreadelfコマンドで見ると,以下の出力が得られます.
ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: AArch64 Version: 0x1 Entry point address: 0x80000 Start of program headers: 64 (bytes into file) Start of section headers: 66856 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 1 Size of section headers: 64 (bytes) Number of section headers: 9 Section header string table index: 6 Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .text PROGBITS 0000000000080000 00010000 00000000000001d8 0000000000000000 AX 0 0 8 [ 2] .text.startup PROGBITS 00000000000801d8 000101d8 0000000000000028 0000000000000000 AX 0 0 8 [ 3] .rodata PROGBITS 0000000000080200 00010200 0000000000000010 0000000000000001 AMS 0 0 8 [ 4] .bss NOBITS 0000000000080210 00010210 0000000000000000 0000000000000000 WA 0 0 1 [ 5] .comment PROGBITS 0000000000000000 00010210 0000000000000011 0000000000000001 MS 0 0 1 [ 6] .shstrtab STRTAB 0000000000000000 00010221 0000000000000045 0000000000000000 0 0 1 [ 7] .symtab SYMTAB 0000000000000000 00010268 0000000000000240 0000000000000018 8 14 8 [ 8] .strtab STRTAB 0000000000000000 000104a8 0000000000000079 0000000000000000 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) There are no section groups in this file. Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000010000 0x0000000000080000 0x0000000000080000 0x0000000000000210 0x0000000000000210 RWE 10000 Section to Segment mapping: Segment Sections... 00 .text .text.startup .rodata There is no dynamic section in this file. There are no relocations in this file. The decoding of unwind sections for machine type AArch64 is not currently supported.
バイナリエディタでELFファイルを見てみると,
アドレス(オフセット) | |
---|---|
0x0-0x3f | ELFヘッダ |
0x40-0x77 | プログラムヘッダ |
0x78-0xffff | 分からない何か(全て0) |
0x10000以降 | .textセクションなど |
のような構造になっていました.
補足情報(FW/ツールのバージョンなど)
gcc-5.2.0とbinutils2.25をダウンロードし,aarch64-elfをターゲットとしてビルドしました.
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。