This is an archive of the discontinued LLVM Phabricator instance.

[ELF][Driver] Fix precedence of symbol ordering file and CGProfile
ClosedPublic

Authored by tcwang on May 8 2019, 6:20 PM.

Details

Summary

This patch is a fix for https://bugs.llvm.org/show_bug.cgi?id=41804.
We try to solve the precedence of user-specified symbol ordering file and C3 ordering provided as call graph. It deals with two case:
(1) When both --symbol-ordering-file=<file> and --call-graph-order-file=<file> are present, whichever flag comes later will take precedence.
(2) When only --symbol-ordering-file=<file> is present, it takes precedence over implicit call graph (CGProfile) generated by CGProfilePass enabled in new pass manager.

Event Timeline

tcwang created this revision.May 8 2019, 6:20 PM
tcwang edited the summary of this revision. (Show Details)May 8 2019, 6:20 PM
ruiu added a comment.May 8 2019, 6:23 PM

(1) When both --symbol-ordering-file=<file> and --call-graph-order-file=<file> are present, whichever flag comes later will take precedence.

It looks like this combination is a misuse of the feature. Instead of silently ignore a flag, I think we should report an error that these flags cannot be used together.

(2) When only --symbol-ordering-file=<file> is present, it takes precedence over implicit call graph (CGProfile) generated by CGProfilePass enabled in new pass manager.

This is fine by me.

tcwang updated this revision to Diff 198874.May 9 2019, 10:53 AM

This patch is a fix for https://bugs.llvm.org/show_bug.cgi?id=41804.
We try to solve the precedence of user-specified symbol ordering file and C3 ordering provided as call graph. It deals with two case:
(1) When both --symbol-ordering-file=<file> and --call-graph-order-file=<file> are present, LLD reports an error and aborts.
(2) When only --symbol-ordering-file=<file> is present, it takes precedence over implicit call graph (CGProfile) generated by CGProfilePass enabled in new pass manager.

(1) When both --symbol-ordering-file=<file> and --call-graph-order-file=<file> are present, whichever flag comes later will take precedence.

It looks like this combination is a misuse of the feature. Instead of silently ignore a flag, I think we should report an error that these flags cannot be used together.

(2) When only --symbol-ordering-file=<file> is present, it takes precedence over implicit call graph (CGProfile) generated by CGProfilePass enabled in new pass manager.

This is fine by me.

Thanks! Fixed the patch with the suggestions.

ruiu added inline comments.May 9 2019, 6:46 PM
lld/ELF/Driver.cpp
968–970

Check for invalid combination of flags are usually done in checkOptions(). Can you write a check for this combination there?

MaskRay added inline comments.May 9 2019, 7:17 PM
lld/test/ELF/symbol-ordering-file-cgprofile-conflicts.s
3

Nit: name the object file %t.o, the executable %t

32

rm -f. -f suppresses the error if the file doesn't exist.

68

Delete the empty line.

tcwang updated this revision to Diff 199030.May 10 2019, 9:50 AM
tcwang marked 3 inline comments as done.

Fix comments on the unit test.

tcwang added inline comments.May 10 2019, 9:50 AM
lld/ELF/Driver.cpp
968–970

checkOptions() function doesn't take any arguments in but I need Args to check if OPT_call_graph_ordering_file is present or not. It's because the flag is read very late in the stage (just before writeResult<ELFT>() ) and not saved to any Config field, I have to use Args to directly check its presence. Whereas in checkOptions(), all other checkings are done by checking Config fields. Also, if I do check in checkOptions(), which happens after readConfigs(), it needs to read in the file even if an error will be reported later?

Friendly ping on the patch.

ruiu added inline comments.May 16 2019, 6:37 PM
lld/ELF/Driver.cpp
968–970

OK, but please make the wording consistent with other error messages. If you look at checkOptions, you'd notice that we use the same wording for reporting incompatible option combinations.

tcwang updated this revision to Diff 199964.May 16 2019, 8:03 PM

Fix comments in options checking.

tcwang marked an inline comment as done.May 16 2019, 8:03 PM
tcwang added inline comments.
lld/ELF/Driver.cpp
968–970

Yeah, that makes sense. Thanks for pointing out.

ruiu accepted this revision.May 17 2019, 3:33 AM

LGTM

This revision is now accepted and ready to land.May 17 2019, 3:33 AM
MaskRay closed this revision.May 20 2019, 6:42 PM

The commit description of rLLD361190 does not contain Differential Revision: https://reviews.llvm.org/D61711, so the revision was not closed when you committed that...

Also, the description should probably say the two options are now exclusive:

(1) When both --symbol-ordering-file=<file> and --call-graph-order-file=<file> are present, whichever flag comes later will take precedence.

The commit description of rLLD361190 does not contain Differential Revision: https://reviews.llvm.org/D61711, so the revision was not closed when you committed that...

Also, the description should probably say the two options are now exclusive:

(1) When both --symbol-ordering-file=<file> and --call-graph-order-file=<file> are present, whichever flag comes later will take precedence.

Thank you! I'll keep in mind to add the differential revision to LLVM commit next time. Also, is it possible to change the commit message on the other commits now? Sorry that I forgot to change them...