[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-24 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay commented:

We need a test to clang/test/Driver/ohos.c similar to linux-ld.c 
`clang_rt.crtbegin.o`.

You can add UNSUPPORTED: system-windows to ohos.c so that we don't need 
backslashes.



https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-17 Thread Nico Weber via cfe-commits

nico wrote:

Aha! Yes, that bot does do incremental builds. (As do many devs.)

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-16 Thread Peng Huang via cfe-commits

phuang wrote:

I still cannot repro the problem locally, but base on th log in 
http://45.33.8.238/linux/155432/step_6.txt . Looks like clang tries to search 
runtime library at 
"/usr/local/google/home/thakis/src/llvm-project/out/gn/lib/clang/20/lib/linux/libclang_rt.builtins-x86_64.a"
 (It is the OldPath in 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChain.cpp#L771).
 Not sure why the file does exist on the gn bot. Maybe it is not a clean build. 
I workarounded the problem by adding "-ohos" suffix in the runtime library like 
android. 

@kpdev  @nico , could you please take a look the new PR 
https://github.com/llvm/llvm-project/pull/120159

Thanks.

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-16 Thread Peng Huang via cfe-commits

phuang wrote:

I found out how to run the test, but I cannot reproduce the problem with my 
change. I run the test with below steps:

1: `cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS="clang;lld"`
2: `ninja -C build`
3: `./build/bin/llvm-lit  ./clang/test/Driver/ohos.c -a -v
`

I checked the compile log at http://45.33.8.238/linux/155432/step_3.txt , it 
only compiles around 1000 files. But in my tree, it  compiles 5329 files. @nico 
do you know why? what's your build steps? 



https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-16 Thread Peng Huang via cfe-commits

phuang wrote:

> are there any prerequisite changes elsewhere that I need to port to it?

HI @nico, how to repro the problem locally? Is there a doc for it? or could you 
please share steps? thanks

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-14 Thread Pavel Kosov via cfe-commits

kpdev wrote:

@phuang @nico Reverted. I will reland it after investigating the issue with GN 
build bot 

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-13 Thread Nico Weber via cfe-commits

nico wrote:

If all other bots are happy, then I'm doing something wrong probably. If you 
don't mind reverting, it'd be nice since then I can catch other, actual 
problems, with the bot, but it's not a requirement.

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-13 Thread Pavel Kosov via cfe-commits

kpdev wrote:

@nico Should I revert this patch for now?

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-13 Thread Peng Huang via cfe-commits

phuang wrote:

I am out of town this week. I will take a look when I return. 

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-13 Thread Pavel Kosov via cfe-commits

kpdev wrote:

Hm... No, it should work. @phuang May I kindly ask you to take a look at this 
issue? http://45.33.8.238/linux/155432/step_6.txt 

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-13 Thread Nico Weber via cfe-commits

nico wrote:

This broke check-clang on my linux box: 
http://45.33.8.238/linux/155432/step_6.txt

That bot uses the GN build – are there any prerequisite changes elsewhere that 
I need to port to it?

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-12 Thread Pavel Kosov via cfe-commits

kpdev wrote:

Agree. Tests would be useful here. Thanks for mentioning it

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-12 Thread Fangrui Song via cfe-commits

MaskRay wrote:

In general, functional changes need tests. When the initial 
https://reviews.llvm.org/D145227 landed, I did not have a chance to look, and 
the tests may have gap. When adding new functionality, ensure that the test 
coverage gets improved.

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-12 Thread via cfe-commits

github-actions[bot] wrote:



@phuang Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-12 Thread Pavel Kosov via cfe-commits

https://github.com/kpdev closed https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-09 Thread Peng Huang via cfe-commits

phuang wrote:

> LGTM

Could you please help merge the PR? I don't see how to do it from my side. 
Thanks.

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-08 Thread Peng Huang via cfe-commits

phuang wrote:

Thanks for reviewing it.


https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-08 Thread Pavel Kosov via cfe-commits

kpdev wrote:

LGTM

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-07 Thread Peng Huang via cfe-commits

https://github.com/phuang updated 
https://github.com/llvm/llvm-project/pull/118192

>From 206f8f800df7e51648ec00b110f2437dca5a3ff6 Mon Sep 17 00:00:00 2001
From: Peng Huang 
Date: Tue, 15 Oct 2024 13:39:03 -0400
Subject: [PATCH 1/2] Fix build error for OHOS

For ohos targets, libclang_rt.builtins.a, clang_rt.crtbegin.o and
clang_rt.crtend.o are installed in
clang/20/lib/${arch}-unknown-linux-ohos. However OHOS toolchain
search them in clang/20/lib/${arch}-linux-ohos folder. It causes
link error. Fix the problem by seaching both folders.
---
 clang/lib/Driver/ToolChains/OHOS.cpp | 60 
 1 file changed, 26 insertions(+), 34 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp 
b/clang/lib/Driver/ToolChains/OHOS.cpp
index 6e1a09ae908b2f..723c891d2a89ca 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -19,8 +19,8 @@
 #include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
@@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D,
   return false;
 }
 
-static bool findOHOSMultilibs(const Driver &D,
-  const ToolChain &TC,
-  const llvm::Triple &TargetTriple,
-  StringRef Path, const ArgList &Args,
-  DetectedMultilibs &Result) {
+static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC,
+  const llvm::Triple &TargetTriple, StringRef Path,
+  const ArgList &Args, DetectedMultilibs &Result) {
   Multilib::flags_list Flags;
   bool IsA7 = false;
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
@@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
   Paths);
 }
 
-ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
-const ArgList &Args) const {
+ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const {
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) {
 StringRef Value = A->getValue();
 if (Value != "compiler-rt")
@@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
   return ToolChain::RLT_CompilerRT;
 }
 
-ToolChain::CXXStdlibType
-OHOS::GetCXXStdlibType(const ArgList &Args) const {
+ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const {
   if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
 StringRef Value = A->getValue();
 if (Value != "libc++")
   getDriver().Diag(diag::err_drv_invalid_stdlib_name)
-<< A->getAsString(Args);
+  << A->getAsString(Args);
   }
 
   return ToolChain::CST_Libcxx;
 }
 
 void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
-ArgStringList &CC1Args) const {
+ ArgStringList &CC1Args) const {
   const Driver &D = getDriver();
   const llvm::Triple &Triple = getTriple();
   std::string SysRoot = computeSysRoot();
@@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList 
&DriverArgs,
 }
 
 void OHOS::AddCXXStdlibLibArgs(const ArgList &Args,
-  ArgStringList &CmdArgs) const {
+   ArgStringList &CmdArgs) const {
   switch (GetCXXStdlibType(Args)) {
   case ToolChain::CST_Libcxx:
 CmdArgs.push_back("-lc++");
@@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
 
   // First try the triple passed to driver as --target=.
   P.assign(D.ResourceDir);
-  llvm::sys::path::append(P, "lib", D.getTargetTriple(), 
SelectedMultilib.gccSuffix());
+  llvm::sys::path::append(P, "lib", D.getTargetTriple(),
+  SelectedMultilib.gccSuffix());
   Paths.push_back(P.c_str());
 
   // Second try the normalized triple.
@@ -340,26 +337,20 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) 
const {
 
 std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component,
 FileType Type) const {
+  std::string CRTBasename =
+  buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+
   SmallString<128> Path(getDriver().ResourceDir);
   llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()),
-  SelectedMultilib.gccSuffix());
-  const char *Prefix =
-  Type == ToolChain::FT_Object ? "" : "lib";
-  const char *Suffix;
-  switch (Type) {
-  case ToolChain::FT_Object:
-Suffix = ".o";
-break;
-  case ToolChain::FT_Static:
-Suffix = ".a";
-break;
-  case ToolChain::FT_Shared:
-Suffix = ".so";
-break;
-  }
-  llvm::sys::path::append(
-  Path, Pre

[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-07 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 6568ceb9fa1c49383b2fa102a04fd8fd3af01491 
206f8f800df7e51648ec00b110f2437dca5a3ff6 --extensions cpp -- 
clang/lib/Driver/ToolChains/OHOS.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp 
b/clang/lib/Driver/ToolChains/OHOS.cpp
index 723c891d2a..c9a532771b 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -344,11 +344,11 @@ std::string OHOS::getCompilerRT(const ArgList &Args, 
StringRef Component,
   llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()),
   SelectedMultilib.gccSuffix(), CRTBasename);
   if (getVFS().exists(Path))
-  return std::string(Path);
+return std::string(Path);
 
   std::string NewPath = ToolChain::getCompilerRT(Args, Component, Type);
   if (getVFS().exists(NewPath))
-  return NewPath;
+return NewPath;
 
   return std::string(Path);
 }

``




https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-07 Thread Pavel Kosov via cfe-commits

kpdev wrote:

@phuang Hi! Thank you for the patch. Will take a look in the nearest pair of 
days

https://github.com/llvm/llvm-project/pull/118192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits