由於某些原因,我想強制PLT部分輸入一些條目。我已經設法爲一些條目做到這一點,但是某些功能從未插入到PLT中。PLT部分中的強制條目
因此,可以說,我有main.c
:
int main(){
// some code
strcmp(a,b); //suppose a, b strings
// more code
// suppose that result of strcmp is used, so it won't be optimised away
}
和help.c
:
// declaration
void forceplt() __attribute__((__used__));
// definition
void forceplt(){
abs(-1);
__aeabi_dadd(0, 0);
}
然後,我編譯和鏈接以上兩個重定位目標,爲可執行的對象。爲確保abs
和dadd
函數將保留在PLT部分中,我使用-O0
編譯helper.o
。 main.o
可以編譯一個更高的級別,可以說'-O1'。
對於可執行對象,我期望看到所有3個函數的條目:strcmp
,abs
和dadd
。然而,這種情況並非如此。
我在這裏錯過了什麼嗎? 鏈接器是否有可能遺漏某些內容,因爲它發現它們從未被調用?儘管使用O0作爲助手,並使用了forceplt函數的屬性?
幫我做一個適當的慶祝..十。百萬。問題!
乾杯!