Linker to ignore unused dependencies

I would like to remove all unused characters from my compiled C ++ binary. I saw this giving an overview using gcc, which is the toolchain used: How to remove unused C / C ++ characters using GCC and ld?

However, on my system, the bind option ( -Wl,--gc-sections) is rejected:

$ 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

I work on lighting, which is the (relatively) recent Solaris plug, with GCC 4.7. Does anyone know which version of the correct linker to use here?


Edit: search for pages with a more detailed search for "-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.

However, the following sequence still places FUNCTION_SHOULD_BE_REMOVEDin the ELF section .text.FUNCTION:

$ 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

man- " ", "" .

+5
1

ld '-z ignore' , , . , :

gcc a.o b.o -Wl,-zignore

- .

gcc -Wl,-zignore a.o b.o

+8

All Articles