Andes Workshop http://forum.andestech.com/ |
|
如何將內建library的function固定在某些section裡 http://forum.andestech.com/viewtopic.php?f=25&t=685 |
Page 1 of 1 |
Author: | cindy [ Wed Mar 13, 2013 2:59 pm ] | ||
Post subject: | 如何將內建library的function固定在某些section裡 | ||
自己寫的程式,如果想訂在某個section上, 可以用下面的語法。 viewtopic.php?f=16&t=132 但是對於library,例如memcpy等function,不能用這個方法。 因為它在編譯時即指定好section。 所以我們要知道function所屬的section或是所屬的.o檔案。 ------------------------------------------------------------------ library在這邊 nds32le-elf/libc/newlib/usr/lib/libc.a 用readelf -Ss 看section和symbol的話, (即為readelf -Ss libc.a) 可以看出 memcpy和abs是有function sections的, (strcpy沒有) File: ./libc.a(lib_a-abs.o) [ 8] .text.memcpy PROGBITS 00000000 000618 000088 00 AX 0 0 4 8: 00000000 136 FUNC GLOBAL DEFAULT 8 memcpy File: ./libc.a(lib_a-strcpy.o) [ 1] .text PROGBITS 00000000 000034 00003c 00 AX 0 0 4 5: 00000000 60 FUNC GLOBAL DEFAULT 1 strcpy File: ./libc.a(lib_a-memcpy.o) [ 8] .text.abs PROGBITS 00000000 000614 000008 00 AX 0 0 4 8: 00000000 8 FUNC GLOBAL DEFAULT 8 abs 有section的, 可以用 * (.text.memcpy) 來拉 --------------------------------------------------------------------- 如果是mculib的話, 因為本來就是分檔寫的, 所以沒有刻意寫成不同section, newlib是標準的C code, 才有用-ffunction-sections分隔 File: libc.a(lib_a-memcpy.o) There are 11 section headers, starting at offset 0x12c: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 000034 000088 00 AX 0 0 4 <-- section 1 是.text [ 2] .rela.text RELA 00000000 00035c 0000a8 0c 9 1 4 [ 3] .rel.text REL 00000000 000404 000000 08 9 1 4 [ 4] .data PROGBITS 00000000 0000bc 000000 00 WA 0 0 1 [ 5] .bss NOBITS 00000000 0000bc 000000 00 WA 0 0 1 [ 6] .mdebug.abi_nds32 PROGBITS 00000000 0000bc 000000 00 0 0 1 [ 7] .comment PROGBITS 00000000 0000bc 000019 00 0 0 1 [ 8] .shstrtab STRTAB 00000000 0000d5 000056 00 0 0 1 [ 9] .symtab SYMTAB 00000000 0002e4 000070 10 10 6 4 [10] .strtab STRTAB 00000000 000354 000008 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) Symbol table '.symtab' contains 7 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 SECTION LOCAL DEFAULT 1 2: 00000000 0 SECTION LOCAL DEFAULT 4 3: 00000000 0 SECTION LOCAL DEFAULT 5 4: 00000000 0 SECTION LOCAL DEFAULT 6 5: 00000000 0 SECTION LOCAL DEFAULT 7 6: 00000000 136 FUNC GLOBAL DEFAULT 1 memcpy <-- 在 section 1 -------------------------------------------------------------------- .text : { *libc.a:*memcpy.o (.text .text.*) * (.text .text.*) } 主要是只寫 libc.a 不夠, 因為他前面應該會有path, 所以使用 * 來match pattern 另外, 為了避免library內有修改檔名或section名, 建議後面也都用 wildcard pattern. 另外要注意, 先符合會先拉, 所以要注意順序. 例如這樣不行, 因為會被 * 先拉完 .text : { * (.text .text.*) *libc.a:*memcpy.o (.text .text.*) } http://sourceware.org/binutils/docs-2.2 ... -Wildcards ``a file name matches more than one wildcard pattern, or if a file name appears explicitly and is also matched by a wildcard pattern, the linker will use the first match in the linker script.'' -------------------------------------------------------------- 注意!比較新的compiler才有分成各section或是分檔寫。 附件是一個example。
|
Author: | ianfeng [ Wed May 07, 2014 10:48 am ] |
Post subject: | Re: 如何將內建library的function固定在某些section裡 |
Attachment: 如附件”demo-printf.zip”的demo。 它將libc.a中的*printf.o跟*atoi.o放到特定的section0中。 先在nds32.sag中新增section0, 使用Linker script generation "nds_ldsag.exe" utility 產生nds32.ld檔案後, 手動修改nds32.ld檔,將*printf.o跟*atoi.o放到section0中。 Code: .text : {
*(EXCLUDE_FILE (*libc.a:*atoi.o) .text .stub EXCLUDE_FILE (*libc.a:*printf.o) .text.* .gnu.linkonce.t.*) KEEP(*(.text.*personality*)) *(.gnu.warning) . = ALIGN(4); } ……………… .section0 : AT(LOADADDR (.bss) + SIZEOF (.bss)) { *libc.a:*printf.o (.text .text.*) *atoi.o *(.section0) } |
Page 1 of 1 | All times are UTC + 8 hours [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |