From d26c8e346344eec7d178b0cf5fe2fa30813c076e Mon Sep 17 00:00:00 2001 From: Shankar Easwaran Date: Sat, 31 Aug 2013 05:27:38 +0000 Subject: [lld][LinkingContext] Atoms created from command line options should be available in YAML This adds an API to the LinkingContext for flavors to add Internal files containing atoms that need to appear in the YAML output as well, when -emit-yaml switch is used. Flavors can add more internal files for other options that are needed. llvm-svn: 189718 --- lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp | 36 +++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp') diff --git a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp index e19a4be573b..7e013705647 100644 --- a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp @@ -9,6 +9,7 @@ #include "lld/ReaderWriter/ELFLinkingContext.h" +#include "File.h" #include "TargetHandler.h" #include "Targets.h" @@ -22,6 +23,17 @@ #include "llvm/Support/Path.h" namespace lld { + +class CommandLineUndefinedAtom : public SimpleUndefinedAtom { +public: + CommandLineUndefinedAtom(const File &f, StringRef name) + : SimpleUndefinedAtom(f, name) {} + + virtual CanBeNull canBeNull() const { + return CanBeNull::canBeNullAtBuildtime; + } +}; + ELFLinkingContext::ELFLinkingContext( llvm::Triple triple, std::unique_ptr targetHandler) : _outputFileType(elf::ET_EXEC), _triple(triple), @@ -29,8 +41,7 @@ ELFLinkingContext::ELFLinkingContext( _isStaticExecutable(false), _outputYAML(false), _noInhibitExec(false), _mergeCommonStrings(false), _runLayoutPass(true), _useShlibUndefines(false), _dynamicLinkerArg(false), - _noAllowDynamicLibraries(false), - _outputMagic(OutputMagic::DEFAULT) {} + _noAllowDynamicLibraries(false), _outputMagic(OutputMagic::DEFAULT) {} bool ELFLinkingContext::is64Bits() const { return getTriple().isArch64Bit(); } @@ -59,11 +70,13 @@ uint16_t ELFLinkingContext::getOutputMachine() const { } } -bool ELFLinkingContext::validateImpl(raw_ostream &diagnostics) { - if (_outputFileType == elf::ET_EXEC && _entrySymbolName.empty()) { - _entrySymbolName = "_start"; - } +StringRef ELFLinkingContext::entrySymbolName() const { + if (_outputFileType == elf::ET_EXEC && _entrySymbolName.empty()) + return "_start"; + return _entrySymbolName; +} +bool ELFLinkingContext::validateImpl(raw_ostream &diagnostics) { _elfReader = createReaderELF(*this); _linkerScriptReader.reset(new ReaderLinkerScript(*this)); _writer = _outputYAML ? createWriterYAML(*this) : createWriterELF(*this); @@ -157,4 +170,15 @@ StringRef ELFLinkingContext::searchLibrary( return libName; } +std::unique_ptr ELFLinkingContext::createUndefinedSymbolFile() { + if (_initialUndefinedSymbols.empty()) + return nullptr; + std::unique_ptr undefinedSymFile( + new SimpleFile(*this, "command line option -u")); + for (auto undefSymStr : _initialUndefinedSymbols) + undefinedSymFile->addAtom(*(new (_allocator) CommandLineUndefinedAtom( + *undefinedSymFile, undefSymStr))); + return std::move(undefinedSymFile); +} + } // end namespace lld -- cgit v1.2.3