//===- MarkLive.cpp -------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements --gc-sections, which is a feature to remove unused // chunks from the output. Unused chunks are those that are not reachable from // known root symbols or chunks. This feature is implemented as a mark-sweep // garbage collector. // // Here's how it works. Each InputChunk has a "Live" bit. The bit is off by // default. Starting with the GC-roots, visit all reachable chunks and set their // Live bits. The Writer will then ignore chunks whose Live bits are off, so // that such chunk are not appear in the output. // //===----------------------------------------------------------------------===// #include "MarkLive.h" #include "Config.h" #include "InputChunks.h" #include "InputElement.h" #include "SymbolTable.h" #include "Symbols.h" #define DEBUG_TYPE … usingnamespacellvm; usingnamespacellvm::wasm; namespace lld::wasm { namespace { class MarkLive { … }; } // namespace void MarkLive::enqueue(Symbol *sym) { … } void MarkLive::enqueue(InputChunk *chunk) { … } // The ctor functions are all referenced by the synthetic callCtors // function. However, this function does not contain relocations so we // have to manually mark the ctors as live. void MarkLive::enqueueInitFunctions(const ObjFile *obj) { … } // Mark segments flagged by segment-level no-strip. Segment-level no-strip is // usually used to retain segments without having symbol table entry. void MarkLive::enqueueRetainedSegments(const ObjFile *file) { … } void MarkLive::run() { … } void MarkLive::mark() { … } void markLive() { … } bool MarkLive::isCallCtorsLive() { … } } // namespace lld::wasm