[llvm] [BOLT] Fix reorder data test for RISC-V (PR #68996)

Job Noorman via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 00:38:13 PDT 2023


https://github.com/mtvec updated https://github.com/llvm/llvm-project/pull/68996

>From e1805ef952a3a92a24358ab9d36b645055e7dbe7 Mon Sep 17 00:00:00 2001
From: Job Noorman <jnoorman at igalia.com>
Date: Fri, 13 Oct 2023 16:57:40 +0200
Subject: [PATCH 1/2] [BOLT] Fix reorder data test for RISC-V

On RISC-V, small data objects are put in the `.sdata` section by
default. This causes the `reorder-data-writable-ptload.c` to fail since
it hard-codes the section to optimize to `.data`.

This patch passes the `-msmall-data-limit=0` option to clang on RISC-V
to ensure the objects are added to `.data`.
---
 bolt/test/reorder-data-writable-ptload.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bolt/test/reorder-data-writable-ptload.c b/bolt/test/reorder-data-writable-ptload.c
index 7b384e9655a3283..0447beba057f9ec 100644
--- a/bolt/test/reorder-data-writable-ptload.c
+++ b/bolt/test/reorder-data-writable-ptload.c
@@ -1,7 +1,8 @@
 // This test checks that reorder-data pass puts new hot .data section
 // to the writable segment.
 
-// RUN: %clang %cflags -O3 -nostdlib -Wl,-q %s -o %t.exe
+// RUN: %clang %cflags %if target=riscv64{{.*}} %{ -msmall-data-limit=0 %} \
+// RUN:     -O3 -nostdlib -Wl,-q %s -o %t.exe
 // RUN: llvm-bolt %t.exe -o %t.bolt --reorder-data=".data" \
 // RUN:   -data %S/Inputs/reorder-data-writable-ptload.fdata
 // RUN: llvm-readelf -SlW %t.bolt | FileCheck %s

>From 3dfded3dc37585542511ed28e52cad78c34b4e30 Mon Sep 17 00:00:00 2001
From: Job Noorman <jnoorman at igalia.com>
Date: Mon, 16 Oct 2023 09:37:41 +0200
Subject: [PATCH 2/2] Use -fPIC -pie to force use of .data

---
 bolt/test/reorder-data-writable-ptload.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/bolt/test/reorder-data-writable-ptload.c b/bolt/test/reorder-data-writable-ptload.c
index 0447beba057f9ec..fa9918779463a7e 100644
--- a/bolt/test/reorder-data-writable-ptload.c
+++ b/bolt/test/reorder-data-writable-ptload.c
@@ -1,8 +1,9 @@
 // This test checks that reorder-data pass puts new hot .data section
 // to the writable segment.
 
-// RUN: %clang %cflags %if target=riscv64{{.*}} %{ -msmall-data-limit=0 %} \
-// RUN:     -O3 -nostdlib -Wl,-q %s -o %t.exe
+// Use -fPIC -pie to prevent the globals being put in .sdata instead of .data on
+// RISC-V.
+// RUN: %clang %cflags -fPIC -pie -O3 -nostdlib -Wl,-q %s -o %t.exe
 // RUN: llvm-bolt %t.exe -o %t.bolt --reorder-data=".data" \
 // RUN:   -data %S/Inputs/reorder-data-writable-ptload.fdata
 // RUN: llvm-readelf -SlW %t.bolt | FileCheck %s



More information about the llvm-commits mailing list