[PATCH] D150940: [lld][RISCV][test] Add test for relaxation combined with --wrap

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 19 00:55:16 PDT 2023


jobnoorman created this revision.
jobnoorman added reviewers: MaskRay, jrtc27, craig.topper, asb.
Herald added subscribers: luke, pmatos, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson, emaste.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD.
Herald added a project: LLVM.

D150220 <https://reviews.llvm.org/D150220> proposed a fix for a relaxation bug when --wrap is used. The
issue happened to be already (accidentally) fixed by D149735 <https://reviews.llvm.org/D149735>. This patch
adds a test to ensure the issue isn't reintroduced in the future.

The issue is the following: when `--wrap bar` is used and an object file
defines both `bar` and `__wrap_bar`, `__wrap_bar` is inserted twice in
the symbol table pointing to the same `Defined`. Before D149735 <https://reviews.llvm.org/D149735>, symbol
values were adjusted by repeated subtraction causing the delta to be
subtracted twice from the duplicated symbol.

Note that I'm not quite sure whether inserting this symbol twice is
actually intended behavior. Could it be worthwhile to look into this?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150940

Files:
  lld/test/ELF/riscv-relax-wrap.s


Index: lld/test/ELF/riscv-relax-wrap.s
===================================================================
--- /dev/null
+++ lld/test/ELF/riscv-relax-wrap.s
@@ -0,0 +1,26 @@
+## Check that relaxation doesn't break when using --wrap. See D150220
+
+# REQUIRES: riscv
+# RUN: rm -rf %t && split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax %t/main.s -o %t/main.o
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax %t/wrap.s -o %t/wrap.o
+# RUN: ld.lld %t/main.o %t/wrap.o --wrap bar -o %t1
+# RUN: llvm-objdump -t %t1 | FileCheck %s
+
+# CHECK-DAG: 0000000000011120 g       .text 0000000000000000 _start
+# CHECK-DAG: 0000000000011124 g       .text 0000000000000000 bar
+# CHECK-DAG: 0000000000011128 g       .text 0000000000000000 __wrap_bar
+
+#--- main.s
+.globl _start
+_start:
+  call bar
+
+#--- wrap.s
+.globl bar, __wrap_bar
+bar:
+## Note that this can be any instruction that gets relaxed. The goal is to force
+## the value of __wrap_bar to change.
+  call __wrap_bar
+__wrap_bar:
+  call __real_bar


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150940.523681.patch
Type: text/x-patch
Size: 1044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230519/7ff5aec4/attachment.bin>


More information about the llvm-commits mailing list