[lld][LinkingContext][ELF] Allow different output file types.

This adds an option --output-filetype that can be set to either
YAML/Native(case insensitive). The linker would create the outputs
associated with the type specified by the user.

Changes all the tests to use the new option.

llvm-svn: 191183
This commit is contained in:
Shankar Easwaran 2013-09-23 04:24:15 +00:00
parent 90061908f6
commit 7915ff34b7
47 changed files with 129 additions and 78 deletions

View File

@ -46,6 +46,14 @@ class InputGraph;
/// to the ELF Reader and Writer.
class LinkingContext : public Reader {
public:
/// \brief The types of output file that the linker
/// creates.
enum class OutputFileType : uint8_t {
Default, // The default output type for this target
YAML, // The output type is set to YAML
Native // The output file format is Native (Atoms)
};
virtual ~LinkingContext();
/// \name Methods needed by core linking
@ -254,6 +262,22 @@ public:
/// the linker to write to an in-memory buffer.
StringRef outputPath() const { return _outputPath; }
/// Set the various output file types that the linker would
/// create
bool setOutputFileType(StringRef outputFileType) {
StringRef lowerOutputFileType = outputFileType.lower();
if (lowerOutputFileType == "yaml")
_outputFileType = OutputFileType::YAML;
else if (lowerOutputFileType == "native")
_outputFileType = OutputFileType::YAML;
else
return false;
return true;
}
/// Returns the output file that that the linker needs to create
OutputFileType outputFileType() const { return _outputFileType; }
/// Abstract method to parse a supplied input file buffer into one or
/// more lld::File objects. Subclasses of LinkingContext must implement this
/// method.
@ -325,6 +349,7 @@ protected:
bool _allowRemainingUndefines;
bool _logInputFiles;
bool _allowShlibUndefines;
OutputFileType _outputFileType;
std::vector<StringRef> _deadStripRoots;
std::vector<const char *> _llvmOptions;
std::unique_ptr<Reader> _yamlReader;

View File

@ -39,6 +39,9 @@ public:
class ELFLinkingContext : public LinkingContext {
public:
/// \brief The type of ELF executable that the linker
/// creates.
enum class OutputMagic : uint8_t {
DEFAULT, // The default mode, no specific magic set
NMAGIC, // Disallow shared libraries and dont align sections
@ -46,14 +49,14 @@ public:
OMAGIC // Disallow shared libraries and dont align sections,
// Mark Text Segment/Data segment RW
};
llvm::Triple getTriple() const { return _triple; }
virtual bool is64Bits() const;
virtual bool isLittleEndian() const;
virtual uint64_t getPageSize() const { return 0x1000; }
OutputMagic getOutputMagic() const { return _outputMagic; }
uint16_t getOutputType() const { return _outputFileType; }
uint16_t getOutputELFType() const { return _outputELFType; }
uint16_t getOutputMachine() const;
bool outputYAML() const { return _outputYAML; }
bool mergeCommonStrings() const { return _mergeCommonStrings; }
virtual uint64_t getBaseAddress() const { return _baseAddress; }
@ -130,13 +133,13 @@ public:
virtual void addPasses(PassManager &pm) const;
void setTriple(llvm::Triple trip) { _triple = trip; }
void setOutputFileType(uint32_t type) { _outputFileType = type; }
void setOutputYAML(bool v) { _outputYAML = v; }
void setNoInhibitExec(bool v) { _noInhibitExec = v; }
void setIsStaticExecutable(bool v) { _isStaticExecutable = v; }
void setMergeCommonStrings(bool v) { _mergeCommonStrings = v; }
void setUseShlibUndefines(bool use) { _useShlibUndefines = use; }
void setOutputELFType(uint32_t type) { _outputELFType = type; }
/// \brief Set the dynamic linker path
void setInterpreter(StringRef dynamicLinker) {
_dynamicLinkerArg = true;
@ -214,12 +217,11 @@ protected:
/// Method to create a internal file for an undefined symbol
virtual std::unique_ptr<File> createUndefinedSymbolFile();
uint16_t _outputFileType; // e.g ET_EXEC
uint16_t _outputELFType; // e.g ET_EXEC
llvm::Triple _triple;
std::unique_ptr<TargetHandlerBase> _targetHandler;
uint64_t _baseAddress;
bool _isStaticExecutable;
bool _outputYAML;
bool _noInhibitExec;
bool _mergeCommonStrings;
bool _runLayoutPass;

View File

@ -24,7 +24,7 @@ LinkingContext::LinkingContext()
_warnIfCoalesableAtomsHaveDifferentLoadName(false),
_printRemainingUndefines(true),
_allowRemainingUndefines(false), _logInputFiles(false),
_allowShlibUndefines(false) {}
_allowShlibUndefines(false), _outputFileType(OutputFileType::Default) {}
LinkingContext::~LinkingContext() {}

View File

@ -154,14 +154,11 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
bool _outputOptionSet = false;
// Create a dynamic executable by default
ctx->setOutputFileType(llvm::ELF::ET_EXEC);
ctx->setOutputELFType(llvm::ELF::ET_EXEC);
ctx->setIsStaticExecutable(false);
ctx->setAllowShlibUndefines(false);
ctx->setUseShlibUndefines(true);
// Set the output file to be a.out
ctx->setOutputPath("a.out");
// Process all the arguments and create Input Elements
for (auto inputArg : *parsedArgs) {
switch (inputArg->getOption().getID()) {
@ -169,16 +166,16 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
ctx->appendLLVMOption(inputArg->getValue());
break;
case OPT_relocatable:
ctx->setOutputFileType(llvm::ELF::ET_REL);
ctx->setOutputELFType(llvm::ELF::ET_REL);
ctx->setPrintRemainingUndefines(false);
ctx->setAllowRemainingUndefines(true);
break;
case OPT_static:
ctx->setOutputFileType(llvm::ELF::ET_EXEC);
ctx->setOutputELFType(llvm::ELF::ET_EXEC);
ctx->setIsStaticExecutable(true);
break;
case OPT_shared:
ctx->setOutputFileType(llvm::ELF::ET_DYN);
ctx->setOutputELFType(llvm::ELF::ET_DYN);
ctx->setAllowShlibUndefines(true);
ctx->setUseShlibUndefines(false);
break;
@ -246,10 +243,8 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
ctx->addFiniFunction(inputArg->getValue());
break;
case OPT_emit_yaml:
if (!_outputOptionSet)
ctx->setOutputPath("-");
ctx->setOutputYAML(true);
case OPT_output_filetype:
ctx->setOutputFileType(inputArg->getValue());
break;
case OPT_no_whole_archive:
@ -333,7 +328,23 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
inputGraph->addInternalFile(ctx->createInternalFiles());
if (ctx->outputYAML())
// Set default output file name if the output file was not
// specified.
if (!_outputOptionSet) {
switch (ctx->outputFileType()) {
case LinkingContext::OutputFileType::YAML:
ctx->setOutputPath("-");
break;
case LinkingContext::OutputFileType::Native:
ctx->setOutputPath("a.native");
break;
default:
ctx->setOutputPath("a.out");
break;
}
}
if (ctx->outputFileType() == LinkingContext::OutputFileType::YAML)
inputGraph->dump(diagnostics);
// Validate the combination of options used.

View File

@ -25,7 +25,6 @@ multiclass dashEq<string opt1, string opt2, string help> {
Alias<!cast<Option>(opt1)>;
}
//===----------------------------------------------------------------------===//
/// Output Kinds
//===----------------------------------------------------------------------===//
@ -223,9 +222,11 @@ def t : Flag<["-"], "t">,
//===----------------------------------------------------------------------===//
def grp_extns : OptionGroup<"opts">,
HelpText<"Extensions">;
def emit_yaml : Flag<["-"], "emit-yaml">,
HelpText<"Write YAML instead of ELF">,
Group<grp_extns>;
def output_filetype: Separate<["--"], "output-filetype">,
HelpText<"Specify what type of output file that lld creates, YAML/Native">,
Group<grp_extns>;
def alias_output_filetype: Joined<["--"], "output-filetype=">,
Alias<output_filetype>;
//===----------------------------------------------------------------------===//
/// Help

View File

@ -36,9 +36,9 @@ public:
ELFLinkingContext::ELFLinkingContext(
llvm::Triple triple, std::unique_ptr<TargetHandlerBase> targetHandler)
: _outputFileType(elf::ET_EXEC), _triple(triple),
: _outputELFType(elf::ET_EXEC), _triple(triple),
_targetHandler(std::move(targetHandler)), _baseAddress(0),
_isStaticExecutable(false), _outputYAML(false), _noInhibitExec(false),
_isStaticExecutable(false), _noInhibitExec(false),
_mergeCommonStrings(false), _runLayoutPass(true),
_useShlibUndefines(false), _dynamicLinkerArg(false),
_noAllowDynamicLibraries(false), _outputMagic(OutputMagic::DEFAULT),
@ -72,7 +72,7 @@ uint16_t ELFLinkingContext::getOutputMachine() const {
}
StringRef ELFLinkingContext::entrySymbolName() const {
if (_outputFileType == elf::ET_EXEC && _entrySymbolName.empty())
if (_outputELFType == elf::ET_EXEC && _entrySymbolName.empty())
return "_start";
return _entrySymbolName;
}
@ -80,12 +80,22 @@ StringRef ELFLinkingContext::entrySymbolName() const {
bool ELFLinkingContext::validateImpl(raw_ostream &diagnostics) {
_elfReader = createReaderELF(*this);
_linkerScriptReader.reset(new ReaderLinkerScript(*this));
_writer = _outputYAML ? createWriterYAML(*this) : createWriterELF(*this);
switch (outputFileType()) {
case LinkingContext::OutputFileType::YAML:
_writer = createWriterYAML(*this);
break;
case LinkingContext::OutputFileType::Native:
llvm_unreachable("Unimplemented");
break;
default:
_writer = createWriterELF(*this);
break;
}
return false;
}
bool ELFLinkingContext::isDynamic() const {
switch (_outputFileType) {
switch (_outputELFType) {
case llvm::ELF::ET_EXEC:
return !_isStaticExecutable;
case llvm::ELF::ET_DYN:

View File

@ -170,7 +170,7 @@ void OutputELFWriter<ELFT>::buildDynamicSymbolTable(const File &file) {
_dynamicTable->addEntry(dyn);
}
StringRef soname = _context.sharedObjectName();
if (!soname.empty() && _context.getOutputType() == llvm::ELF::ET_DYN) {
if (!soname.empty() && _context.getOutputELFType() == llvm::ELF::ET_DYN) {
Elf_Dyn dyn;
dyn.d_tag = DT_SONAME;
dyn.d_un.d_val = _dynamicStringTable->addString(soname);
@ -368,7 +368,7 @@ error_code OutputELFWriter<ELFT>::writeFile(const File &file, StringRef path) {
_elfHeader->e_ident(ELF::EI_DATA, _context.isLittleEndian()
? ELF::ELFDATA2LSB
: ELF::ELFDATA2MSB);
_elfHeader->e_type(_context.getOutputType());
_elfHeader->e_type(_context.getOutputELFType());
_elfHeader->e_machine(_context.getOutputMachine());
if (!_targetHandler.doesOverrideELFHeader()) {

View File

@ -23,7 +23,7 @@ std::unique_ptr<Writer> createWriterELF(const ELFLinkingContext &info) {
// We would set the layout to a dynamic executable layout
// if we came across any shared libraries in the process
switch(info.getOutputType()) {
switch (info.getOutputELFType()) {
case llvm::ELF::ET_EXEC:
if (info.is64Bits()) {
if (info.isLittleEndian())

View File

@ -461,7 +461,7 @@ private:
void elf::X86_64LinkingContext::addPasses(PassManager &pm) const {
switch (_outputFileType) {
switch (_outputELFType) {
case llvm::ELF::ET_EXEC:
if (_isStaticExecutable)
pm.add(std::unique_ptr<Pass>(new StaticGOTPLTPass(*this)));

View File

@ -1,10 +1,10 @@
RUN: lld -flavor gnu -L%p/../elf/Inputs -lfnarchive -emit-yaml --noinhibit-exec 2> %t.err
RUN: lld -flavor gnu -L%p/../elf/Inputs -lfnarchive --output-filetype=yaml --noinhibit-exec 2> %t.err
RUN: FileCheck %s < %t.err
RUN: lld -flavor gnu -L%p/../elf/Inputs --whole-archive -lfnarchive -emit-yaml --noinhibit-exec 2> %t1.err
RUN: lld -flavor gnu -L%p/../elf/Inputs --whole-archive -lfnarchive --output-filetype=yaml --noinhibit-exec 2> %t1.err
RUN: FileCheck %s -check-prefix="WHOLEARCHIVE" < %t1.err
RUN: lld -flavor gnu -L%p/../elf/Inputs --whole-archive --as-needed -lfnarchive -emit-yaml --noinhibit-exec 2> %t2.err
RUN: lld -flavor gnu -L%p/../elf/Inputs --whole-archive --as-needed -lfnarchive --output-filetype=yaml --noinhibit-exec 2> %t2.err
RUN: FileCheck %s -check-prefix="ASNEEDED" < %t2.err
RUN: lld -flavor gnu --sysroot=%p/../elf -L=/Inputs -lfnarchive -emit-yaml --noinhibit-exec 2> %t3.err
RUN: lld -flavor gnu --sysroot=%p/../elf -L=/Inputs -lfnarchive --output-filetype=yaml --noinhibit-exec 2> %t3.err
RUN: FileCheck -check-prefix="SYSROOT" %s < %t3.err
CHECK: Name : {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a

View File

@ -2,4 +2,4 @@
RUN: lld -flavor gnu --help | FileCheck %s
CHECK: --noinhibit-exec
CHECK: -emit-yaml
CHECK: --output-filetype

View File

@ -1,5 +1,5 @@
# RUN: lld -flavor gnu -u undefinedsymbol -e entrysymbol %s -emit-yaml \
# RUN: --noinhibit-exec | FileCheck %s
# RUN: lld -flavor gnu -u undefinedsymbol -e entrysymbol %s \
# RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s
#
# Test that we are able to add undefined atoms from the command line

View File

@ -1,6 +1,6 @@
# This tests GOT's and PLT's for dynamic libraries for Hexagon
RUN: lld -flavor gnu -target hexagon %p/Inputs/dynobj.o \
RUN: -o %t -emit-yaml -shared --noinhibit-exec
RUN: -o %t --output-filetype=yaml -shared --noinhibit-exec
RUN: FileCheck -check-prefix=CHECKGOTPLT %s < %t
- name: __got0

View File

@ -1,5 +1,5 @@
RUN: lld -flavor gnu -target hexagon %p/Inputs/use-shared.hexagon \
RUN: -emit-yaml --noinhibit-exec -o %t2
RUN: --output-filetype=yaml --noinhibit-exec -o %t2
RUN: FileCheck %s < %t2
CHECK: - name: fn3

View File

@ -4,7 +4,7 @@
# in the output ELF.
RUN: lld -flavor gnu -target hexagon %p/Inputs/initfini-option.o \
RUN: -init init -fini fini --noinhibit-exec -emit-yaml -static -o %t
RUN: -init init -fini fini --noinhibit-exec --output-filetype=yaml -static -o %t
RUN: FileCheck %s < %t
CHECK: content: [ 00, 00, 00, 00 ]

View File

@ -1,6 +1,6 @@
# Test that debug info is assigned typeNoAlloc and that the output sections have
# a virtual address of 0.
RUN: lld -flavor gnu -target x86_64 -e main -emit-yaml \
RUN: lld -flavor gnu -target x86_64 -e main --output-filetype=yaml \
RUN: %p/Inputs/debug0.x86-64 %p/Inputs/debug1.x86-64 -o %t
RUN: FileCheck %s -check-prefix YAML < %t

View File

@ -1,6 +1,6 @@
# This tests that lld is not ignoring zero sized sections
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/zerosizedsection.o \
RUN: --noinhibit-exec -emit-yaml -o %t
RUN: --noinhibit-exec --output-filetype=yaml -o %t
RUN: FileCheck %s < %t
CHECK: section-name: .data

View File

@ -1,7 +1,7 @@
# This tests verifies that TLS variables have correct offsets
# when variables the TLS variables are not defined in the program
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/externtls.x86-64 -static \
RUN: -emit-yaml --noinhibit-exec | FileCheck %s -check-prefix=CHECKGOT
RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s -check-prefix=CHECKGOT
- name: __got_tls_extern_tls
CHECKGOT: type: got

View File

@ -4,7 +4,7 @@
# in the output ELF.
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/initfini-option.o \
RUN: -init init -fini fini --noinhibit-exec -emit-yaml -o %t
RUN: -init init -fini fini --noinhibit-exec --output-filetype=yaml -o %t
RUN: FileCheck %s < %t
CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]

View File

@ -4,7 +4,7 @@
# in the output ELF.
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/initfini.o \
RUN: --noinhibit-exec -emit-yaml -o %t
RUN: --noinhibit-exec --output-filetype=yaml -o %t
RUN: FileCheck %s < %t
CHECK: - type: data

View File

@ -3,7 +3,7 @@
# Any typeZeroFill content wouldnot have space reserved in the file to store
# its content
RUN: lld -flavor gnu -target x86_64 %p/Inputs/largebss.o -emit-yaml --noinhibit-exec | FileCheck %s
RUN: lld -flavor gnu -target x86_64 %p/Inputs/largebss.o --output-filetype=yaml --noinhibit-exec | FileCheck %s
CHECK: - name: largecommon

View File

@ -2,7 +2,7 @@
# properly
RUN: lld -flavor gnu -target x86_64 %p/Inputs/multiweaksyms.o \
RUN: --noinhibit-exec -static -emit-yaml -o %t
RUN: --noinhibit-exec -static --output-filetype=yaml -o %t
RUN: FileCheck %s -check-prefix=WEAKSYMS < %t
WEAKSYMS: - ref-name: [[SYMA:[-a-zA-Z0-9_]+]]

View File

@ -3,7 +3,7 @@ RUN: lld -flavor gnu -target x86_64 %p/Inputs/multi-weak.o \
RUN: %p/Inputs/multi-ovrd.o -o %t -e main --noinhibit-exec
RUN: llvm-nm -n %t | FileCheck -check-prefix=WEAKORDER %s
RUN: lld -flavor gnu -target x86_64 %p/Inputs/multi-weak.o \
RUN: %p/Inputs/multi-ovrd.o -emit-yaml -o %t2 --noinhibit-exec
RUN: %p/Inputs/multi-ovrd.o --output-filetype=yaml -o %t2 --noinhibit-exec
RUN: FileCheck -check-prefix=WEAKATOMSORDER %s < %t2
WEAKORDER: {{[0-9a-f]+}} T f

View File

@ -1,7 +1,7 @@
# Test for weak symbol getting overridden
RUN: lld -flavor gnu -target x86_64 %p/Inputs/multi-weak.o -o %t --noinhibit-exec
RUN: llvm-nm -n %t | FileCheck -check-prefix=WEAKORDER %s
RUN: lld -flavor gnu -target x86_64 %p/Inputs/multi-weak.o -o %t2 -emit-yaml --noinhibit-exec
RUN: lld -flavor gnu -target x86_64 %p/Inputs/multi-weak.o -o %t2 --output-filetype=yaml --noinhibit-exec
RUN: FileCheck -check-prefix=WEAKATOMSORDER %s < %t2
WEAKORDER: {{[0-9a-f]+}} T fn

View File

@ -1,7 +1,7 @@
# This testcase tests the behaviour of the layoutpass so that the atoms that
# appear by their override take preference before proceeding to default behaviour
RUN: lld -flavor gnu -target x86_64 %p/Inputs/rwint.o \
RUN: %p/Inputs/constint.o -emit-yaml -o %t --noinhibit-exec
RUN: %p/Inputs/constint.o --output-filetype=yaml -o %t --noinhibit-exec
RUN: FileCheck %s -check-prefix=CHECKORDER < %t
CHECKORDER: - name: b

View File

@ -1,6 +1,6 @@
# This tests that we are able to properly set the sectionChoice for DefinedAtoms
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/zerosizedsection.o \
RUN: --noinhibit-exec -o %t -emit-yaml
RUN: --noinhibit-exec -o %t --output-filetype=yaml
RUN: FileCheck %s < %t
CHECK-NOT: section-choice: sectionCustomRequired

View File

@ -3,7 +3,7 @@ RUN: lld -flavor gnu -target x86_64 %p/Inputs/weak.o %p/Inputs/ovrd.o \
RUN: -o %t --noinhibit-exec
RUN: llvm-nm %t | FileCheck -check-prefix=WEAKORDER %s
RUN: lld -flavor gnu -target x86_64 %p/Inputs/weak.o \
RUN: %p/Inputs/ovrd.o -o %t2 -emit-yaml --noinhibit-exec
RUN: %p/Inputs/ovrd.o -o %t2 --output-filetype=yaml --noinhibit-exec
RUN: FileCheck -check-prefix=WEAKATOMSORDER %s < %t2
WEAKORDER: {{[0-9a-c]+}} T f

View File

@ -3,7 +3,7 @@ RUN: lld -flavor gnu -target x86_64 %p/Inputs/weak-zero-sized.o -o %t \
RUN: --noinhibit-exec
RUN: llvm-nm %t | FileCheck -check-prefix=WEAKORDER %s
RUN: lld -flavor gnu -target x86_64 %p/Inputs/weak-zero-sized.o \
RUN: -emit-yaml -o %t2 --noinhibit-exec
RUN: --output-filetype=yaml -o %t2 --noinhibit-exec
RUN: FileCheck -check-prefix=WEAKATOMSORDER %s < %t2
WEAKORDER: 004001a4 T _start

View File

@ -2,7 +2,7 @@
# an input YAML from a previous link
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/initfini.o \
RUN: --noinhibit-exec -emit-yaml -o %t.objtxt
RUN: --noinhibit-exec --output-filetype=yaml -o %t.objtxt
RUN: lld -flavor gnu -target x86_64-linux %t.objtxt \
RUN: --noinhibit-exec -o %t1
RUN: llvm-readobj -sections %t1 | FileCheck %s -check-prefix=SECTIONS

View File

@ -9,7 +9,7 @@
# built using: "gcc -m32"
#
RUN: lld -flavor gnu -emit-yaml -r %p/Inputs/abs-test.i386 | FileCheck -check-prefix=YAML %s
RUN: lld -flavor gnu --output-filetype=yaml -r %p/Inputs/abs-test.i386 | FileCheck -check-prefix=YAML %s
YAML: absolute-atoms:
YAML: - name: absLocalSymbol

View File

@ -24,7 +24,7 @@
# gcc -c main.c fn.c fn1.c
RUN: lld -flavor gnu -target x86_64-linux -e main %p/Inputs/mainobj.x86_64 \
RUN: --whole-archive %p/Inputs/libfnarchive.a --no-whole-archive -emit-yaml \
RUN: --whole-archive %p/Inputs/libfnarchive.a --no-whole-archive --output-filetype=yaml \
RUN: | FileCheck -check-prefix FORCELOAD %s
FORCELOAD: defined-atoms:

View File

@ -23,7 +23,7 @@
# }
# gcc -c main.c fn.c fn1.c
RUN: lld -flavor gnu -emit-yaml -r %p/Inputs/mainobj.x86_64 %p/Inputs/libfnarchive.a | FileCheck -check-prefix NOFORCELOAD %s
RUN: lld -flavor gnu --output-filetype=yaml -r %p/Inputs/mainobj.x86_64 %p/Inputs/libfnarchive.a | FileCheck -check-prefix NOFORCELOAD %s
NOFORCELOAD: defined-atoms:
NOFORCELOAD: - name: fn

View File

@ -1,4 +1,4 @@
RUN: lld -flavor gnu -target hexagon -static -emit-yaml \
RUN: lld -flavor gnu -target hexagon -static --output-filetype=yaml \
RUN: %p/Inputs/branch-test.hexagon %p/Inputs/target-test.hexagon --noinhibit-exec | FileCheck %s -check-prefix hexagon-yaml
RUN: lld -flavor gnu -target hexagon -e target -o %t1 \
RUN: %p/Inputs/branch-test.hexagon %p/Inputs/target-test.hexagon --noinhibit-exec

View File

@ -1,9 +1,9 @@
# This tests the basic functionality of ordering data and functions as they
# appear in the inputs
RUN: lld -flavor gnu -target i386 -e global_func --noinhibit-exec -emit-yaml \
RUN: lld -flavor gnu -target i386 -e global_func --noinhibit-exec --output-filetype=yaml \
RUN: %p/Inputs/object-test.elf-i386 -o %t
RUN: FileCheck %s -check-prefix ELF-i386 < %t
RUN: lld -flavor gnu -target hexagon -e global_func --noinhibit-exec -emit-yaml \
RUN: lld -flavor gnu -target hexagon -e global_func --noinhibit-exec --output-filetype=yaml \
RUN: %p/Inputs/object-test.elf-hexagon -o %t1
RUN: FileCheck %s -check-prefix ELF-hexagon < %t1

View File

@ -3,7 +3,7 @@ RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \
RUN: %p/Inputs/shared.so-x86-64 -o %t -e main --allow-shlib-undefined \
RUN: -rpath /l1:/l2 -rpath /l3
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \
RUN: %p/Inputs/shared.so-x86-64 -emit-yaml -o %t2 --allow-shlib-undefined \
RUN: %p/Inputs/shared.so-x86-64 --output-filetype=yaml -o %t2 --allow-shlib-undefined \
RUN: --noinhibit-exec
RUN: llvm-objdump -p %t >> %t2
RUN: llvm-readobj -s -dyn-symbols -dynamic-table %t >> %t2

View File

@ -1,5 +1,5 @@
# This test checks that GOTPCREL entries are being handled properly
RUN: lld -flavor gnu -target x86_64-linux -static -e main -emit-yaml \
RUN: lld -flavor gnu -target x86_64-linux -static -e main --output-filetype=yaml \
RUN: --noinhibit-exec %p/Inputs/gotpcrel.x86-64 \
RUN: | FileCheck %s -check-prefix=YAML

View File

@ -1,9 +1,9 @@
# This test checks that IRELATIVE relocations are created for symbols that
# need relocation even for static links.
RUN: lld -flavor gnu -target x86_64-linux -emit-yaml -r \
RUN: lld -flavor gnu -target x86_64-linux --output-filetype=yaml -r \
RUN: %p/Inputs/ifunc.x86-64 | FileCheck %s
RUN: lld -flavor gnu -target x86_64-linux -emit-yaml --noinhibit-exec \
RUN: lld -flavor gnu -target x86_64-linux --output-filetype=yaml --noinhibit-exec \
RUN: %p/Inputs/ifunc.x86-64 %p/Inputs/ifunc.cpp.x86-64 \
RUN: | FileCheck %s --check-prefix=PLT

View File

@ -1,5 +1,5 @@
# The test checks for mergeable strings that appear in the object file
RUN: lld -flavor gnu --merge-strings -emit-yaml %p/Inputs/constants-merge.x86-64 --noinhibit-exec | FileCheck -check-prefix=mergeAtoms %s
RUN: lld -flavor gnu --merge-strings --output-filetype=yaml %p/Inputs/constants-merge.x86-64 --noinhibit-exec | FileCheck -check-prefix=mergeAtoms %s
mergeAtoms: - ref-name: [[CONSTANT:[-a-zA-Z0-9_]+]]
mergeAtoms: type: constant

View File

@ -1,6 +1,6 @@
# ELF files can have mergeable strings which are global!, treat them as global
# defined atoms
RUN: lld -flavor gnu -emit-yaml %p/Inputs/globalconst.o.x86-64 \
RUN: lld -flavor gnu --output-filetype=yaml %p/Inputs/globalconst.o.x86-64 \
RUN: --noinhibit-exec | FileCheck -check-prefix=globalatoms %s
globalatoms: - name: mystr

View File

@ -1,4 +1,4 @@
RUN: lld -flavor gnu -target hexagon -emit-yaml %p/Inputs/quickdata-test.elf-hexagon \
RUN: lld -flavor gnu -target hexagon --output-filetype=yaml %p/Inputs/quickdata-test.elf-hexagon \
RUN: --noinhibit-exec | FileCheck %s -check-prefix hexagon
hexagon: - name: init

View File

@ -1,4 +1,4 @@
RUN: lld -flavor gnu --merge-strings -r -emit-yaml %p/Inputs/reloc-test.elf-i386 | FileCheck %s -check-prefix ELF-i386
RUN: lld -flavor gnu --merge-strings -r --output-filetype=yaml %p/Inputs/reloc-test.elf-i386 | FileCheck %s -check-prefix ELF-i386
ELF-i386: defined-atoms:
ELF-i386: - ref-name: [[STRNAMEA:[-a-zA-Z0-9_]+]]

View File

@ -1,6 +1,6 @@
# This tests verifies that TLS variables have correct offsets
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 -static \
RUN: -emit-yaml --noinhibit-exec | FileCheck %s -check-prefix=YAML
RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s -check-prefix=YAML
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 -o %t \
RUN: --noinhibit-exec -e main -static && llvm-objdump -d %t | FileCheck %s

View File

@ -1,5 +1,5 @@
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/relocs-dynamic.x86-64 \
RUN: -emit-yaml --noinhibit-exec | FileCheck %s
RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s
path: <linker-internal>
defined-atoms:

View File

@ -1,7 +1,7 @@
# Checks that linking an object file with a shared object creates the necessary
# PLT/GOT Entries
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared.x86-64 \
RUN: %p/Inputs/shared.so-x86-64 -emit-yaml -o %t1 --noinhibit-exec
RUN: %p/Inputs/shared.so-x86-64 --output-filetype=yaml -o %t1 --noinhibit-exec
RUN: FileCheck %s < %t1
// Don't check the GOT and PLT names as they are only present in assert builds.

View File

@ -18,7 +18,7 @@
#
# Assembled with: "as --32"
RUN: lld -flavor gnu -target i386 -e back -emit-yaml %p/Inputs/reloc-xb.x86 %p/Inputs/reloc-xt.x86 | FileCheck %s -check-prefix x86-yaml
RUN: lld -flavor gnu -target i386 -e back --output-filetype=yaml %p/Inputs/reloc-xb.x86 %p/Inputs/reloc-xt.x86 | FileCheck %s -check-prefix x86-yaml
x86-yaml: - name: back
x86-yaml: scope: global

View File

@ -2,7 +2,7 @@ RUN: lld -flavor gnu -target x86_64-linux -o %t1 %p/Inputs/relocs.x86-64 \
RUN: -e _start -static
RUN: llvm-objdump -d %t1 | FileCheck %s -check-prefix=RELOCS
RUN: lld -flavor gnu -target x86_64-linux -emit-yaml -e _start -static \
RUN: lld -flavor gnu -target x86_64-linux --output-filetype=yaml -e _start -static \
RUN: %p/Inputs/relocs.x86-64 | FileCheck %s -check-prefix=X86_64
RELOCS: ELF64-x86-64

View File

@ -39,16 +39,18 @@ TEST_F(GnuLdParserTest, Basic) {
EXPECT_EQ("a.out", linkingContext()->outputPath());
EXPECT_EQ(1, inputFileCount());
EXPECT_EQ("infile.o", inputFile(0));
EXPECT_FALSE(_context->outputYAML());
EXPECT_FALSE(_context->outputFileType() ==
LinkingContext::OutputFileType::YAML);
}
TEST_F(GnuLdParserTest, ManyOptions) {
EXPECT_FALSE(parse("ld", "-entry", "_start", "-o", "outfile",
"-emit-yaml", "infile.o", nullptr));
"--output-filetype=yaml", "infile.o", nullptr));
EXPECT_NE(linkingContext(), nullptr);
EXPECT_EQ("outfile", linkingContext()->outputPath());
EXPECT_EQ("_start", linkingContext()->entrySymbolName());
EXPECT_TRUE(_context->outputYAML());
EXPECT_TRUE(_context->outputFileType() ==
LinkingContext::OutputFileType::YAML);
}
} // end anonymous namespace