Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -2078,8 +2078,14 @@ ArgStringList &CmdArgs) { const Driver &D = TC.getDriver(); const llvm::Triple &Triple = TC.getTriple(); + // Default small data limitation is eight. const char *SmallDataLimit = "8"; + + // GP relaxation is not supported on Android. + if (Triple.isAndroid()) + SmallDataLimit = "0"; + // Get small data limitation. if (Args.getLastArg(options::OPT_shared, options::OPT_fpic, options::OPT_fPIC)) { @@ -2097,7 +2103,10 @@ D.Diag(diag::warn_drv_unsupported_sdata); } } else if (Arg *A = Args.getLastArg(options::OPT_G)) { - SmallDataLimit = A->getValue(); + if (Triple.isAndroid()) + D.Diag(diag::warn_drv_unsupported_sdata); + else + SmallDataLimit = A->getValue(); } // Forward the -msmall-data-limit= option. CmdArgs.push_back("-msmall-data-limit"); Index: clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c =================================================================== --- clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c +++ 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} Index: clang/test/Driver/riscv-sdata-warning.c =================================================================== --- clang/test/Driver/riscv-sdata-warning.c +++ 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