溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

android如何編譯出帶符號表的.so庫

發(fā)布時間:2020-07-29 12:29:51 來源:網(wǎng)絡(luò) 閱讀:3499 作者:GaoNeil 欄目:移動開發(fā)

android如何編譯出帶符號表的.so庫

關(guān)于這個問題,其實(shí)編譯器帶-g就會有調(diào)試信息。這是gcc相關(guān)的。
默認(rèn)其實(shí)android編譯的就是帶符號表的,只是在strip掉了。

例如下面的操作:
/$ find . | grep libext2_e2p.so
./obj/SHARED_LIBRARIES/libext2_e2p_intermediates/LINKED/libext2_e2p.so
./obj/lib/libext2_e2p.so
./symbols/system/lib64/libext2_e2p.so
./symbols/system/lib/libext2_e2p.so
./obj_arm/SHARED_LIBRARIES/libext2_e2p_intermediates/LINKED/libext2_e2p.so
./obj_arm/lib/libext2_e2p.so
./system/lib64/libext2_e2p.so
./system/lib/libext2_e2p.so
/$ ls -l ./obj/SHARED_LIBRARIES/libext2_e2p_intermediates/LINKED/libext2_e2p.so
-rwxrwxr-x 1 neil neil 109808 12月 19 21:20 ./obj/SHARED_LIBRARIES/libext2_e2p_intermediates/LINKED/libext2_e2p.so
/$ ls -l ./obj/lib/libext2_e2p.so
-rwxrwxr-x 1 neil neil 31448 12月 19 21:25 ./obj/lib/libext2_e2p.so
/$ ls -l ./symbols/system/lib64/libext2_e2p.so
-rwxrwxr-x 1 neil neil 109808 12月 19 21:24 ./symbols/system/lib64/libext2_e2p.so
/$ ls -l ./symbols/system/lib/libext2_e2p.so
-rwxrwxr-x 1 neil neil 86172 12月 19 21:20 ./symbols/system/lib/libext2_e2p.so
/$ ls -l ./system/lib64/libext2_e2p.so
-rwxrwxr-x 1 neil neil 31448 12月 19 21:27 ./system/lib64/libext2_e2p.so
/$ ls -l ./system/lib/libext2_e2p.so
-rwxrwxr-x 1 neil neil 22444 12月 19 21:25 ./system/lib/libext2_e2p.so

從上面可以看出,stip前和strip后,文件大小不同。
由于strip前后,elf文件的其他section段的內(nèi)容沒有變化,只是刪除了symbol和debug的section,所以程序跑strip后的elf文件,調(diào)試時使用strip前有符號表的elf文件,不會出問題,因?yàn)樗麄兊拇a和數(shù)據(jù)部分相同。

/$ readelf -S ./system/lib/libext2_e2p.so
There are 21 section headers, starting at offset 0x5464:

Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 00000134 000134 000013 00 A 0 0 1
[ 2] .dynsym DYNSYM 00000148 000148 0004b0 10 A 3 1 4
[ 3] .dynstr STRTAB 000005f8 0005f8 000381 00 A 0 0 1
[ 4] .hash HASH 0000097c 00097c 000240 04 A 2 0 4
[ 5] .rel.dyn REL 00000bbc 000bbc 0002e8 08 A 2 0 4
[ 6] .rel.plt REL 00000ea4 000ea4 000180 08 A 2 7 4
[ 7] .plt PROGBITS 00001024 001024 000254 00 AX 0 0 4
[ 8] .text PROGBITS 00001278 001278 001da0 00 AX 0 0 4
[ 9] .ARM.exidx ARM_EXIDX 00003018 003018 000108 08 AL 8 0 4
[10] .rodata PROGBITS 00003120 003120 000fb8 00 A 0 0 4
[11] .ARM.extab PROGBITS 000040d8 0040d8 00000c 00 A 0 0 4
[12] .fini_array FINI_ARRAY 00005e60 004e60 000004 00 WA 0 0 4
[13] .dynamic DYNAMIC 00005e64 004e64 0000c8 08 WA 3 0 4
[14] .got PROGBITS 00005f2c 004f2c 0000d4 00 WA 0 0 4
[15] .data PROGBITS 00006000 005000 000344 00 WA 0 0 4
[16] .bss NOBITS 00006344 005344 0001f0 00 WA 0 0 4
[17] .comment PROGBITS 00000000 005344 000010 01 MS 0 0 1
[18] .note.gnu.gold-ve NOTE 00000000 005354 00001c 00 0 0 4
[19] .ARM.attributes ARM_ATTRIBUTES 00000000 005370 000040 00 0 0 1
[20] .shstrtab STRTAB 00000000 0053b0 0000b4 00 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)
/$ readelf -S ./symbols/system/lib/libext2_e2p.so
There are 31 section headers, starting at offset 0x14bc4:

