Skip to content

Commit a4deb80

Browse files
committed
Revert "Reapply "[Driver][OHOS] Fix lld link issue for OHOS (#118192)" (#120159)"
This reverts commit bd154e8. Test fails with -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF, see #120159 (comment)
1 parent d622b66 commit a4deb80

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

clang/lib/Driver/ToolChains/OHOS.cpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "llvm/ProfileData/InstrProf.h"
2020
#include "llvm/Support/FileSystem.h"
2121
#include "llvm/Support/Path.h"
22-
#include "llvm/Support/ScopedPrinter.h"
2322
#include "llvm/Support/VirtualFileSystem.h"
23+
#include "llvm/Support/ScopedPrinter.h"
2424

2525
using namespace clang::driver;
2626
using namespace clang::driver::toolchains;
@@ -58,9 +58,11 @@ static bool findOHOSMuslMultilibs(const Driver &D,
5858
return false;
5959
}
6060

61-
static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC,
62-
const llvm::Triple &TargetTriple, StringRef Path,
63-
const ArgList &Args, DetectedMultilibs &Result) {
61+
static bool findOHOSMultilibs(const Driver &D,
62+
const ToolChain &TC,
63+
const llvm::Triple &TargetTriple,
64+
StringRef Path, const ArgList &Args,
65+
DetectedMultilibs &Result) {
6466
Multilib::flags_list Flags;
6567
bool IsA7 = false;
6668
if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
@@ -170,7 +172,8 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
170172
Paths);
171173
}
172174

173-
ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const {
175+
ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
176+
const ArgList &Args) const {
174177
if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) {
175178
StringRef Value = A->getValue();
176179
if (Value != "compiler-rt")
@@ -181,19 +184,20 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const {
181184
return ToolChain::RLT_CompilerRT;
182185
}
183186

184-
ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const {
187+
ToolChain::CXXStdlibType
188+
OHOS::GetCXXStdlibType(const ArgList &Args) const {
185189
if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
186190
StringRef Value = A->getValue();
187191
if (Value != "libc++")
188192
getDriver().Diag(diag::err_drv_invalid_stdlib_name)
189-
<< A->getAsString(Args);
193+
<< A->getAsString(Args);
190194
}
191195

192196
return ToolChain::CST_Libcxx;
193197
}
194198

195199
void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
196-
ArgStringList &CC1Args) const {
200+
ArgStringList &CC1Args) const {
197201
const Driver &D = getDriver();
198202
const llvm::Triple &Triple = getTriple();
199203
std::string SysRoot = computeSysRoot();
@@ -254,7 +258,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
254258
}
255259

256260
void OHOS::AddCXXStdlibLibArgs(const ArgList &Args,
257-
ArgStringList &CmdArgs) const {
261+
ArgStringList &CmdArgs) const {
258262
switch (GetCXXStdlibType(Args)) {
259263
case ToolChain::CST_Libcxx:
260264
CmdArgs.push_back("-lc++");
@@ -287,8 +291,7 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
287291

288292
// First try the triple passed to driver as --target=<triple>.
289293
P.assign(D.ResourceDir);
290-
llvm::sys::path::append(P, "lib", D.getTargetTriple(),
291-
SelectedMultilib.gccSuffix());
294+
llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix());
292295
Paths.push_back(P.c_str());
293296

294297
// Second try the normalized triple.
@@ -337,20 +340,26 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const {
337340

338341
std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component,
339342
FileType Type) const {
340-
std::string CRTBasename =
341-
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
342-
343343
SmallString<128> Path(getDriver().ResourceDir);
344344
llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()),
345-
SelectedMultilib.gccSuffix(), CRTBasename);
346-
if (getVFS().exists(Path))
347-
return std::string(Path);
348-
349-
std::string NewPath = ToolChain::getCompilerRT(Args, Component, Type);
350-
if (getVFS().exists(NewPath))
351-
return NewPath;
352-
353-
return std::string(Path);
345+
SelectedMultilib.gccSuffix());
346+
const char *Prefix =
347+
Type == ToolChain::FT_Object ? "" : "lib";
348+
const char *Suffix;
349+
switch (Type) {
350+
case ToolChain::FT_Object:
351+
Suffix = ".o";
352+
break;
353+
case ToolChain::FT_Static:
354+
Suffix = ".a";
355+
break;
356+
case ToolChain::FT_Shared:
357+
Suffix = ".so";
358+
break;
359+
}
360+
llvm::sys::path::append(
361+
Path, Prefix + Twine("clang_rt.") + Component + Suffix);
362+
return static_cast<std::string>(Path.str());
354363
}
355364

356365
void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
@@ -387,7 +396,7 @@ SanitizerMask OHOS::getSupportedSanitizers() const {
387396

388397
// TODO: Make a base class for Linux and OHOS and move this there.
389398
void OHOS::addProfileRTLibs(const llvm::opt::ArgList &Args,
390-
llvm::opt::ArgStringList &CmdArgs) const {
399+
llvm::opt::ArgStringList &CmdArgs) const {
391400
// Add linker option -u__llvm_profile_runtime to cause runtime
392401
// initialization module to be linked in.
393402
if (needsProfileRT(Args))
@@ -404,8 +413,7 @@ ToolChain::path_list OHOS::getArchSpecificLibPaths() const {
404413
return Paths;
405414
}
406415

407-
ToolChain::UnwindLibType
408-
OHOS::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
416+
ToolChain::UnwindLibType OHOS::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
409417
if (Args.getLastArg(options::OPT_unwindlib_EQ))
410418
return Generic_ELF::GetUnwindLibType(Args);
411419
return GetDefaultUnwindLibType();

0 commit comments

Comments
 (0)