The previous code assigned priorities for sections across different call stacks from Driver.cpp. The data gathered to assign priorities seems to be spread across different call stacks by necessity (test fails when I try to put them all together). However, the actual priority assignments do not need to be. After all of the relevant data has been collected, we can make all the priority assignments under one function (ie, buildInputSectionPriorities()) specific for that purpose. This is the change for this diff.
This diff is almost completely a NFC but there is one slight functional change that I believe corrects a bug. The existing code for extractCallGraphProfile() filters data about calls from or to symbols that already has a priority (based on the order file). There are two ways for a symbol to have a priority at that point in time:
- The symbol is specifically referenced by name and its order file in the order file.
- The symbol is indirectly referenced by an entry in the order file that contains its name but specifies no order file.
If two order files each have a symbol using the same name and the order file includes one of the symbols (specifying its order file), the existing code produced a side effect of giving all symbols of the same name a default priority of zero. Having a priority of zero is not the same as having no priority at all as now those symbols with default priority zero will have their calls ignored by extractCallGraphProfile().
My diff changes this behavior so that an entry in the order file for one symbol in a specific object file will have no effect on the priority of symbols with the same name in other object files.
clang-format: please reformat the code