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