मैं अपने संकलित C++ बाइनरी से सभी अप्रयुक्त प्रतीकों को हटाना चाहता हूं। मैं इस देखा था, जो जीसीसी का उपयोग कर एक सिंहावलोकन देता है, जो toolchain मैं उपयोग कर रहा हूँ है: How to remove unused C/C++ symbols with GCC and ld?लिंकर विकल्प
हालांकि, अपने सिस्टम पर, जोड़ने विकल्प (-Wl,--gc-sections
) को अस्वीकार कर दिया गया है:
$ gcc -fdata-sections -ffunction-sections a.c -o a.o -Wl,--gc-sections
ld: fatal: unrecognized option '--'
ld: fatal: use the -z help option for usage information
collect2: error: ld returned 1 exit status
मैं बीमारियों पर चल रहा है, जो जीसीसी 4.7 के साथ सोलारिस का एक (अपेक्षाकृत) हालिया कांटा है। किसी को भी पता है कि यहां उपयोग करने के लिए सही लिंकर विकल्प क्या है?
संपादित करें: खोज आदमी पृष्ठों और अधिक बारीकी से कर दिया "-zignore":
-z ignore | record
Ignores, or records, dynamic dependencies that are not
referenced as part of the link-edit. Ignores, or
records, unreferenced ELF sections from the relocatable
objects that are read as part of the link-edit. By
default, -z record is in effect.
If an ELF section is ignored, the section is eliminated
from the output file being generated. A section is
ignored when three conditions are true. The eliminated
section must contribute to an allocatable segment. The
eliminated section must provide no global symbols. No
other section from any object that contributes to the
link-edit, must reference an eliminated section.
हालांकि निम्न क्रम अभी भी ELF अनुभाग .text.FUNCTION
में FUNCTION_SHOULD_BE_REMOVED
कहते हैं:
$ cat a.c
int main() {
return 0;
}
$ cat b.c
int FUNCTION_SHOULD_BE_REMOVED() {
return 0;
}
$ gcc -fdata-sections -ffunction-sections -c a.c -Wl,-zignore
$ gcc -fdata-sections -ffunction-sections -c b.c -Wl,-zignore
$ gcc -fdata-sections -ffunction-sections a.o b.o -Wl,-zignore
$ elfdump -s a.out # I removed a lot of output for brevity
Symbol Table Section: .dynsym
[2] 0x08050e72 0x0000000a FUNC GLOB D 1 .text.FUNCTION FUNCTION_SHOULD_BE_REMOVED
Symbol Table Section: .symtab
[71] 0x08050e72 0x0000000a FUNC GLOB D 0 .text.FUNCTION FUNCTION_SHOULD_BE_REMOVED
क्योंकि मैन पेज कहते हैं "कोई वैश्विक प्रतीक नहीं", मैंने फ़ंक्शन को "स्थैतिक" बनाने का प्रयास किया और इसका अंत परिणाम भी था।
ld संस्करण 2.23.52.0.1 (2013, CentOS 7.0) समर्थन शामिल नहीं है '-z ignore' दुर्भाग्य से। –