diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2096,6 +2096,12 @@ if (Args.hasArg(options::OPT_G)) { D.Diag(diag::warn_drv_unsupported_sdata); } + } else if (Triple.isAndroid()) { + // GP relaxation is not supported on Android. + SmallDataLimit = "0"; + if (Args.hasArg(options::OPT_G)) { + D.Diag(diag::warn_drv_unsupported_sdata); + } } else if (Arg *A = Args.getLastArg(options::OPT_G)) { SmallDataLimit = A->getValue(); } diff --git a/clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c b/clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c --- a/clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c +++ b/clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c @@ -21,6 +21,10 @@ // RUN: | FileCheck %s -check-prefix=RV64-S2G4 // RUN: %clang -target riscv64-unknown-elf %s -S -emit-llvm -msmall-data-threshold=16 -o - \ // RUN: | FileCheck %s -check-prefix=RV64-T16 +// RUN: %clang -target riscv64-linux-android %s -S -emit-llvm -o - \ +// RUN: | FileCheck %s -check-prefix=RV64-ANDROID +// RUN: %clang -target riscv64-linux-android %s -S -emit-llvm -msmall-data-limit=8 -o - \ +// RUN: | FileCheck %s -check-prefix=RV64-ANDROID // RUN: %clang -target riscv64-unknown-elf %s -S -emit-llvm -fpic -o - \ // RUN: | FileCheck %s -check-prefix=RV64-PIC // RUN: %clang -target riscv64-unknown-elf %s -S -emit-llvm -mcmodel=large -o - \ @@ -46,3 +50,6 @@ // The value will be passed by module flag instead of target feature. // RV32-S0-NOT: +small-data-limit= // RV64-S0-NOT: +small-data-limit= + +// RV64-ANDROID-NOT: small-data-limit +// RV64-ANDROID: !{i32 8, !"SmallDataLimit", i32 0} diff --git a/clang/test/Driver/riscv-sdata-warning.c b/clang/test/Driver/riscv-sdata-warning.c --- a/clang/test/Driver/riscv-sdata-warning.c +++ b/clang/test/Driver/riscv-sdata-warning.c @@ -6,3 +6,7 @@ // RUN: %clang -S --target=riscv64-unknown-elf -mcmodel=large -msmall-data-limit=8 %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-RV64-LARGE-SDATA %s // CHECK-RV64-LARGE-SDATA: warning: ignoring '-msmall-data-limit=' with -mcmodel=large for -fpic or RV64 + +// RUN: %clang -S --target=riscv64-linux-android -msmall-data-limit=8 %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-RV64-LARGE-SDATA-ANDROID %s +// CHECK-RV64-LARGE-SDATA-ANDROID: warning: ignoring '-msmall-data-limit=' with -mcmodel=large for -fpic or RV64