1
A
回答
3
我不確定「已加載」事件,但是如果您使用的是gcc
,則可能會發現constructor
屬性有用。舉個例子:
testlib.c: 的#include
void testing(void) __attribute__((constructor));
void testing(void)
{
printf("It worked!\n");
}
hworld.c:
#include <stdio.h>
int main(void)
{
printf("Hello world!\n");
return 0;
}
$ gcc -o hworld hworld.c
$ gcc -shared -fPIC -o testlib.so testlib.c
$ export LD_PRELOAD=./testlib.so
$ ./hworld
It worked!
Hello world!
的constructor屬性意味着該函數應該main()
之前執行。或者,如果您使用的是C++,則可以創建一個類的靜態全局實例,該實例的構造函數進行初始化,這將實現與使用constructor
相同的效果。
相關問題
- 1. 由LD_PRELOAD指定的lib無法加載
- 2. LD_PRELOAD不預加載所有符號
- 3. 圖書館將只與LD_PRELOAD加載
- 4. 如何使靜態鏈接ELF文件加載LD_PRELOAD .so
- 5. IComponent加載事件
- 6. jQuery加載事件
- 7. 帶文件功能的LD_PRELOAD
- 8. JQuery的加載事件
- 9. Grid的加載事件
- 10. Jquery單擊事件以加載事件
- 11. AIX上的LD_PRELOAD
- 12. LD_PRELOAD與幾個源文件
- 13. jquery預加載事件
- 14. Javascript文檔加載事件
- 15. iframe中加載事件
- 16. iframe加載事件後?
- 17. 在程序加載事件..?
- 18. GoogleMapAPIv3街景加載事件
- 19. HTML5 Appcache加載事件
- 20. 在datepicker中加載事件
- 21. UIWebView完成加載事件
- 22. Angularjs圖像加載事件
- 23. 分析WPF加載事件
- 24. FormClosing()事件加載兩次
- 25. Angular2懶加載事件
- 26. JQuery UI加載事件?
- 27. 加載項SelectChange()事件
- 28. 模板加載事件
- 29. ReportViewerForMvc事件報告加載
- 30. 加載事件問題
謝謝!但我注意到這個構造函數多次調用了一次,你能幫助如何修復它嗎?謝謝! – user1262425
@ user1262425你可以更新一個你看到它不止一次被調用的例子嗎? Afaik應該只在'main()'運行之前調用一次。 – FatalError