This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Fix case of using both --icf and --symbol-ordering-file together.
ClosedPublic

Authored by grimar on Feb 13 2018, 6:02 AM.

Details

Summary

Imagine that we have sections A, B, C, where A == C and
symbol ordering file containing symbols: symC, symB, symA

Previously because of ICF it was possible that final order would be
B, A or B, C. That violates order specified in ordering file.
Patch changes that.

Alternative can be to disable ICF for ordered sections. Not sure what
is better. May be we should do that instead ?

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

grimar created this revision.Feb 13 2018, 6:02 AM
ruiu added a comment.Feb 13 2018, 5:54 PM

I think that this patch isn't necessarily wrong but perhaps not desirable. Why did you pick the highest priority instead of the lowest priority, for example? The stuff you want to achieve with --symbol-ordering-file is to force some layout, and if your file contains duplicate entries due to ICF, you can't achieve your goal.

I think that you create a symbol ordering file from profiler output. COMDAT names that the profiler uses is the one that is selected by ICF, no? So, the generated symbol ordering file naturally uses the COMDAT names that were selected by ICF. So I don't think we need to do anything about it.

I think that you create a symbol ordering file from profiler output. COMDAT names that the profiler uses is the one that is selected by ICF, no? So, the generated symbol ordering file naturally uses the COMDAT names that were selected by ICF. So I don't think we need to do anything about it.

I think this is the normal use case, but I don't think it's the only use case, so I'm not sure we can assume that these files have always been auto-generated. I think that warning for the removed symbol is probably sufficient though, to alert users to something going wrong. This is the current behaviour, following my earlier change, and see also D43336, where I realised that it should be tested explicitly. One counter-argument to this is that profilers may not load the symbols in symbol table order, so this means that they could load the "discarded" symbol first (since it appears in the symbol table), and try to add it to the order file, instead of the selected one, resulting in warnings for what should seem like a perfectly good input on first look.

I think the only way we can avoid warnings in both cases is to disable --icf with --symbol-ordering-file, at least for the contents of that file (symbols in the ordering file could still be in "selected" sections, but not removed ones). I'm not sure if this is ideal either though.

grimar updated this revision to Diff 134630.Feb 16 2018, 8:11 AM
  • Addressed comment.
pasko added a subscriber: pasko.Feb 21 2018, 5:41 AM
espindola accepted this revision.Feb 26 2018, 2:40 PM

LGTM.

Please land this. It is now trivial and there is always post commit review.

This revision is now accepted and ready to land.Feb 26 2018, 2:40 PM
This revision was automatically updated to reflect the committed changes.