2015-08-14 22:12:54 +08:00
|
|
|
//===- Config.h -------------------------------------------------*- C++ -*-===//
|
2015-07-25 05:03:07 +08:00
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_ELF_CONFIG_H
|
|
|
|
#define LLD_ELF_CONFIG_H
|
|
|
|
|
2015-11-12 17:52:08 +08:00
|
|
|
#include "llvm/ADT/MapVector.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2016-12-20 02:00:52 +08:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
2017-03-17 10:24:16 +08:00
|
|
|
#include "llvm/Support/CachePruning.h"
|
2017-03-01 07:43:26 +08:00
|
|
|
#include "llvm/Support/CodeGen.h"
|
2017-03-22 05:40:08 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-09-28 21:11:36 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
namespace lld {
|
2016-02-28 08:25:54 +08:00
|
|
|
namespace elf {
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-10-12 09:55:32 +08:00
|
|
|
class InputFile;
|
2015-10-10 05:12:40 +08:00
|
|
|
|
2015-10-07 17:13:03 +08:00
|
|
|
enum ELFKind {
|
|
|
|
ELFNoneKind,
|
|
|
|
ELF32LEKind,
|
|
|
|
ELF32BEKind,
|
|
|
|
ELF64LEKind,
|
|
|
|
ELF64BEKind
|
|
|
|
};
|
|
|
|
|
2016-08-31 16:38:11 +08:00
|
|
|
// For --build-id.
|
2016-09-14 19:32:57 +08:00
|
|
|
enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
|
2016-04-08 06:49:21 +08:00
|
|
|
|
2017-01-26 05:23:06 +08:00
|
|
|
// For --discard-{all,locals,none}.
|
|
|
|
enum class DiscardPolicy { Default, All, Locals, None };
|
2016-08-31 16:46:30 +08:00
|
|
|
|
2016-08-31 16:38:11 +08:00
|
|
|
// For --strip-{all,debug}.
|
|
|
|
enum class StripPolicy { None, All, Debug };
|
|
|
|
|
|
|
|
// For --unresolved-symbols.
|
2017-07-26 17:46:59 +08:00
|
|
|
enum class UnresolvedPolicy { ReportError, Warn, Ignore, IgnoreAll };
|
2016-06-29 20:35:04 +08:00
|
|
|
|
2017-10-25 23:20:30 +08:00
|
|
|
// For --orphan-handling.
|
|
|
|
enum class OrphanHandlingPolicy { Place, Warn, Error };
|
|
|
|
|
2016-09-17 04:21:55 +08:00
|
|
|
// For --sort-section and linkerscript sorting rules.
|
2016-09-17 05:14:55 +08:00
|
|
|
enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
|
2016-09-17 04:21:55 +08:00
|
|
|
|
2016-10-18 02:12:24 +08:00
|
|
|
// For --target2
|
|
|
|
enum class Target2Policy { Abs, Rel, GotRel };
|
|
|
|
|
2016-07-16 20:26:39 +08:00
|
|
|
struct SymbolVersion {
|
|
|
|
llvm::StringRef Name;
|
|
|
|
bool IsExternCpp;
|
2016-11-18 14:30:08 +08:00
|
|
|
bool HasWildcard;
|
2016-07-16 20:26:39 +08:00
|
|
|
};
|
|
|
|
|
2016-06-20 19:55:12 +08:00
|
|
|
// This struct contains symbols version definition that
|
|
|
|
// can be found in version script if it is used for link.
|
2016-07-16 12:02:00 +08:00
|
|
|
struct VersionDefinition {
|
2016-06-20 19:55:12 +08:00
|
|
|
llvm::StringRef Name;
|
2017-03-10 03:23:00 +08:00
|
|
|
uint16_t Id = 0;
|
2016-07-16 20:26:39 +08:00
|
|
|
std::vector<SymbolVersion> Globals;
|
2017-03-10 03:23:00 +08:00
|
|
|
size_t NameOff = 0; // Offset in the string table
|
2016-06-20 19:55:12 +08:00
|
|
|
};
|
|
|
|
|
2016-01-06 01:55:05 +08:00
|
|
|
// 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.
|
2015-07-25 05:03:07 +08:00
|
|
|
struct Configuration {
|
2016-10-27 22:00:51 +08:00
|
|
|
uint8_t OSABI = 0;
|
2017-03-17 10:24:16 +08:00
|
|
|
llvm::CachePruningPolicy ThinLTOCachePolicy;
|
2016-09-14 21:07:13 +08:00
|
|
|
llvm::StringMap<uint64_t> SectionStartMap;
|
2017-07-21 02:17:55 +08:00
|
|
|
llvm::StringRef Chroot;
|
2015-09-12 02:49:42 +08:00
|
|
|
llvm::StringRef DynamicLinker;
|
2015-09-30 06:33:21 +08:00
|
|
|
llvm::StringRef Entry;
|
2015-10-11 11:36:49 +08:00
|
|
|
llvm::StringRef Emulation;
|
2015-10-08 03:34:51 +08:00
|
|
|
llvm::StringRef Fini;
|
|
|
|
llvm::StringRef Init;
|
2016-11-26 13:37:04 +08:00
|
|
|
llvm::StringRef LTOAAPipeline;
|
|
|
|
llvm::StringRef LTONewPmPasses;
|
2017-01-14 05:05:46 +08:00
|
|
|
llvm::StringRef MapFile;
|
2015-10-07 08:25:09 +08:00
|
|
|
llvm::StringRef OutputFile;
|
2017-02-14 01:49:18 +08:00
|
|
|
llvm::StringRef OptRemarksFilename;
|
2015-10-02 03:36:04 +08:00
|
|
|
llvm::StringRef SoName;
|
2015-09-30 06:33:21 +08:00
|
|
|
llvm::StringRef Sysroot;
|
2017-03-02 07:00:10 +08:00
|
|
|
llvm::StringRef ThinLTOCacheDir;
|
2017-04-30 07:06:43 +08:00
|
|
|
std::string Rpath;
|
2016-07-16 12:09:27 +08:00
|
|
|
std::vector<VersionDefinition> VersionDefinitions;
|
2017-07-11 05:01:37 +08:00
|
|
|
std::vector<llvm::StringRef> Argv;
|
2016-09-02 17:13:05 +08:00
|
|
|
std::vector<llvm::StringRef> AuxiliaryList;
|
2017-07-17 17:43:18 +08:00
|
|
|
std::vector<llvm::StringRef> FilterList;
|
2015-10-11 11:28:42 +08:00
|
|
|
std::vector<llvm::StringRef> SearchPaths;
|
2016-12-20 09:51:08 +08:00
|
|
|
std::vector<llvm::StringRef> SymbolOrderingFile;
|
2015-10-20 01:35:12 +08:00
|
|
|
std::vector<llvm::StringRef> Undefined;
|
2017-09-09 02:16:59 +08:00
|
|
|
std::vector<SymbolVersion> DynamicList;
|
2016-07-16 20:26:39 +08:00
|
|
|
std::vector<SymbolVersion> VersionScriptGlobals;
|
2016-11-17 02:46:23 +08:00
|
|
|
std::vector<SymbolVersion> VersionScriptLocals;
|
2016-05-14 05:55:56 +08:00
|
|
|
std::vector<uint8_t> BuildIdVector;
|
2015-10-01 01:26:13 +08:00
|
|
|
bool AllowMultipleDefinition;
|
2017-10-28 01:49:40 +08:00
|
|
|
bool AndroidPackDynRelocs = false;
|
2017-11-28 21:51:48 +08:00
|
|
|
bool ARMHasBlx = false;
|
|
|
|
bool ARMHasMovtMovw = false;
|
|
|
|
bool ARMJ1J2BranchEncoding = false;
|
2015-10-12 04:59:12 +08:00
|
|
|
bool AsNeeded = false;
|
2015-10-14 05:02:34 +08:00
|
|
|
bool Bsymbolic;
|
2016-02-02 17:28:53 +08:00
|
|
|
bool BsymbolicFunctions;
|
2017-04-17 16:58:12 +08:00
|
|
|
bool CompressDebugSections;
|
2017-01-24 11:41:20 +08:00
|
|
|
bool DefineCommon;
|
2016-01-14 02:55:39 +08:00
|
|
|
bool Demangle = true;
|
2016-04-03 11:39:09 +08:00
|
|
|
bool DisableVerify;
|
2016-01-15 21:34:52 +08:00
|
|
|
bool EhFrameHdr;
|
2017-02-09 00:18:10 +08:00
|
|
|
bool EmitRelocs;
|
2015-10-07 04:02:15 +08:00
|
|
|
bool EnableNewDtags;
|
2015-10-01 01:26:13 +08:00
|
|
|
bool ExportDynamic;
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
bool GcSections;
|
2016-10-20 17:19:48 +08:00
|
|
|
bool GdbIndex;
|
2017-10-06 17:37:44 +08:00
|
|
|
bool GnuHash = false;
|
2017-09-09 02:53:43 +08:00
|
|
|
bool HasDynamicList = false;
|
2017-09-16 02:05:02 +08:00
|
|
|
bool HasDynSymTab;
|
2016-02-26 02:43:51 +08:00
|
|
|
bool ICF;
|
2016-11-06 06:58:01 +08:00
|
|
|
bool MipsN32Abi = false;
|
2016-04-08 04:41:41 +08:00
|
|
|
bool NoGnuUnique;
|
2016-06-28 16:07:26 +08:00
|
|
|
bool NoUndefinedVersion;
|
2017-07-27 15:48:36 +08:00
|
|
|
bool NoinhibitExec;
|
2016-09-03 03:20:33 +08:00
|
|
|
bool Nostdlib;
|
2016-08-25 17:05:47 +08:00
|
|
|
bool OFormatBinary;
|
2017-02-25 09:52:03 +08:00
|
|
|
bool Omagic;
|
2017-02-14 01:49:18 +08:00
|
|
|
bool OptRemarksWithHotness;
|
2016-03-17 13:57:33 +08:00
|
|
|
bool Pie;
|
2015-12-10 17:12:18 +08:00
|
|
|
bool PrintGcSections;
|
2016-02-25 16:23:37 +08:00
|
|
|
bool Relocatable;
|
2016-03-10 04:01:08 +08:00
|
|
|
bool SaveTemps;
|
2016-11-28 18:05:20 +08:00
|
|
|
bool SingleRoRx;
|
2015-10-01 01:26:13 +08:00
|
|
|
bool Shared;
|
2015-10-02 00:42:03 +08:00
|
|
|
bool Static = false;
|
2017-10-06 17:37:44 +08:00
|
|
|
bool SysvHash = false;
|
2016-08-02 03:28:13 +08:00
|
|
|
bool Target1Rel;
|
2016-03-29 16:45:40 +08:00
|
|
|
bool Trace;
|
2015-10-11 10:03:03 +08:00
|
|
|
bool Verbose;
|
2016-03-14 17:19:30 +08:00
|
|
|
bool WarnCommon;
|
2016-12-07 12:06:21 +08:00
|
|
|
bool WarnMissingEntry;
|
2016-05-10 23:47:57 +08:00
|
|
|
bool ZCombreloc;
|
2016-10-12 01:46:48 +08:00
|
|
|
bool ZExecstack;
|
2017-02-22 05:41:50 +08:00
|
|
|
bool ZNocopyreloc;
|
2015-11-21 05:00:42 +08:00
|
|
|
bool ZNodelete;
|
2017-03-23 08:54:16 +08:00
|
|
|
bool ZNodlopen;
|
2015-11-21 05:00:42 +08:00
|
|
|
bool ZNow;
|
|
|
|
bool ZOrigin;
|
2015-11-24 18:15:50 +08:00
|
|
|
bool ZRelro;
|
2017-05-27 03:12:38 +08:00
|
|
|
bool ZRodynamic;
|
2017-03-09 16:48:34 +08:00
|
|
|
bool ZText;
|
2016-10-27 02:59:00 +08:00
|
|
|
bool ExitEarly;
|
2016-10-14 18:34:36 +08:00
|
|
|
bool ZWxneeded;
|
2016-08-31 16:46:30 +08:00
|
|
|
DiscardPolicy Discard;
|
2017-10-25 23:20:30 +08:00
|
|
|
OrphanHandlingPolicy OrphanHandling;
|
2016-09-17 04:21:55 +08:00
|
|
|
SortSectionPolicy SortSection;
|
2017-02-25 10:12:37 +08:00
|
|
|
StripPolicy Strip;
|
2016-06-29 20:35:04 +08:00
|
|
|
UnresolvedPolicy UnresolvedSymbols;
|
2017-02-25 10:27:58 +08:00
|
|
|
Target2Policy Target2;
|
2016-04-08 06:49:21 +08:00
|
|
|
BuildIdKind BuildId = BuildIdKind::None;
|
2015-10-14 00:20:50 +08:00
|
|
|
ELFKind EKind = ELFNoneKind;
|
2016-07-16 11:08:26 +08:00
|
|
|
uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
|
2015-10-07 17:13:03 +08:00
|
|
|
uint16_t EMachine = llvm::ELF::EM_NONE;
|
2017-10-10 18:09:35 +08:00
|
|
|
llvm::Optional<uint64_t> ImageBase;
|
2016-09-28 23:20:47 +08:00
|
|
|
uint64_t MaxPageSize;
|
|
|
|
uint64_t ZStackSize;
|
2016-11-26 13:37:04 +08:00
|
|
|
unsigned LTOPartitions;
|
|
|
|
unsigned LTOO;
|
2016-04-01 05:15:31 +08:00
|
|
|
unsigned Optimize;
|
2016-11-26 13:37:04 +08:00
|
|
|
unsigned ThinLTOJobs;
|
2017-02-14 13:45:47 +08:00
|
|
|
|
2017-03-18 07:29:01 +08:00
|
|
|
// The following config options do not directly correspond to any
|
|
|
|
// particualr command line options.
|
2017-03-15 17:12:56 +08:00
|
|
|
|
2017-03-18 07:29:01 +08:00
|
|
|
// True if we need to pass through relocations in input files to the
|
|
|
|
// output file. Usually false because we consume relocations.
|
|
|
|
bool CopyRelocs;
|
2017-03-18 07:28:41 +08:00
|
|
|
|
2017-03-22 08:01:11 +08:00
|
|
|
// True if the target is ELF64. False if ELF32.
|
|
|
|
bool Is64;
|
|
|
|
|
|
|
|
// True if the target is little-endian. False if big-endian.
|
2017-03-18 07:29:01 +08:00
|
|
|
bool IsLE;
|
|
|
|
|
2017-03-22 05:40:08 +08:00
|
|
|
// endianness::little if IsLE is true. endianness::big otherwise.
|
|
|
|
llvm::support::endianness Endianness;
|
|
|
|
|
2017-03-18 07:29:01 +08:00
|
|
|
// True if the target is the little-endian MIPS64.
|
|
|
|
//
|
|
|
|
// The reason why we have this variable only for the MIPS is because
|
|
|
|
// we use this often. Some ELF headers for MIPS64EL are in a
|
|
|
|
// mixed-endian (which is horrible and I'd say that's a serious spec
|
|
|
|
// bug), and we need to know whether we are reading MIPS ELF files or
|
|
|
|
// not in various places.
|
|
|
|
//
|
|
|
|
// (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
|
|
|
|
// name whatever that means. A fun hypothesis is that "EL" is short for
|
|
|
|
// little-endian written in the little-endian order, but I don't know
|
|
|
|
// if that's true.)
|
|
|
|
bool IsMips64EL;
|
2017-03-18 07:28:41 +08:00
|
|
|
|
2017-10-25 01:01:40 +08:00
|
|
|
// Holds set of ELF header flags for the target.
|
|
|
|
uint32_t EFlags = 0;
|
2017-10-02 22:56:41 +08:00
|
|
|
|
2017-03-07 08:43:53 +08:00
|
|
|
// The ELF spec defines two types of relocation table entries, RELA and
|
|
|
|
// REL. RELA is a triplet of (offset, info, addend) while REL is a
|
|
|
|
// tuple of (offset, info). Addends for REL are implicit and read from
|
|
|
|
// the location where the relocations are applied. So, REL is more
|
|
|
|
// compact than RELA but requires a bit of more work to process.
|
|
|
|
//
|
|
|
|
// (From the linker writer's view, this distinction is not necessary.
|
|
|
|
// If the ELF had chosen whichever and sticked with it, it would have
|
|
|
|
// been easier to write code to process relocations, but it's too late
|
|
|
|
// to change the spec.)
|
|
|
|
//
|
2017-03-18 07:29:01 +08:00
|
|
|
// Each ABI defines its relocation type. IsRela is true if target
|
|
|
|
// uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
|
|
|
|
// few 32-bit ABIs are using RELA too.
|
|
|
|
bool IsRela;
|
|
|
|
|
|
|
|
// True if we are creating position-independent code.
|
|
|
|
bool Pic;
|
|
|
|
|
|
|
|
// 4 for ELF32, 8 for ELF64.
|
|
|
|
int Wordsize;
|
2015-07-25 05:03:07 +08:00
|
|
|
};
|
|
|
|
|
2016-01-06 01:55:05 +08:00
|
|
|
// The only instance of Configuration struct.
|
2015-07-25 05:03:07 +08:00
|
|
|
extern Configuration *Config;
|
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
} // namespace elf
|
2015-07-25 05:03:07 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|