我實際上編寫了一個共享對象加載器,它在cortex-m4控制器上加載了gcc創建的共享對象(ELF)。加載,依賴關係解析和重定位等工作正常。但共享對象在.dynsym部分有一些奇怪的符號,我不知道該如何處理。Cortex-M4上的共享對象dynsym部分中的奇怪符號
readelf --dyn-SYM libfoo.so
Num: Wert Size Typ Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 000005c8 0 SECTION LOCAL DEFAULT 8
2: 00000874 0 SECTION LOCAL DEFAULT 16
3: 00000000 0 NOTYPE GLOBAL DEFAULT UND printf
4: 0000082d 32 FUNC GLOBAL DEFAULT 12 foo3
5: 0000087c 0 NOTYPE GLOBAL DEFAULT 18 __bss_start__
6: 00000000 0 NOTYPE GLOBAL DEFAULT UND __libc_init_array
7: 00000728 0 NOTYPE GLOBAL DEFAULT 12 _mainCRTStartup
8: 000005c8 0 FUNC GLOBAL DEFAULT 8 _init
9: 00000000 0 NOTYPE GLOBAL DEFAULT UND __libc_fini_array
10: 00000000 0 NOTYPE WEAK DEFAULT UND __deregister_frame_info
11: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
12: 00000898 0 NOTYPE GLOBAL DEFAULT 18 __bss_end__
13: 00000728 0 NOTYPE GLOBAL DEFAULT 12 _start
14: 00000000 0 NOTYPE WEAK DEFAULT UND software_init_hook
15: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab
16: 00000000 0 NOTYPE GLOBAL DEFAULT UND memset
17: 00000000 0 NOTYPE GLOBAL DEFAULT UND main
18: 00000000 0 NOTYPE WEAK DEFAULT UND hardware_init_hook
19: 000005e0 0 FUNC GLOBAL DEFAULT 9 _fini
20: 00000000 0 NOTYPE GLOBAL DEFAULT UND atexit
21: 00000000 0 NOTYPE WEAK DEFAULT UND __stack
22: 00000000 0 NOTYPE GLOBAL DEFAULT UND exit
23: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
24: 00000000 0 NOTYPE WEAK DEFAULT UND __register_frame_info
爲什麼共享對象需要一個主功能和對__libc_init_array函數的引用?特別是__libc_init_array的符號對我來說沒有意義......這個函數正常地初始化__preinit_array,_init和__init_array,但是這個工作應該由我的加載程序完成,而不是由對象本身完成,或者我錯了?
是否有任何地方一步一步的文檔如何初始化加載的共享對象及其所有依賴關係?
這是這樣的,我如何建立我的共享對象:
gcc -std=gnu99 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -ffunction-sections -fdata-sections -mfloat-abi=soft -mcpu=cortex-m4 -mthumb -mlong-calls -Os -g -c -fPIC -o foo.o foo.c
gcc -shared -fPIC -Wl,-soname,libfoo.so -T./shared.ld -o libfoo.so foo.o
只是有一個問題:如果沒有-mlong通話選項,我的gcc生成.plt節無效操作..我做錯了什麼?
編輯: 我foo.c的是檸簡單:
#include <stdio.h>
#include <string.h>
void foo3 (void)
{
printf("Hello from shared-object");
}
這是我shared.ld:
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SECTIONS
{
.interp : { *(.interp) }
.note.ABI-tag : { *(.note.ABI-tag) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.dynamic : { *(.dynamic) }
.hash : { *(.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.rel.dyn : { *(.rel.dyn) }
.rela.dyn : { *(.rela.dyn) }
.rel.plt : { *(.rel.plt) }
.rela.plt : { *(.rela.plt) }
.plt : { *(.plt) }
.got : { *(.got.plt) *(.got) }
.init ALIGN(32/8) :
{
KEEP (*(.init))
}
.fini ALIGN(32/8) :
{
KEEP (*(.fini))
}
.preinit_array ALIGN(32/8) :
{
PROVIDE(__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE(__preinit_array_end = .);
}
.init_array ALIGN(32/8) :
{
PROVIDE(__init_array_start = .);
KEEP (*(.init_array*))
PROVIDE(__init_array_end = .);
}
.fini_array ALIGN(32/8) :
{
PROVIDE(__fini_array_start = .);
KEEP (*(.fini_array*))
PROVIDE(__fini_array_end = .);
}
.text ALIGN(32/8) :
{
*(.text .text.*)
}
.rodata ALIGN(32/8) :
{
*(.rodata .rodata.*)
}
.data ALIGN(32/8) :
{
*(.data .data.*)
}
.bss ALIGN(32/8) :
{
PROVIDE(__bss_start__ = .);
*(.bss .bss.*)
*(COMMON)
PROVIDE(__bss_end__ = .);
}
}
注意:的printf至基準設置到linktime的主程序的printf - 僅用於測試目的。
感謝您的幫助:-)
如果您還爲foo.c和shared.ld提供了(修剪)代碼,它會有所幫助。 – yugr
「如果沒有-mlong-calls選項,我的gcc會在.plt部分生成無效的操作碼......我做錯了什麼?」 - 如果在最近的binutils上覆制,你應該[提交一個bug](https://sourceware.org/bugzilla/)。 – yugr
我不知道你的工具鏈是否有能力建立共享庫。你可以檢查http://stackoverflow.com/questions/18586291/could-not-build-shared-library-using-toolchain-arm-uclinuxeabi中的建議嗎? – yugr