PATCH: new linker option for shared library COMDAT optimization

Alan Modra amodra@gmail.com
Mon Feb 20 23:40:00 GMT 2012


On Fri, Feb 17, 2012 at 11:41:03AM -0700, Sandra Loosemore wrote:
> The slight wrinkle in this scheme is that the ELF specification
> defines COMDAT groups as an attribute of relocatable files only, not
> shared objects.  So we cannot say definitely that a shared object
> provides a named COMDAT group.  The expedient hack I've adopted is
> to consider that a shared library provides a COMDAT group if it
> provides weak definitions for all symbols defined in sections that
> make up the group.

I wondered how robust this will prove to be.  So I wrote a patch for
nm to print out symbols defined in linkonce or comdat group sections,
and had a look at a powerpc-linux libstdc++ build.

$ find . -name \*.o | xargs ~/build/ppc/bin/binutils/nm-new -g -L | sed -n -e 's,[^ ][^ ]* [^ ][^ ]* ,,p' | sort | uniq > /tmp/xxx
$ nm -D src/.libs/libstdc++.so.6 | sed -n -e 's,[^ ][^ ]* [^ ][^ ]* ,,p' | sort | uniq > /tmp/yyy
$ diff -u /tmp/xxx /tmp/yyy
[snip]
-DW.ref.__gxx_personality_v0
-DW.ref._ZTIN10__cxxabiv115__forced_unwindE
-DW.ref._ZTISt9bad_alloc
-DW.ref._ZTISt9exception
-_X_ZNKSbIwSt11char_traitsIwESaIwEE11_M_disjunctEPKw
-_X_ZNKSbIwSt11char_traitsIwESaIwEE15_M_check_lengthEjjPKc
-_X_ZNKSs11_M_disjunctEPKc
-_X_ZNKSs15_M_check_lengthEjjPKc
-_X_ZNKSt13basic_fstreamIcSt11char_traitsIcEE7is_openEv
[snip]
$ diff -u /tmp/xxx /tmp/yyy | grep '^-[^-]' | wc -l
516
$ wc -l /tmp/xxx
3138 /tmp/xxx

That's rather a lot of missing symbols.  I think for this to work you
need another linker option to export all global symbols defined in
comdat sections.  Then, given that you will need to build shared
libraries differently, it would be a much better idea to mark them as
supporting shared-comdat, perhaps by exporting each comdat signature
symbol.  If you did that, you could probably dispense with all the
code you've written to match symbols..

-- 
Alan Modra
Australia Development Lab, IBM
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nm.diff
Type: text/x-diff
Size: 2981 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20120220/5e111952/attachment.bin>


More information about the Binutils mailing list