Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chrome] merge riscv64_109.0.5414.87_dev_clang into riscv64_109.0.5414.87_dev #42

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
163 changes: 163 additions & 0 deletions third_party/llvm-patches/0001-applied-patch-D145474.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
From 881585120dd548eedc17a74b5ff05b528c7c5d68 Mon Sep 17 00:00:00 2001
From: Wang Chen <wangchen20@iscas.ac.cn>
Date: Sat, 11 Mar 2023 19:31:42 +0800
Subject: [PATCH] applied patch D145474

Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
---
.../RISCV/MCTargetDesc/RISCVELFStreamer.cpp | 10 ++
llvm/test/MC/RISCV/riscv64-64b-pcrel.s | 111 +++++++++++-------
2 files changed, 81 insertions(+), 40 deletions(-)

diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
index c63488bb4d34..11b158c5e55f 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
@@ -239,6 +239,16 @@ class RISCVELFStreamer : public MCELFStreamer {
if (B.isInSection() && B.getSection().getKind().isText())
return true;

+ // If A is undefined and B is defined, we should emit ADD/SUB for A-B.
+ // Unfortunately, A may be defined later, but this requiresFixups call has to
+ // eagerly make a decision. For now, emit ADD/SUB unless A is .L*. This
+ // heuristic handles many temporary label differences for .debug_* and
+ // .apple_types sections.
+ //
+ // TODO Implement delayed relocation decision.
+ if (!A.isInSection() && !A.isTemporary() && B.isInSection())
+ return true;
+
// Support cross-section symbolic differences ...
return A.isInSection() && B.isInSection() &&
A.getSection().getName() != B.getSection().getName();
diff --git a/llvm/test/MC/RISCV/riscv64-64b-pcrel.s b/llvm/test/MC/RISCV/riscv64-64b-pcrel.s
index 5f5870ee7331..951c882f03ca 100644
--- a/llvm/test/MC/RISCV/riscv64-64b-pcrel.s
+++ b/llvm/test/MC/RISCV/riscv64-64b-pcrel.s
@@ -1,51 +1,82 @@
# RUN: llvm-mc -triple riscv64-unknown-linux-gnu -filetype obj -o - %s \
# RUN: | llvm-readobj -r - | FileCheck %s
# RUN: not llvm-mc -triple riscv64-unknown-linux-gnu -filetype obj --defsym ERR=1 -o /dev/null %s 2>&1 \
-# RUN: | FileCheck %s --check-prefix CHECK-ERROR
+# RUN: | FileCheck %s --check-prefix=ERROR

-# CHECK: Relocations [
-# CHECK: .relasx {
-# CHECK-NEXT: 0x0 R_RISCV_ADD64 y 0x0
-# CHECK-NEXT: 0x0 R_RISCV_SUB64 x 0x0
-# CHECK: }
-# CHECK: .relasy {
-# CHECK-NEXT: 0x0 R_RISCV_ADD64 x 0x0
-# CHECK-NEXT: 0x0 R_RISCV_SUB64 y 0x0
-# CHECK: }
-# CHECK: .relasa {
-# CHECK-NEXT: 0x0 R_RISCV_ADD64 a 0x0
-# CHECK-NEXT: 0x0 R_RISCV_SUB64 z 0x0
-# CHECK: }
+# CHECK: Relocations [
+# CHECK-NEXT: Section ({{.*}}) .rela.note {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 extern 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 note 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: Section ({{.*}}) .rela.rodata {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 extern 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 rodata 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: Section ({{.*}}) .rela.alloc_w {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 extern 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 w 0x0
+# CHECK-NEXT: 0x8 R_RISCV_ADD64 w 0x0
+# CHECK-NEXT: 0x8 R_RISCV_SUB64 extern 0x0
+# CHECK-NEXT: 0x10 R_RISCV_ADD32 x 0x0
+# CHECK-NEXT: 0x10 R_RISCV_SUB32 w 0x0
+# CHECK-NEXT: 0x14 R_RISCV_ADD32 w1 0x0
+# CHECK-NEXT: 0x14 R_RISCV_SUB32 w 0x0
+# CHECK-NEXT: 0x18 R_RISCV_ADD32 .L.str 0x0
+# CHECK-NEXT: 0x18 R_RISCV_SUB32 w 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: Section ({{.*}}) .rela.alloc_x {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 y 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 x 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: Section ({{.*}}) .rela.alloc_y {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 x 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 y 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: Section ({{.*}}) .rela.nonalloc_w {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 extern 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 nw 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: Section ({{.*}}) .rela.nonalloc_x {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 ny 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 nx 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: Section ({{.*}}) .rela.nonalloc_y {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 nx 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 ny 0x0
+# CHECK-NEXT: }
# CHECK-NEXT: ]

- .section sx,"aw",@progbits
-x:
- .quad y-x
+.section .note,"a",@note; note:
+.quad extern-note
+.section .rodata,"a",@progbits; rodata:
+.quad extern-rodata

- .section sy,"aw",@progbits
-y:
- .quad x-y
+.section .alloc_w,"aw",@progbits; w:
+.quad extern-w # extern is undefined
+.quad w-extern
+.long x-w # A is later defined in another section
+.long w1-w # A is later defined in the same section
+.long .L.str-w # A is temporary
+w1:

- .section sz
-z:
-.ifdef ERR
- .quad z-a
+.section .alloc_x,"aw",@progbits; x:
+.quad y-x
+.section .alloc_y,"aw",@progbits; y:
+.quad x-y

-# CHECK-ERROR: Cannot represent a difference across sections
-# CHECK-ERROR: .quad z-a
-# CHECK-ERROR: ^
-.else
- .quad 0
+.section .nonalloc_w; nw:
+.quad extern-nw
+.ifdef ERR
+# ERROR: :[[#@LINE+1]]:7: error: symbol 'extern' can not be undefined in a subtraction expression
+.quad nw-extern
.endif
+.section .nonalloc_x; nx:
+.quad ny-nx
+.section .nonalloc_y; ny:
+.quad nx-ny

- .section sa
-a:
- .quad a-z
-
-## .apple_names/.apple_types are fixed-size and do not need fixups.
-## llvm-dwarfdump --apple-names does not process R_RISCV_{ADD,SUB}32 in them.
-## See llvm/test/DebugInfo/Generic/accel-table-hash-collisions.ll
- .section .apple_types
- .word 0
- .word .Ltypes0-.apple_types
-.Ltypes0:
+## -gdwarf-aranges generated assembly expects no relocation.
+## Otherwise, a .Lsec_end0 symbol (defined at the end of .rodata.str1.1)
+## will be rejected by linkers.
+.section .rodata.str1.1,"aMS",@progbits,1
+.L.str:
\ No newline at end of file
--
2.25.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
From 91520467c83d3265e618910f4daed657f93a8430 Mon Sep 17 00:00:00 2001
From: Colin Cross <ccross@android.com>
Date: Thu, 13 Oct 2022 13:19:19 -0700
Subject: [PATCH] Enable targeting riscv64-linux-android

Add riscv64-linux-android to Linux::getMultiarchTriple, add
__get_tls for riscv64-linux-android sanitizers, and add RISCV64
to the list of Android fuzzer targets.

Test: build.py
Change-Id: I0fdf55125d22d1d3aab9d2199838f25562ffd8a0
---
clang/lib/Driver/ToolChains/Linux.cpp | 2 ++
compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake | 2 +-
compiler-rt/lib/sanitizer_common/sanitizer_linux.h | 3 +++
3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index ceb1a982c3a4..ed8079353ea4 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -125,6 +125,8 @@ std::string Linux::getMultiarchTriple(const Driver &D,
case llvm::Triple::ppc64le:
return "powerpc64le-linux-gnu";
case llvm::Triple::riscv64:
+ if (IsAndroid)
+ return "riscv64-linux-android";
return "riscv64-linux-gnu";
case llvm::Triple::sparc:
return "sparc-linux-gnu";
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index a1da35b0ac4b..68a386019070 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -42,7 +42,7 @@ if(OS_NAME MATCHES "Linux")
elseif (OS_NAME MATCHES "Windows")
set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64})
elseif(OS_NAME MATCHES "Android")
- set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64})
+ set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64})
else()
set(ALL_FUZZER_SUPPORTED_ARCH ${X86_64} ${ARM64})
endif()
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
index 761c57d1b8eb..13c359c7e3a3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
@@ -152,6 +152,9 @@ inline void ReleaseMemoryPagesToOSAndZeroFill(uptr beg, uptr end) {
"rdhwr %0,$29\n" \
".set pop\n" : "=r"(__v)); \
__v; })
+#elif defined (__riscv)
+# define __get_tls() \
+ ({ void** __v; __asm__("mv %0, tp" : "=r"(__v)); __v; })
#elif defined(__i386__)
# define __get_tls() \
({ void** __v; __asm__("movl %%gs:0, %0" : "=r"(__v)); __v; })
--
2.38.0.135.g90850a2211-goog

