This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Treat .gnu.linkonce sections as COMDAT
AbandonedPublic

Authored by grimar on Aug 10 2017, 4:19 AM.

Details

Summary

This is request from PR31586 comment.

.gnu.linkonce were invented before regular COMDAT sections
and should work in the same way (http://www.airs.com/blog/archives/52).

Previously we dropped such sections.
Patch makes them COMDATS.

It based on logic of https://reviews.llvm.org/D28430?id=83485 which
was changed in later diff.

Diff Detail

Event Timeline

grimar created this revision.Aug 10 2017, 4:19 AM
grimar added a reviewer: pcc.Aug 10 2017, 4:19 AM
ruiu edited edge metadata.Aug 11 2017, 8:23 AM

If I understand https://bugs.llvm.org/show_bug.cgi?id=31586 correctly, this is adding more code to a hack that will be removed in near future. I don't think we should do that unless it is absolutely necessary, especially because this patch touches not a single place but many places in the source code.

@ruiu, my understanding was that this change would make it less of a hack. It's not terribly difficult to work around as it stands though (you can define your own version of the symbol which got dropped, and in practice that symbol tends to only contain a few instructions); it would be nicer to have the linker handle it, but it's understandable if you think this isn't worthwhile. Thanks for the attempt, @grimar!

grimar abandoned this revision.Aug 16 2017, 12:07 AM

Ok.

ruiu added inline comments.Aug 16 2017, 4:05 PM
ELF/InputFiles.cpp
496–502

".gnu.linkonce.t" is not the only ".gnu.linkonce" section. There are other sections such as ".gnu.linkonce.r". Why can you ignore them but only handle ".gnu.linkonce.t"? It seems something is missing.

grimar added inline comments.Aug 16 2017, 11:39 PM
ELF/InputFiles.cpp
496–502

In all descriptions I found it was said that we should expect
.gnu.linkonce.NAME or .gnu.linkonce.TYPE.NAME, for example:

(http://www.airs.com/blog/archives/52)
"Any section whose name starts with “.gnu.linkonce.” is a COMDAT section. The associated string is simply the section name itself. Thus the inline function f1 would be put into the section “.gnu.linkonce.f1”"

In that case all we would need here is to take the string NAME which follows last ..
But in real life situation is different and I did not find exact documentation about naming.

gold linker has comment saying that for .gnu.linkonce.t.__i686.get_pc_thunk.bx
__i686.get_pc_thunk.bx should be used as function name. That corresponds
to documentation probably. But at the same time it says that for case of .gnu.linkonce.d.rel.ro.local
the name should not be rel.ro.local, but local. So we generally can not simply take whole
string following the last . for taking comdat group name.

And because this patch was a hack to fix exact user request, I decided to support case
that is simple, clear for me and enough for fixing request.

But anyways, this patch was abandoned, do you want to resurrect it ?