From: Fangrui Song <i@maskray.me>
To: mengqinggang <mengqinggang@loongson.cn>
Cc: binutils@sourceware.org, xuchenghua@loongson.cn,
chenglulu@loongson.cn, liuzhensong@loongson.cn,
xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com
Subject: Re: [PATCH v1 6/6] LoongArch: Add more relaxation testcases
Date: Wed, 15 Nov 2023 22:39:27 -0800 [thread overview]
Message-ID: <DS7PR12MB57657BD0C100090DED2E2ADFCBB0A@DS7PR12MB5765.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20231116062307.3292483-7-mengqinggang@loongson.cn>
On Wed, Nov 15, 2023 at 10:23 PM mengqinggang <mengqinggang@loongson.cn> wrote:
>
> 1. .so relaxation testcase
> 2. ld --no-relax testcase
> 3. segment alignment testcase
> ---
> .../ld-loongarch-elf/relax-segment-max.s | 13 +++
> .../ld-loongarch-elf/relax-segment-min.s | 13 +++
> ld/testsuite/ld-loongarch-elf/relax-so.s | 4 +
> ld/testsuite/ld-loongarch-elf/relax.exp | 80 +++++++++++++++++--
> 4 files changed, 105 insertions(+), 5 deletions(-)
> create mode 100644 ld/testsuite/ld-loongarch-elf/relax-segment-max.s
> create mode 100644 ld/testsuite/ld-loongarch-elf/relax-segment-min.s
> create mode 100644 ld/testsuite/ld-loongarch-elf/relax-so.s
>
> diff --git a/ld/testsuite/ld-loongarch-elf/relax-segment-max.s b/ld/testsuite/ld-loongarch-elf/relax-segment-max.s
> new file mode 100644
> index 00000000000..417260fb880
> --- /dev/null
> +++ b/ld/testsuite/ld-loongarch-elf/relax-segment-max.s
> @@ -0,0 +1,13 @@
> +# The .align may cause overflow because deleting nops.
> + .text # 0x120000000
> + .fill 0x4000
> + .align 3 # 0x120004000
> + la.local $r12, .L1
> +
> +# .fill 0x1f7ffc # max fill without overflow, .data address is 0x120200000
> +# .fill 0x1f8000 # min fill with overflow, .data address is 0x120204000
> + .fill 0x1fbff4 # max fill with overflow, .data address is 0x120204000
> +
> + .data
> +.L1:
> + .byte 2
> diff --git a/ld/testsuite/ld-loongarch-elf/relax-segment-min.s b/ld/testsuite/ld-loongarch-elf/relax-segment-min.s
> new file mode 100644
> index 00000000000..14a541b97c8
> --- /dev/null
> +++ b/ld/testsuite/ld-loongarch-elf/relax-segment-min.s
> @@ -0,0 +1,13 @@
> +# The .align may cause overflow because deleting nops.
> + .text # 0x120000000
> + .fill 0x4000
> + .align 3 # 0x120004000
> + la.local $r12, .L1
> +
> +# .fill 0x1f7ffc # max fill without overflow, .data address is 0x120200000
> + .fill 0x1f8000 # min fill with overflow, .data address is 0x120204000
> +# .fill 0x1fbff4 # max fill with overflow, .data address is 0x120204000
> +
> + .data
> +.L1:
> + .byte 2
You may want something more complex.
When I implemented linker relaxation for lld, I put a lot of thoughts
into organizing the tests.
I have come up with
https://github.com/llvm/llvm-project/blob/main/lld/test/ELF/riscv-relax-call.s
https://github.com/llvm/llvm-project/blob/main/lld/test/ELF/riscv-relax-call2.s
https://github.com/llvm/llvm-project/blob/main/lld/test/ELF/riscv-relax-align.s
.fill 0x4000 creates a lot of zeroes. I prefer output section addresses.
> diff --git a/ld/testsuite/ld-loongarch-elf/relax-so.s b/ld/testsuite/ld-loongarch-elf/relax-so.s
> new file mode 100644
> index 00000000000..01a404a8b47
> --- /dev/null
> +++ b/ld/testsuite/ld-loongarch-elf/relax-so.s
> @@ -0,0 +1,4 @@
> +.text
> +.align 2
> +.L1:
> + la.local $r12, .L1
> diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp
> index 7ff876d7914..426b72dac5d 100644
> --- a/ld/testsuite/ld-loongarch-elf/relax.exp
> +++ b/ld/testsuite/ld-loongarch-elf/relax.exp
> @@ -22,7 +22,7 @@
> if [istarget loongarch64-*-*] {
>
> if [isbuild loongarch64-*-*] {
> - set testname "loongarch relax build"
> + set testname "loongarch relax .exe build"
> set pre_builds [list \
> [list \
> "$testname" \
> @@ -39,17 +39,87 @@ if [istarget loongarch64-*-*] {
> if [file exist "tmpdir/relax"] {
> set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax"]
> if { [ regexp ".*pcaddi.*pcaddi.*" $objdump_output] } {
> - pass "loongarch relax"
> + pass "loongarch relax .exe"
> } {
> - fail "loongarch relax"
> + fail "loongarch relax .exe"
> }
> }
> +
> + set testname "loongarch ld --no-relax build"
> + set pre_builds [list \
> + [list \
> + "$testname" \
> + "-Wl,--no-relax" \
> + "" \
> + {relax.s} \
> + {} \
> + "norelax" \
> + ] \
> + ]
> +
> + run_cc_link_tests $pre_builds
> +
> + if [file exist "tmpdir/norelax"] {
> + set objdump_output [run_host_cmd "objdump" "-d tmpdir/norelax"]
> + if { [ regexp ".*pcaddi.*" $objdump_output] } {
> + fail "loongarch ld --no-relax"
> + } {
> + pass "loongarch ld --no-relax"
> + }
> + }
> +
> + run_ld_link_tests \
> + [list \
> + [list \
> + "loongarch relax .so build" \
> + "-shared -e 0x0" "" \
> + "" \
> + {relax-so.s} \
> + {} \
> + "relax-so" \
> + ] \
> + ]
> +
> + if [file exist "tmpdir/relax-so"] {
> + set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-so"]
> + if { [ regexp ".*pcaddi.*" $objdump_output] } {
> + pass "loongarch relax .so"
> + } {
> + fail "loongarch relax .so"
> + }
> + }
> +
> + # If symbol in data segment, offset need to sub segment align to prevent
> + # overflow.
> + run_ld_link_tests \
> + [list \
> + [list \
> + "loongarch relax segment alignment min" \
> + "-e0 -Ttext 0x120000000 -pie" "" \
> + "" \
> + {relax-segment-min.s} \
> + {} \
> + "relax-segment-min" \
> + ] \
> + ]
> +
> + run_ld_link_tests \
> + [list \
> + [list \
> + "loongarch relax segment alignment max" \
> + "-e0 -Ttext 0x120000000 -pie" "" \
> + "" \
> + {relax-segment-max.s} \
> + {} \
> + "relax-segment-max" \
> + ] \
> + ]
> }
>
> run_ld_link_tests \
> [list \
> [list \
> - "relax-align" \
> + "loongarch relax-align" \
> "-e 0x0 -z relro" "" \
> "" \
> {relax-align.s} \
> @@ -64,7 +134,7 @@ if [istarget loongarch64-*-*] {
> run_ld_link_tests \
> [list \
> [list \
> - "uleb128" \
> + "loongarch uleb128" \
> "-e 0x0" "" \
> "" \
> {uleb128.s} \
> --
> 2.36.0
>
prev parent reply other threads:[~2023-11-16 6:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-16 6:23 [PATCH v1 0/6] Fix some bugs of relaxation mengqinggang
2023-11-16 6:23 ` [PATCH v1 1/6] LoongArch: Fix ld --no-relax bug mengqinggang
2023-11-16 7:34 ` WANG Xuerui
2023-11-16 6:23 ` [PATCH v1 2/6] LoongArch: Directly delete relaxed instuctions in first relaxation pass mengqinggang
2023-11-16 6:23 ` [PATCH v1 3/6] LoongArch: Multiple relax_trip in one relax_pass mengqinggang
2023-11-16 6:23 ` [PATCH v1 4/6] LoongArch: Remove "elf_seg_map (info->output_bfd) == NULL" relaxation condition mengqinggang
2023-11-16 7:43 ` WANG Xuerui
2023-11-16 9:38 ` mengqinggang
2023-11-16 6:23 ` [PATCH v1 5/6] LoongArch: Modify link_info.relax_pass from 3 to 2 mengqinggang
2023-11-16 6:23 ` [PATCH v1 6/6] LoongArch: Add more relaxation testcases mengqinggang
2023-11-16 6:39 ` Fangrui Song [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DS7PR12MB57657BD0C100090DED2E2ADFCBB0A@DS7PR12MB5765.namprd12.prod.outlook.com \
--to=i@maskray.me \
--cc=binutils@sourceware.org \
--cc=chenglulu@loongson.cn \
--cc=i.swmail@xen0n.name \
--cc=liuzhensong@loongson.cn \
--cc=maskray@google.com \
--cc=mengqinggang@loongson.cn \
--cc=xry111@xry111.site \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).