Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,14 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::loongarch64:
switch (os) {
case llvm::Triple::Linux:
return std::make_unique<LinuxTargetInfo<LoongArch64TargetInfo>>(Triple,
Opts);
switch (Triple.getEnvironment()) {
default:
return std::make_unique<LinuxTargetInfo<LoongArch64TargetInfo>>(Triple,
Opts);
case llvm::Triple::OpenHOS:
return std::make_unique<OHOSTargetInfo<LoongArch64TargetInfo>>(Triple,
Opts);
}
case llvm::Triple::FreeBSD:
return std::make_unique<FreeBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
Opts);
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Driver/ToolChains/OHOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ std::string OHOS::getMultiarchTriple(const llvm::Triple &T) const {
return "x86_64-linux-ohos";
case llvm::Triple::aarch64:
return "aarch64-linux-ohos";
case llvm::Triple::loongarch64:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No loongarch32 addition here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.
Just on loongarch64.

return "loongarch64-linux-ohos";
}
return T.str();
}
Expand Down Expand Up @@ -368,7 +370,9 @@ void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
CmdArgs.push_back("-z");
CmdArgs.push_back("relro");
CmdArgs.push_back("-z");
CmdArgs.push_back("max-page-size=4096");
CmdArgs.push_back(getArch() == llvm::Triple::loongarch64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be tested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test in the latest patch. Thanks!

? "max-page-size=16384"
: "max-page-size=4096");
// .gnu.hash section is not compatible with the MIPS target
if (getArch() != llvm::Triple::mipsel)
CmdArgs.push_back("--hash-style=both");
Expand Down
21 changes: 20 additions & 1 deletion clang/test/Driver/ohos.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
// RUN: -resource-dir=%S/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z \
// RUN: --sysroot=%S/Inputs/ohos_native_tree/sysroot -fuse-ld=ld -march=armv7-a -mcpu=cortex-a7 -mfloat-abi=soft 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK,CHECK-ARM-A7-SOFT %s
// RUN: %clang %s -### -no-canonical-prefixes --target=loongarch64-linux-ohos \
// RUN: -resource-dir=%S/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z \
// RUN: --sysroot=%S/Inputs/ohos_native_tree/sysroot 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK,CHECK-LOONGARCH %s
// CHECK: {{.*}}clang{{.*}}" "-cc1"
// CHECK-NOT: "-munwind-tables"
// CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
Expand All @@ -19,13 +23,17 @@
// CHECK-NOT: "--build-id"
// CHECK: "--hash-style=both"
// CHECK: "-pie"
// CHECK: "-dynamic-linker" "/lib/ld-musl-arm.so.1"
// CHECK-ARM: "-dynamic-linker" "/lib/ld-musl-arm.so.1"
// CHECK-ARM-A7-SOFT: "-dynamic-linker" "/lib/ld-musl-arm.so.1"
// CHECK-LOONGARCH: "-dynamic-linker" "/lib/ld-musl-loongarch64.so.1"
// CHECK: Scrt1.o
// CHECK: crti.o
// CHECK: clang_rt.crtbegin.o
// CHECK-ARM: "-L[[SYSROOT]]{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}arm-liteos-ohos{{/|\\\\}}"
// CHECK-LOONGARCH: "-L[[SYSROOT]]{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}loongarch64-linux-ohos{{/|\\\\}}"
// CHECK-ARM-A7-SOFT: "-L[[SYSROOT]]{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}arm-liteos-ohos{{/|\\\\}}a7_soft"
// CHECK-ARM: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}arm-liteos-ohos{{/|\\\\}}libclang_rt.builtins.a"
// CHECK-LOONGARCH: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}loongarch64-linux-ohos{{/|\\\\}}libclang_rt.builtins.a"
// CHECK-ARM-A7-SOFT: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}arm-liteos-ohos/a7_soft{{/|\\\\}}libclang_rt.builtins.a"
// CHECK: "-lc"
// CHECK: clang_rt.crtend.o
Expand Down Expand Up @@ -235,3 +243,14 @@

// CHECK-OHOS-PTHREAD-NOT: -lpthread

// RUN: %clang -### --target=aarch64-linux-ohos %s 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-MAXPAGESIZE-4KB %s
// RUN: %clang -### --target=loongarch64-linux-ohos %s 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-MAXPAGESIZE-16KB %s
// RUN: %clang -### --target=riscv64-linux-ohos %s 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-MAXPAGESIZE-4KB %s
// RUN: %clang -### --target=x86_64-linux-ohos %s 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-MAXPAGESIZE-4KB %s

// CHECK-MAXPAGESIZE-4KB: "-z" "max-page-size=4096"
// CHECK-MAXPAGESIZE-16KB: "-z" "max-page-size=16384"
2 changes: 2 additions & 0 deletions clang/test/Preprocessor/ohos.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=riscv64-linux-ohos < /dev/null | FileCheck %s -match-full-lines -check-prefix=RISCV64-OHOS-CXX
// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=mipsel-linux-ohos < /dev/null | FileCheck %s -match-full-lines -check-prefix=MIPSEL-OHOS-CXX
// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=x86_64-linux-ohos < /dev/null | FileCheck %s -match-full-lines -check-prefix=X86_64-OHOS-CXX
// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=loongarch64-linux-ohos < /dev/null | FileCheck %s -match-full-lines -check-prefix=LOONGARCH64-OHOS-CXX
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should test loongarch32 here too.

// RUN: %clang_cc1 -E -dM -ffreestanding -triple=arm-linux-ohos < /dev/null | FileCheck %s -check-prefix=OHOS-DEFS

// ARM-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
// ARM64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
// RISCV64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
// MIPSEL-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
// X86_64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
// LOONGARCH64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
// OHOS-DEFS: __OHOS_FAMILY__
// OHOS-DEFS: __OHOS__
// OHOS-DEFS-NOT: __OHOS__
Loading