Page MenuHomePhabricator

[llvm] Enable specifying the order of Registry entries
DraftPublic

Authored by njames93 on Nov 13 2020, 12:03 PM.
This is a draft revision that has not yet been submitted for review.

Details

Reviewers
None
Summary

Adds support for specifying the order that items appear in llvm::Registry instances.
Currently they appear in the Registry linked list in an undefined order due to the 'static initialization order fiasco'.
For most registries this doesn't pose a problem as there is no observable difference in behaviour, however for a select few there is.
Take the CompilationDatabasePlugins as example. Usages of this is to load a database from a directory with each plugin, breaking out of the loop once a plugin is successful.
In the case where 2 plugins both can load from the same directory, the database you will get will depend on which plugin entry was initialized first. A bug for this has been reported here - https://github.com/clangd/clangd/issues/578.

This patch adds an optional paramater to the Registry::Add function to specify the order of the plugins in the list, lower orders appear near the start. Any plugins that dont specify an order will be placed at the end using the same SIOF behaviour that currently exists.

Diff Detail

Unit TestsFailed

TimeTest
360 mslinux > HWAddressSanitizer-x86_64.TestCases::sizes.cpp
Script: -- : 'RUN: at line 3'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang --driver-mode=g++ -m64 -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -mcmodel=large -mllvm -hwasan-globals -mllvm -hwasan-use-short-granules -mllvm -hwasan-instrument-landing-pads=0 -mllvm -hwasan-instrument-personality-functions /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/hwasan/TestCases/sizes.cpp -nostdlib++ -lstdc++ -o /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/sizes.cpp.tmp
50 mslinux > SanitizerCommon-Unit._/Sanitizer-x86_64-Test::SanitizerCommon.StackDepotPrint
Note: Google Test filter = SanitizerCommon.StackDepotPrint [==========] Running 1 test from 1 test case. [----------] Global test environment set-up.

Event Timeline

njames93 created this revision.Nov 13 2020, 12:03 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 13 2020, 12:03 PM
njames93 updated this revision to Diff 305312.Nov 14 2020, 6:22 AM
  • Fix some lint warnings, can't fix the include order as the fix disagrees with clang-format.
  • Add missing new line at end of test file.
nridge added a subscriber: nridge.Nov 14 2020, 11:34 AM
njames93 updated this revision to Diff 305454.Nov 16 2020, 3:22 AM

Use __LINE__ instead of __COUNTER__ macro as its standardized.