17 changes: 15 additions & 2 deletions tools/clang/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
# Path constants. (All of these should be absolute paths.)
THIRD_PARTY_DIR = os.path.join(CHROMIUM_DIR, 'third_party')
LLVM_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm')
LLVM_PATCHES_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm-patches')
COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'compiler-rt')
LLVM_BOOTSTRAP_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm-bootstrap')
LLVM_BOOTSTRAP_INSTALL_DIR = os.path.join(THIRD_PARTY_DIR,
Expand Down Expand Up @@ -613,6 +614,18 @@ def main():

if not args.skip_checkout:
CheckoutLLVM(checkout_revision, LLVM_DIR)
# temp hack to apply patches
# DON'T submit to google upstream
patches = [
'Enable-targeting-riscv64-linux-android.patch',
'0001-applied-patch-D145474.patch',
]
for _patch in patches:
patch_cmd = [
'patch', '-d', LLVM_DIR, '-f', '-p1', '--no-backup-if-mismatch',
'-i', LLVM_PATCHES_DIR + '/' + _patch
]
RunCommand(patch_cmd)

if args.llvm_force_head_revision:
CLANG_REVISION = GetCommitDescription(checkout_revision)
Expand Down Expand Up @@ -1063,12 +1076,12 @@ def main():

if args.with_android:
toolchain_dir = ANDROID_NDK_DIR + '/toolchains/llvm/prebuilt/linux-x86_64'
for target_arch in ['aarch64', 'arm', 'i686', 'x86_64']:
for target_arch in ['aarch64', 'arm', 'i686', 'x86_64', 'riscv64']:
target_triple = target_arch
if target_arch == 'arm':
target_triple = 'armv7'
api_level = '19'
if target_arch == 'aarch64' or target_arch == 'x86_64':
if target_arch == 'aarch64' or target_arch == 'x86_64' or target_arch == 'riscv64':
api_level = '21'
target_triple += '-linux-android' + api_level
cflags = [
Expand Down
5 changes: 5 additions & 0 deletions tools/clang/scripts/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,18 @@ def main():
'lib/clang/$V/lib/linux/libclang_rt.asan-aarch64-android.so',
'lib/clang/$V/lib/linux/libclang_rt.asan-arm-android.so',
'lib/clang/$V/lib/linux/libclang_rt.asan-i686-android.so',
'lib/clang/$V/lib/linux/libclang_rt.asan-riscv64-android.so',
'lib/clang/$V/lib/linux/libclang_rt.asan_static-aarch64-android.a',
'lib/clang/$V/lib/linux/libclang_rt.asan_static-arm-android.a',
'lib/clang/$V/lib/linux/libclang_rt.asan_static-i686-android.a',
'lib/clang/$V/lib/linux/libclang_rt.asan_static-riscv64-android.a',

# Builtins for Android.
'lib/clang/$V/lib/linux/libclang_rt.builtins-aarch64-android.a',
'lib/clang/$V/lib/linux/libclang_rt.builtins-arm-android.a',
'lib/clang/$V/lib/linux/libclang_rt.builtins-i686-android.a',
'lib/clang/$V/lib/linux/libclang_rt.builtins-x86_64-android.a',
'lib/clang/$V/lib/linux/libclang_rt.builtins-riscv64-android.a',

# Builtins for Lacros (and potentially Linux, but not used there atm).
'lib/clang/$V/lib/aarch64-unknown-linux-gnu/libclang_rt.builtins.a',
Expand Down Expand Up @@ -378,6 +381,7 @@ def main():
'lib/clang/$V/lib/linux/libclang_rt.profile-i686-android.a',
'lib/clang/$V/lib/linux/libclang_rt.profile-aarch64-android.a',
'lib/clang/$V/lib/linux/libclang_rt.profile-arm-android.a',
'lib/clang/$V/lib/linux/libclang_rt.profile-riscv64-android.a',

# ThreadSanitizer C runtime (pure C won't link with *_cxx).
'lib/clang/$V/lib/x86_64-unknown-linux-gnu/libclang_rt.tsan.a',
Expand All @@ -400,6 +404,7 @@ def main():
# UndefinedBehaviorSanitizer Android runtime, needed for CFI.
'lib/clang/$V/lib/linux/libclang_rt.ubsan_standalone-aarch64-android.so',
'lib/clang/$V/lib/linux/libclang_rt.ubsan_standalone-arm-android.so',
'lib/clang/$V/lib/linux/libclang_rt.ubsan_standalone-riscv64-android.so',

# Ignorelist for MemorySanitizer (used on Linux only).
'lib/clang/$V/share/msan_*list.txt',
Expand Down