| 1 |
//===- SomeDrivers.cpp ------------------------------------------*- C++ -*-===// |
| 2 |
// |
| 3 |
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// In this test we showcase the fact that only one LLD driver can be invoked - |
| 9 |
// the ELF driver that was linked in the test binary. Calling other drivers |
| 10 |
// would return a failure. When using LLD as a library, any driver can be |
| 11 |
// linked into your application. |
| 12 |
//===----------------------------------------------------------------------===// |
| 13 |
|
| 14 |
#include "lld/Common/Driver.h" |
| 15 |
#include "gmock/gmock.h" |
| 16 |
|
| 17 |
LLD_HAS_DRIVER(elf) |
| 18 |
|
| 19 |
static bool lldInvoke(const char *lldExe) { |
| 20 |
std::vector<const char *> args{lldExe, "--version"}; |
| 21 |
lld::Result s = lld::lldMain(args, llvm::outs(), llvm::errs(), |
| 22 |
{{lld::Gnu, &lld::elf::link}}); |
| 23 |
return !s.retCode && s.canRunAgain; |
| 24 |
} |
| 25 |
|
| 26 |
TEST(AsLib, SomeDrivers) { |
| 27 |
// When this flag is on, we actually need the MinGW driver library, not the |
| 28 |
// ELF one. Here our test only covers the case where the ELF driver is linked |
| 29 |
// into the unit test binary. |
| 30 |
#ifndef LLD_DEFAULT_LD_LLD_IS_MINGW |
| 31 |
EXPECT_TRUE(lldInvoke("ld.lld")); // ELF |
| 32 |
#endif |
| 33 |
// These drivers are not linked in this unit test. |
| 34 |
EXPECT_FALSE(lldInvoke("ld64.lld")); // Mach-O |
| 35 |
EXPECT_FALSE(lldInvoke("lld-link")); // COFF |
| 36 |
EXPECT_FALSE(lldInvoke("wasm-ld")); // Wasm |
| 37 |
} |