brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 0502754 Raw
38 lines · cpp
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-exception6//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 drivers10// would return a failure. When using LLD as a library, any driver can be11// linked into your application.12//===----------------------------------------------------------------------===//13 14#include "lld/Common/Driver.h"15#include "gmock/gmock.h"16 17LLD_HAS_DRIVER(elf)18 19static 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 26TEST(AsLib, SomeDrivers) {27  // When this flag is on, we actually need the MinGW driver library, not the28  // ELF one. Here our test only covers the case where the ELF driver is linked29  // into the unit test binary.30#ifndef LLD_DEFAULT_LD_LLD_IS_MINGW31  EXPECT_TRUE(lldInvoke("ld.lld")); // ELF32#endif33  // These drivers are not linked in this unit test.34  EXPECT_FALSE(lldInvoke("ld64.lld")); // Mach-O35  EXPECT_FALSE(lldInvoke("lld-link")); // COFF36  EXPECT_FALSE(lldInvoke("wasm-ld"));  // Wasm37}38