2011-05-07 15 views
5

चाहता हूं, मैं एक i686-elf क्रॉस-कंपाइलर का उपयोग कर सिग्विन में एक साझा लाइब्रेरी बनाने की कोशिश कर रहा हूं। कोड बहुत सरल है: सहीजीसीसी एक निष्पादन योग्य ईएलएफ फ़ाइल आउटपुट करता है जब मैं एक साझा लाइब्रेरी

i686-elf-gcc -fPIC -shared -nostdlib core.c -o libcore.so 

यह एक साझा वस्तु उत्पादन किया जाना चाहिए,:

int add(int a, int b) { 
    return a + b; 
} 

void _init() { 
    add(3, 4); 
} 

मैं निम्न आदेश के साथ संकलन कर रहा हूँ? लेकिन जीसीसी _start प्रतीक खोजने में सक्षम नहीं होने के बारे में एक चेतावनी आउटपुट करता है, जो एक्जिक्यूटिव के लिए प्रवेश बिंदु है, साझा वस्तुओं नहीं। इसके अलावा, readelf निम्नलिखित कहते हैं:

$ readelf -a libcore.so 
ELF Header: 
    Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
    ... 
    Type:        EXEC (Executable file) 
    ... 

क्या गलत हो रहा है?

उत्तर

2

क्या गलत हो रहा है यह अनिवार्य रूप से है कि आप i686-elf को लक्षित कर रहे हैं, और कोई भी उस लक्ष्य के लिए साझा लाइब्रेरीज़ नहीं बनाता है। -Wl,-shared आपको कुछ साझा करेगा जो साझा लाइब्रेरी के रूप में चिह्नित है, लेकिन आप एक नंगे धातु लक्ष्य पर साझा लाइब्रेरी को लोड करने की योजना कैसे बनाते हैं?

+0

कि महान काम किया है, धन्यवाद। अपने प्रश्न का उत्तर देने के लिए, मैं बूटलोडर पर काम कर रहा हूं जो स्थानांतरित ईएलएफ मॉड्यूल लोड करता है। –

0

मेरा मानना ​​है कि -shared नंगे धातु लक्ष्य पर एक नो-ऑप है (संकलक मानते हैं कि विकल्प निर्दिष्ट नहीं किया गया था) और इसलिए संकलक निष्पादन योग्य बनाता है। कमांड लाइन पर info gcc से:

'-shared' 
    Produce a shared object which can then be linked with other 
    objects to form an executable. Not all systems support this 
    option. For predictable results, you must also specify the same 
    set of options that were used to generate code ('-fpic', '-fPIC', 
    or model suboptions) when you specify this option.(1) 

... और फ़ुटनोट के लिए नीचे स्क्रॉल:

(1) On some systems, 'gcc -shared' needs to build supplementary stub 
    code for constructors to work. On multi-libbed systems, 'gcc -shared' 
    must select the correct support libraries to link against. Failing to 
    supply the correct flags may lead to subtle defects. Supplying them in 
    cases where they are not necessary is innocuous. 
संबंधित मुद्दे