llvm-project/lld/wasm/Config.h
Sam Clegg 758633f922 [lld][WebAssembly] Add new --import-undefined option
This change revisits https://reviews.llvm.org/D79248 which originally
added support for the --unresolved-symbols flag.

At the time I thought it would make sense to add a third option to this
flag called `import-functions` but it turns out (as was suspects by on
the reviewers IIRC) that this option can be authoganal.

Instead I've added a new option called `--import-undefined` that only
operates on symbols that can be imported (for example, function symbols
can always be imported as opposed to data symbols we can only be
imported when compiling with PIC).

This option gives us the full expresivitiy that emscripten needs to be
able allow reporting of undefined data symbols as well as the option to
disable that.

This change does remove the `--unresolved-symbols=import-functions`
option, which is been in the codebase now for about a year but I would
be extremely surprised if anyone was using it.

Differential Revision: https://reviews.llvm.org/D103290
2021-06-17 11:44:21 -07:00

103 lines
2.9 KiB
C++

//===- Config.h -------------------------------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef LLD_WASM_CONFIG_H
#define LLD_WASM_CONFIG_H
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/Support/CachePruning.h"
namespace lld {
namespace wasm {
// For --unresolved-symbols.
enum class UnresolvedPolicy { ReportError, Warn, Ignore };
// This struct contains the global configuration for the linker.
// Most fields are direct mapping from the command line options
// and such fields have the same name as the corresponding options.
// Most fields are initialized by the driver.
struct Configuration {
bool bsymbolic;
bool checkFeatures;
bool compressRelocations;
bool demangle;
bool disableVerify;
bool experimentalPic;
bool emitRelocs;
bool exportAll;
bool exportDynamic;
bool exportTable;
bool growableTable;
bool gcSections;
bool importMemory;
bool sharedMemory;
bool importTable;
bool importUndefined;
llvm::Optional<bool> is64;
bool mergeDataSegments;
bool pie;
bool printGcSections;
bool relocatable;
bool saveTemps;
bool shared;
bool stripAll;
bool stripDebug;
bool stackFirst;
bool trace;
uint64_t globalBase;
uint64_t initialMemory;
uint64_t maxMemory;
uint64_t zStackSize;
unsigned ltoPartitions;
unsigned ltoo;
unsigned optimize;
llvm::StringRef thinLTOJobs;
bool ltoNewPassManager;
bool ltoDebugPassManager;
UnresolvedPolicy unresolvedSymbols;
llvm::StringRef entry;
llvm::StringRef mapFile;
llvm::StringRef outputFile;
llvm::StringRef thinLTOCacheDir;
llvm::StringSet<> allowUndefinedSymbols;
llvm::StringSet<> exportedSymbols;
std::vector<llvm::StringRef> requiredExports;
std::vector<llvm::StringRef> searchPaths;
llvm::CachePruningPolicy thinLTOCachePolicy;
llvm::Optional<std::vector<std::string>> features;
// The following config options do not directly correspond to any
// particualr command line options.
// True if we are creating position-independent code.
bool isPic;
// True if we have an MVP input that uses __indirect_function_table and which
// requires it to be allocated to table number 0.
bool legacyFunctionTable = false;
// The table offset at which to place function addresses. We reserve zero
// for the null function pointer. This gets set to 1 for executables and 0
// for shared libraries (since they always added to a dynamic offset at
// runtime).
uint32_t tableBase = 0;
};
// The only instance of Configuration struct.
extern Configuration *config;
} // namespace wasm
} // namespace lld
#endif