可以看到上面的文件沒有symbol的section

Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 00000134 000134 000013 00 A 0 0 1
[ 2] .dynsym DYNSYM 00000148 000148 0004b0 10 A 3 1 4
[ 3] .dynstr STRTAB 000005f8 0005f8 000381 00 A 0 0 1
[ 4] .hash HASH 0000097c 00097c 000240 04 A 2 0 4
[ 5] .rel.dyn REL 00000bbc 000bbc 0002e8 08 A 2 0 4
[ 6] .rel.plt REL 00000ea4 000ea4 000180 08 A 2 0 4
[ 7] .plt PROGBITS 00001024 001024 000254 00 AX 0 0 4
[ 8] .text PROGBITS 00001278 001278 001da0 00 AX 0 0 4
[ 9] .ARM.exidx ARM_EXIDX 00003018 003018 000108 08 AL 8 0 4
[10] .rodata PROGBITS 00003120 003120 000fb8 00 A 0 0 4
[11] .ARM.extab PROGBITS 000040d8 0040d8 00000c 00 A 0 0 4
[12] .fini_array FINI_ARRAY 00005e60 004e60 000004 00 WA 0 0 4
[13] .dynamic DYNAMIC 00005e64 004e64 0000c8 08 WA 3 0 4
[14] .got PROGBITS 00005f2c 004f2c 0000d4 00 WA 0 0 4
[15] .data PROGBITS 00006000 005000 000344 00 WA 0 0 4
[16] .bss NOBITS 00006344 005344 0001f0 00 WA 0 0 4
[17] .comment PROGBITS 00000000 005344 000010 01 MS 0 0 1
[18] .debug_info PROGBITS 00000000 005354 005b3f 00 0 0 1
[19] .debug_abbrev PROGBITS 00000000 00ae93 001daf 00 0 0 1
[20] .debug_loc PROGBITS 00000000 00cc42 002d90 00 0 0 1
[21] .debug_aranges PROGBITS 00000000 00f9d2 0002e8 00 0 0 1
[22] .debug_ranges PROGBITS 00000000 00fcba 000438 00 0 0 1
[23] .debug_line PROGBITS 00000000 0100f2 001aa6 00 0 0 1
[24] .debug_str PROGBITS 00000000 011b98 001432 01 MS 0 0 1
[25] .debug_frame PROGBITS 00000000 012fcc 000514 00 0 0 4
[26] .note.gnu.gold-ve NOTE 00000000 0134e0 00001c 00 0 0 4
[27] .ARM.attributes ARM_ATTRIBUTES 00000000 0134fc 000040 00 0 0 1
[28] .symtab SYMTAB 00000000 01353c 001030 10 29 185 4
[29] .strtab STRTAB 00000000 01456c 00052e 00 0 0 1
[30] .shstrtab STRTAB 00000000 014a9a 00012a 00 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)
/$

可以看到上面的文件有symbol的section

可以看到,symbol/system目錄的.so庫文件大小比system目錄的大。因?yàn)楹蟹柋怼?/p>

關(guān)于ELF文件的介紹和linux中的加載原理和實(shí)現(xiàn),歡迎觀看我的視頻:
https://edu.51cto.com/course/17147.html

關(guān)于具體的寫linux驅(qū)動的方法、技巧和注意事項,歡迎觀看我的《如何編寫linux設(shè)備驅(qū)動》的視頻:
https://edu.51cto.com/course/17132.html

另外我的相關(guān)培訓(xùn)視頻請看:
歡迎觀看我發(fā)布的各個課程: https://edu.51cto.com/lecturer/8896847.html

另外我的免費(fèi)的linux各種驅(qū)動開發(fā)課程如下:
https://edu.51cto.com/course/17138.html

我的新的更多優(yōu)惠的打包課程鏈接如下:
https://edu.51cto.com/sd/0a9d4

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI