[clang] 28bd84f - [RISCV] Allow mismatched SmallDataLimit and use Min for conflicting values
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 6 15:33:14 PST 2023
Author: AdityaK
Date: 2023-02-06T15:32:45-08:00
New Revision: 28bd84f55fc087d4aefd3fe5360f8648d1d50980
URL: https://github.com/llvm/llvm-project/commit/28bd84f55fc087d4aefd3fe5360f8648d1d50980
DIFF: https://github.com/llvm/llvm-project/commit/28bd84f55fc087d4aefd3fe5360f8648d1d50980.diff
LOG: [RISCV] Allow mismatched SmallDataLimit and use Min for conflicting values
Authored By: joshua-arch1 (Jun Sha)
Reviewed By: shiva0217, apazos, luismarques, asb, jrtc27, MaskRay
Reviewers: MaskRay, jrtc27
Differential Revision: https://reviews.llvm.org/D131230
This patch is to fix an issue about module linking with LTO.
When compiling with PIE, the small data limitation needs to be consistent with that in PIC, otherwise there will be linking errors due to conflicting values.
bar.c
int bar() { return 1; }
foo.c
int foo() { return 1; }
clang --target=riscv64-unknown-linux-gnu -flto -c foo.c -o foo.o -fPIE
clang --target=riscv64-unknown-linux-gnu -flto -c bar.c -o bar.o -fPIC
clang --target=riscv64-unknown-linux-gnu -flto foo.o bar.o -flto -nostdlib -v -fuse-ld=lld
ld.lld: error: linking module flags 'SmallDataLimit': IDs have conflicting values in 'bar.o' and 'ld-temp.o'
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
What we are trying to do here is to use Min instead of Error for conflicting SmallDataLimit when combining -fno-PIC code with -fPIC code.
Signed-off-by: xiaojing.zhang <xiaojing.zhang at xcalibyte.com>
Signed-off-by: jianxin.lai <jianxin.lai at xcalibyte.com>
Added:
Modified:
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 24b63372500ba..e9d088da01f12 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -980,7 +980,7 @@ void CodeGenModule::EmitOpenCLMetadata() {
void CodeGenModule::EmitBackendOptionsMetadata(
const CodeGenOptions CodeGenOpts) {
if (getTriple().isRISCV()) {
- getModule().addModuleFlag(llvm::Module::Error, "SmallDataLimit",
+ getModule().addModuleFlag(llvm::Module::Min, "SmallDataLimit",
CodeGenOpts.SmallDataLimit);
}
}
diff --git a/clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c b/clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c
index 89c9cc8cb0d07..aa407c17ea05b 100644
--- a/clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c
+++ b/clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c
@@ -28,20 +28,20 @@
void test(void) {}
-// RV32-DEFAULT: !{i32 1, !"SmallDataLimit", i32 8}
-// RV32-G4: !{i32 1, !"SmallDataLimit", i32 4}
-// RV32-S0: !{i32 1, !"SmallDataLimit", i32 0}
-// RV32-S2G4: !{i32 1, !"SmallDataLimit", i32 4}
-// RV32-T16: !{i32 1, !"SmallDataLimit", i32 16}
-// RV32-PIC: !{i32 1, !"SmallDataLimit", i32 0}
+// RV32-DEFAULT: !{i32 8, !"SmallDataLimit", i32 8}
+// RV32-G4: !{i32 8, !"SmallDataLimit", i32 4}
+// RV32-S0: !{i32 8, !"SmallDataLimit", i32 0}
+// RV32-S2G4: !{i32 8, !"SmallDataLimit", i32 4}
+// RV32-T16: !{i32 8, !"SmallDataLimit", i32 16}
+// RV32-PIC: !{i32 8, !"SmallDataLimit", i32 0}
-// RV64-DEFAULT: !{i32 1, !"SmallDataLimit", i32 8}
-// RV64-G4: !{i32 1, !"SmallDataLimit", i32 4}
-// RV64-S0: !{i32 1, !"SmallDataLimit", i32 0}
-// RV64-S2G4: !{i32 1, !"SmallDataLimit", i32 4}
-// RV64-T16: !{i32 1, !"SmallDataLimit", i32 16}
-// RV64-PIC: !{i32 1, !"SmallDataLimit", i32 0}
-// RV64-LARGE: !{i32 1, !"SmallDataLimit", i32 0}
+// RV64-DEFAULT: !{i32 8, !"SmallDataLimit", i32 8}
+// RV64-G4: !{i32 8, !"SmallDataLimit", i32 4}
+// RV64-S0: !{i32 8, !"SmallDataLimit", i32 0}
+// RV64-S2G4: !{i32 8, !"SmallDataLimit", i32 4}
+// RV64-T16: !{i32 8, !"SmallDataLimit", i32 16}
+// RV64-PIC: !{i32 8, !"SmallDataLimit", i32 0}
+// RV64-LARGE: !{i32 8, !"SmallDataLimit", i32 0}
// The value will be passed by module flag instead of target feature.
// RV32-S0-NOT: +small-data-limit=
More information about the cfe-commits
mailing list