Skip to content

Commit fcc1594

Browse files
committed
[LFI] Add Clang driver toolchain for LFI
1 parent 2b46bc0 commit fcc1594

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
412412
Builder.defineMacro("__aarch64__");
413413
}
414414

415+
if (getTriple().isLFI())
416+
Builder.defineMacro("__LFI__");
417+
415418
// Inline assembly supports AArch64 flag outputs.
416419
Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
417420

clang/lib/Driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ add_clang_library(clangDriver
6565
ToolChains/Hexagon.cpp
6666
ToolChains/HLSL.cpp
6767
ToolChains/Hurd.cpp
68+
ToolChains/LFILinux.cpp
6869
ToolChains/Linux.cpp
6970
ToolChains/Managarm.cpp
7071
ToolChains/MipsLinux.cpp

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "ToolChains/Haiku.h"
3030
#include "ToolChains/Hexagon.h"
3131
#include "ToolChains/Hurd.h"
32+
#include "ToolChains/LFILinux.h"
3233
#include "ToolChains/Lanai.h"
3334
#include "ToolChains/Linux.h"
3435
#include "ToolChains/MSP430.h"
@@ -6864,6 +6865,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
68646865
TC = std::make_unique<toolchains::OHOS>(*this, Target, Args);
68656866
else if (Target.isWALI())
68666867
TC = std::make_unique<toolchains::WebAssembly>(*this, Target, Args);
6868+
else if (Target.isLFI())
6869+
TC = std::make_unique<toolchains::LFILinuxToolChain>(*this, Target, Args);
68676870
else
68686871
TC = std::make_unique<toolchains::Linux>(*this, Target, Args);
68696872
break;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===-- LFILinux.cpp - LFI ToolChain Implementations ------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, 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+
9+
#include "LFILinux.h"
10+
11+
using namespace clang::driver::toolchains;
12+
using namespace llvm::opt;
13+
14+
void LFILinuxToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
15+
ArgStringList &CmdArgs) const {
16+
switch (GetCXXStdlibType(Args)) {
17+
case ToolChain::CST_Libcxx:
18+
CmdArgs.push_back("-lc++");
19+
if (Args.hasArg(options::OPT_fexperimental_library))
20+
CmdArgs.push_back("-lc++experimental");
21+
CmdArgs.push_back("-lc++abi");
22+
break;
23+
case ToolChain::CST_Libstdcxx:
24+
CmdArgs.push_back("-lstdc++");
25+
break;
26+
}
27+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===--- LFILinux.h - LFI ToolChain Implementations -------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, 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+
9+
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LFI_LINUX_H
10+
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LFI_LINUX_H
11+
12+
#include "Linux.h"
13+
14+
namespace clang {
15+
namespace driver {
16+
namespace toolchains {
17+
18+
class LLVM_LIBRARY_VISIBILITY LFILinuxToolChain : public Linux {
19+
public:
20+
LFILinuxToolChain(const Driver &D, const llvm::Triple &Triple,
21+
const llvm::opt::ArgList &Args)
22+
: Linux(D, Triple, Args) {
23+
ExtraOpts.push_back("-z");
24+
ExtraOpts.push_back("separate-code");
25+
}
26+
27+
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
28+
llvm::opt::ArgStringList &CmdArgs) const override;
29+
};
30+
31+
} // end namespace toolchains
32+
} // end namespace driver
33+
} // end namespace clang
34+
35+
#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LFI_LINUX_H

0 commit comments

Comments
 (0)