[PATCH] D108850: [LLD] Remove global state in lldCommon
Alexandre Ganea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 27 14:50:42 PDT 2021
aganea created this revision.
aganea added reviewers: rnk, mstorsjo, amccarth, MaskRay.
aganea added a project: lld.
Herald added subscribers: ormris, dexonsmith, steven_wu, kbarton, hiraditya, arichardson, sbc100, mgorny, nemanjai, emaste.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
aganea requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
As discussed in our last Windows/COFF call, and as proposed by Reid in [1], this patch implements a first iteration to make LLD free of global initializers & global state. Here we only remove global state in `lldCommon`, however the same concept can be applied to other LLD libs.
The idea is to move all variables at file-scope or function-static-scope into a hosting structure (`lld::CommonGlobals`) that lives at `lldMain()`-scope. I was planning on a single structure per library (`lld::CommonGlobals` for `lldCommon`, a future `lld::CoffGlobals` for `lldCOFF`, etc.).
Before, code was directly referencing state in the `.data` section. It now goes through an indirection to a `thread_local` pointer to the `lld::CommonGlobals` instance. Several instances of `lld::CommonGlobals` could coexist in the future (if the caller application is similar to D86351 <https://reviews.llvm.org/D86351>). This also means that `ThreadPool`s and `TaskGroup`s need to explicitly set their corresponding `thread_local` pointer to the `lld::CommonGlobals` instance initiated by the caller `lldMain()`.
The next step after this patch would be to apply the same concept to the `lldCOFF` library.
In the future, I was also thinking in merging the feature of `ThreadPool`s and `TaskGroup` to only have an unique `ThreadPoolExecutor` per application. Tasks scheduled from different runtime instances of `lldMain()` would share the same thread pool.
[1] https://lists.llvm.org/pipermail/llvm-dev/2021-June/151184.html
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D108850
Files:
lld/COFF/Chunks.cpp
lld/COFF/DLL.cpp
lld/COFF/Driver.cpp
lld/COFF/DriverUtils.cpp
lld/COFF/InputFiles.cpp
lld/COFF/LTO.cpp
lld/COFF/MinGW.cpp
lld/COFF/PDB.cpp
lld/COFF/SymbolTable.cpp
lld/COFF/Writer.cpp
lld/Common/CMakeLists.txt
lld/Common/ErrorHandler.cpp
lld/Common/Globals.cpp
lld/Common/Memory.cpp
lld/Common/TargetOptionsCommandFlags.cpp
lld/Common/Timer.cpp
lld/ELF/AArch64ErrataFix.cpp
lld/ELF/ARMErrataFix.cpp
lld/ELF/Arch/PPC64.cpp
lld/ELF/Driver.cpp
lld/ELF/DriverUtils.cpp
lld/ELF/InputFiles.cpp
lld/ELF/InputSection.cpp
lld/ELF/LTO.cpp
lld/ELF/MarkLive.cpp
lld/ELF/ScriptParser.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/Thunks.cpp
lld/ELF/Writer.cpp
lld/MachO/ConcatOutputSection.cpp
lld/MachO/Driver.cpp
lld/MachO/DriverUtils.cpp
lld/MachO/InputFiles.cpp
lld/MachO/LTO.cpp
lld/MachO/SyntheticSections.cpp
lld/MachO/Writer.cpp
lld/MinGW/Driver.cpp
lld/include/lld/Common/Driver.h
lld/include/lld/Common/ErrorHandler.h
lld/include/lld/Common/Globals.h
lld/include/lld/Common/Memory.h
lld/include/lld/Common/Timer.h
lld/lib/Driver/DarwinLdDriver.cpp
lld/tools/lld/lld.cpp
lld/unittests/DriverTests/DarwinLdDriverTest.cpp
lld/wasm/Driver.cpp
lld/wasm/InputFiles.cpp
lld/wasm/LTO.cpp
lld/wasm/SymbolTable.cpp
lld/wasm/Writer.cpp
llvm/include/llvm/LTO/LTO.h
llvm/include/llvm/Support/Parallel.h
llvm/lib/LTO/LTO.cpp
llvm/lib/Support/Parallel.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108850.369181.patch
Type: text/x-patch
Size: 96922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210827/6bac9a68/attachment-0001.bin>
More information about the llvm-commits
mailing list