llvm/lld/wasm/Writer.cpp

//===- Writer.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
//
//===----------------------------------------------------------------------===//

#include "Writer.h"
#include "Config.h"
#include "InputChunks.h"
#include "InputElement.h"
#include "MapFile.h"
#include "OutputSections.h"
#include "OutputSegment.h"
#include "Relocations.h"
#include "SymbolTable.h"
#include "SyntheticSections.h"
#include "WriterUtils.h"
#include "lld/Common/Arrays.h"
#include "lld/Common/CommonLinkerContext.h"
#include "lld/Common/Strings.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/BinaryFormat/WasmTraits.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/Parallel.h"
#include "llvm/Support/RandomNumberGenerator.h"
#include "llvm/Support/SHA1.h"
#include "llvm/Support/xxhash.h"

#include <cstdarg>
#include <map>
#include <optional>

#define DEBUG_TYPE

usingnamespacellvm;
usingnamespacellvm::wasm;

namespace lld::wasm {
static constexpr int stackAlignment =;
static constexpr int heapAlignment =;

namespace {

// The writer writes a SymbolTable result to a file.
class Writer {};

} // anonymous namespace

void Writer::calculateCustomSections() {}

void Writer::createCustomSections() {}

// Create relocations sections in the final output.
// These are only created when relocatable output is requested.
void Writer::createRelocSections() {}

void Writer::populateProducers() {}

void Writer::writeHeader() {}

void Writer::writeSections() {}

// Computes a hash value of Data using a given hash function.
// In order to utilize multiple cores, we first split data into 1MB
// chunks, compute a hash for each chunk, and then compute a hash value
// of the hash values.

static void
computeHash(llvm::MutableArrayRef<uint8_t> hashBuf,
            llvm::ArrayRef<uint8_t> data,
            std::function<void(uint8_t *dest, ArrayRef<uint8_t> arr)> hashFn) {}

static void makeUUID(unsigned version, llvm::ArrayRef<uint8_t> fileHash,
                     llvm::MutableArrayRef<uint8_t> output) {}

void Writer::writeBuildId() {}

static void setGlobalPtr(DefinedGlobal *g, uint64_t memoryPtr) {}

// Fix the memory layout of the output binary.  This assigns memory offsets
// to each of the input data sections as well as the explicit stack region.
// The default memory layout is as follows, from low to high.
//
//  - initialized data (starting at config->globalBase)
//  - BSS data (not currently implemented in llvm)
//  - explicit stack (config->ZStackSize)
//  - heap start / unallocated
//
// The --stack-first option means that stack is placed before any static data.
// This can be useful since it means that stack overflow traps immediately
// rather than overwriting global data, but also increases code size since all
// static data loads and stores requires larger offsets.
void Writer::layoutMemory() {}

void Writer::addSection(OutputSection *sec) {}

// If a section name is valid as a C identifier (which is rare because of
// the leading '.'), linkers are expected to define __start_<secname> and
// __stop_<secname> symbols. They are at beginning and end of the section,
// respectively. This is not requested by the ELF standard, but GNU ld and
// gold provide the feature, and used by many programs.
static void addStartStopSymbols(const OutputSegment *seg) {}

void Writer::addSections() {}

void Writer::finalizeSections() {}

void Writer::populateTargetFeatures() {}

void Writer::checkImportExportTargetFeatures() {}

static bool shouldImport(Symbol *sym) {}

void Writer::calculateImports() {}

void Writer::calculateExports() {}

void Writer::populateSymtab() {}

void Writer::calculateTypes() {}

// In a command-style link, create a wrapper for each exported symbol
// which calls the constructors and destructors.
void Writer::createCommandExportWrappers() {}

static void finalizeIndirectFunctionTable() {}

static void scanRelocations() {}

void Writer::assignIndexes() {}

static StringRef getOutputDataSegmentName(const InputChunk &seg) {}

OutputSegment *Writer::createOutputSegment(StringRef name) {}

void Writer::createOutputSegments() {}

void Writer::combineOutputSegments() {}

static void createFunction(DefinedFunction *func, StringRef bodyContent) {}

bool Writer::needsPassiveInitialization(const OutputSegment *segment) {}

bool Writer::hasPassiveInitializedSegments() {}

void Writer::createSyntheticInitFunctions() {}

void Writer::createInitMemoryFunction() {}

void Writer::createStartFunction() {}

// For -shared (PIC) output, we create create a synthetic function which will
// apply any relocations to the data segments on startup.  This function is
// called `__wasm_apply_data_relocs` and is expected to be called before
// any user code (i.e. before `__wasm_call_ctors`).
void Writer::createApplyDataRelocationsFunction() {}

void Writer::createApplyTLSRelocationsFunction() {}

// Similar to createApplyDataRelocationsFunction but generates relocation code
// for WebAssembly globals. Because these globals are not shared between threads
// these relocation need to run on every thread.
void Writer::createApplyGlobalRelocationsFunction() {}

// Similar to createApplyGlobalRelocationsFunction but for
// TLS symbols.  This cannot be run during the start function
// but must be delayed until __wasm_init_tls is called.
void Writer::createApplyGlobalTLSRelocationsFunction() {}

// Create synthetic "__wasm_call_ctors" function based on ctor functions
// in input object.
void Writer::createCallCtorsFunction() {}

// Create a wrapper around a function export which calls the
// static constructors and destructors.
void Writer::createCommandExportWrapper(uint32_t functionIndex,
                                        DefinedFunction *f) {}

void Writer::createInitTLSFunction() {}

// Populate InitFunctions vector with init functions from all input objects.
// This is then used either when creating the output linking section or to
// synthesize the "__wasm_call_ctors" function.
void Writer::calculateInitFunctions() {}

void Writer::createSyntheticSections() {}

void Writer::createSyntheticSectionsPostLayout() {}

void Writer::run() {}

// Open a result file.
void Writer::openFile() {}

void Writer::createHeader() {}

void writeResult() {}

} // namespace wasm::lld