views:

124

answers:

2

I was bored and playing around with various options to gcc to see what size binaries I could produce.

I found a -s flag in ld64 that is supposedly supposed to not include symbol table information in an executable. The manpage for ld64 says the flag is ignored.

The manpage for gcc says it's a linker option(which to me implies it means it will just enable the -s flag on ld64 when it's invoked) and mentions nothing about being ignored.

It's not seeming to be ignored, though...

me@dinosaurhunter ~/bin/c> cat small.c 
int main(void) { return 1; }
me@dinosaurhunter ~/bin/c> gcc -Wall small.c -o small
me@dinosaurhunter ~/bin/c> wc -c small
   12564 small
me@dinosaurhunter ~/bin/c> gcc -Wall -s small.c -o small
ld64: warning: option -s is obsolete and being ignored
me@dinosaurhunter ~/bin/c> wc -c small
   12468 small

If the flag is obsolete and being ignored -- why do the size of the binaries differ?

+3  A: 

Not having access to the ld sourcecode right now, I can't answer about the warning.

I can tell you why the binaries have different size -- use nm.

Here's without the '-s':

0000000100001040 D _NXArgc
0000000100001048 D _NXArgv
                 U ___keymgr_dwarf2_register_sections
0000000100001058 D ___progname
                 U __cthread_init_routine
0000000100000e68 t __dyld_func_lookup
0000000100000000 A __mh_execute_header
0000000100000d6a t __start
                 U _atexit
0000000100001050 D _environ
                 U _errno
                 U _exit
                 U _mach_init_routine
0000000100000e6e T _main
0000000100000e54 t dyld_stub_binding_helper
0000000100000d48 T start

With the '-s' I see that the dyld_stub_binding_helper section is missing.

Google says dyld_stub_binding_helper is a glue function that assists the dynamic linker in lazily binding an external function.

Geoff Hutchison
Interesting! It's curious that it says it's being ignored when it clearly isn't. I wonder if a bug report should be filed?
ashgromnies
+2  A: 

See the source:

   else if ( strcmp(arg, "-s") == 0 ) {
    warnObsolete(arg);
    fLocalSymbolHandling = kLocalSymbolsNone;
    fReaderOptions.fDebugInfoStripping = ObjectFile::ReaderOptions::kDebugInfoNone;
   }

The bug appears to be in the error message and man page, as a binary built with -s still works. (Nearly all the other uses of warnObsolete appear to match the error message.) Probably worth a trip to bugreport.apple.com and a post to one of the Darwin lists, depending on your curiosity.

Nicholas Riley