[分享] ELFsh 使用範例

看板CompilerDev作者 (影斯作業系統)時間5年前 (2020/06/08 16:27), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
早期的 forth image 都沒有 symbol table,不易用 gdb 除錯, 所以可以用 elfsh 工具增加這項內容。 gforth Smake.f 會造出執行檔 sforth,把函式名字和位置列印出來, 之後就可以輸出有 symbol table 的 sforth.new 執行檔。 // http://elfsh.asgardlabs.org/ // http://www.eresi-project.org/ // https://github.com/thorkill/eresi // ** symtab_extend.c for elfsh testsuite #include "libelfsh.h" #define INPUT_FILE "./sforth" #define OUTPUT_FILE "./sforth.new" elfshobj_t *file; int linkcode (char *name, int addr) { int ret; elfsh_Sym sym; // name = "SEARCH-WORDLIST"; // sym = elfsh_create_symbol(addr, 21, STT_FUNC, 0, 0, 1); printf ("name is %s, addr 0x%x \n", name, addr); sym = elfsh_create_symbol(addr, 42, 0, 0, 0, 1); ret = elfsh_insert_symbol(file->secthash[ELFSH_SECTION_SYMTAB], &sym, name); } int main(int argc, char **argv) { int ret; elfsh_Sym sym; // ... sym = elfsh_create_symbol(0x11152, 21, STT_FUNC, 0, 0, 1); ret = elfsh_insert_symbol(file->secthash[ELFSH_SECTION_SYMTAB], &sym, name); while (gets(buf)) { if (2 == sscanf(buf, "linkcode %s 0x%x", buf2, &addr)) { linkcode(buf2, addr); } } ret = elfsh_save_obj(file, buf2); printf("Relinking *%s* \n", ret ? "Error" : "OK"); } sforth4addr.txt /* gforth Smake.f ;*/ linkcode MY_COLD 0x10000 linkcode E820 0x10024 linkcode AH88 0x10043 linkcode SYSCALL0 0x1004B linkcode SYSCALL1 0x1004E linkcode SYSCALL2 0x10056 linkcode SYSCALL3 0x10061 linkcode SYSCALL4 0x1006F linkcode SYSCALL5 0x10082 ... -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.43.77.156 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/CompilerDev/M.1591604848.A.CDC.html
文章代碼(AID): #1UtVPmpS (CompilerDev)