From patchwork Wed Jun 26 10:04:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 92879 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B596A3870C3C for ; Wed, 26 Jun 2024 10:07:19 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id B8A7B387085A for ; Wed, 26 Jun 2024 10:05:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B8A7B387085A Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B8A7B387085A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719396326; cv=none; b=wXq6FEHLcO4NhQokxSM82F45Og7dMYRBmUH49GW4x3GXI8vyL50aJLU/qqp13Oxq8rgOIHSN6RauVaCSXuc1ajCPER9QaAPeFaw9iX0H1DeUUdeh9jDMYAvcYxgU8/4kn7cdFhNBnC0TAQEvVUcH/0r+B57pHNxWnoKSi6VEa7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719396326; c=relaxed/simple; bh=mYZOIdRCSP4qlsyHSoy0rkr1HqW2zzp6m9QY6gPGUd8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=w0jFelU7LZeHD383a16Ji3wOlvdUFwYMnnheAtnzsIn2c5suYM5VAbfOvKpn4yApeCYrR1ZMqvZ0JgSYG1gUii4DQVl4xIG5i3mUNExGBRMYAeGW/C58DRAUo+Jh/NRLvfs8Wfspb2Br5kLUyIFzLrw+ZkLdj8vaoObFpCGT+Zc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1719396321; bh=mYZOIdRCSP4qlsyHSoy0rkr1HqW2zzp6m9QY6gPGUd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e4/Vo26rPC/hPgtF5LOoZ6uiYfvypzZz4BYBd/9x/VG1w9sUauRD+km+q9Kv4yK6/ a/Ik4PBSRWOKNbL0+O9BJILzoCufAjntq/BdDZSMWPOMkb3sPRm4YI41UrpfgelW64 sr5gEnKTmpRKJQZbhVyMkxAZecsMxV6GHGJxI9+0= Received: from stargazer.. (unknown [113.200.174.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 617E066D6C; Wed, 26 Jun 2024 06:05:19 -0400 (EDT) From: Xi Ruoyao To: binutils@sourceware.org Cc: mengqinggang@loongson.cn, Zhensong Liu , i.swmail@xen0n.name, maskray@google.com, Szabolcs Nagy , Xi Ruoyao Subject: [PATCH v2 5/5] LoongArch: Add DT_RELR tests Date: Wed, 26 Jun 2024 18:04:54 +0800 Message-ID: <20240626100453.98946-7-xry111@xry111.site> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626100453.98946-2-xry111@xry111.site> References: <20240626100453.98946-2-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org Most tests are ported from AArch64. The relr-addend test is added to make sure the addend (link-time address) is correctly written into the relocated section. Doing so is not strictly needed for RELA, but strictly needed for RELR). Signed-off-by: Xi Ruoyao --- .../ld-loongarch-elf/ld-loongarch-elf.exp | 10 ++ ld/testsuite/ld-loongarch-elf/relr-addend.d | 11 ++ ld/testsuite/ld-loongarch-elf/relr-addend.s | 17 +++ ld/testsuite/ld-loongarch-elf/relr-align.d | 22 ++++ ld/testsuite/ld-loongarch-elf/relr-align.s | 106 ++++++++++++++++++ ld/testsuite/ld-loongarch-elf/relr-data-pie.d | 18 +++ .../ld-loongarch-elf/relr-data-shared.d | 18 +++ ld/testsuite/ld-loongarch-elf/relr-data.s | 71 ++++++++++++ .../ld-loongarch-elf/relr-discard-pie.d | 8 ++ .../ld-loongarch-elf/relr-discard-shared.d | 11 ++ ld/testsuite/ld-loongarch-elf/relr-discard.ld | 13 +++ ld/testsuite/ld-loongarch-elf/relr-discard.s | 61 ++++++++++ ld/testsuite/ld-loongarch-elf/relr-got-pie.d | 15 +++ .../ld-loongarch-elf/relr-got-shared.d | 15 +++ ld/testsuite/ld-loongarch-elf/relr-got.s | 27 +++++ ld/testsuite/ld-loongarch-elf/relr-relocs.ld | 24 ++++ ld/testsuite/ld-loongarch-elf/relr-text-pie.d | 14 +++ .../ld-loongarch-elf/relr-text-shared.d | 14 +++ ld/testsuite/ld-loongarch-elf/relr-text.s | 10 ++ 19 files changed, 485 insertions(+) create mode 100644 ld/testsuite/ld-loongarch-elf/relr-addend.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-addend.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-align.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-align.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-data-pie.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-data-shared.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-data.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-discard-pie.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-discard-shared.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-discard.ld create mode 100644 ld/testsuite/ld-loongarch-elf/relr-discard.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-got-pie.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-got-shared.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-got.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-relocs.ld create mode 100644 ld/testsuite/ld-loongarch-elf/relr-text-pie.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-text-shared.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-text.s diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp index 9a668fb7164..4606ede9fc0 100644 --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp @@ -135,10 +135,20 @@ if [istarget "loongarch64-*-*"] { run_dump_test "r_larch_32_elf64" run_dump_test "ifunc-reloc" run_dump_test "protected-func" + run_dump_test "relr-addend" + run_dump_test "relr-align" + run_dump_test "relr-data-shared" + run_dump_test "relr-discard-shared" + run_dump_test "relr-got-shared" + run_dump_test "relr-text-shared" } if [check_pie_support] { run_dump_test "pie_discard" + run_dump_test "relr-data-pie" + run_dump_test "relr-discard-pie" + run_dump_test "relr-got-pie" + run_dump_test "relr-text-pie" } run_dump_test "max_imm_b16" diff --git a/ld/testsuite/ld-loongarch-elf/relr-addend.d b/ld/testsuite/ld-loongarch-elf/relr-addend.d new file mode 100644 index 00000000000..da13c2cf823 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-addend.d @@ -0,0 +1,11 @@ +#ld: -shared -z pack-relative-relocs -T relr-relocs.ld +#objdump: -s -j.got -j.data + +.*: file format elf64-loongarch + +Contents of section \.got: + 20000 [0-9a-f]+ [0-9a-f]+ 00003412 00000000 .* + 20010 08003412 00000000 .* +Contents of section \.data: + 12340000 14451100 00000000 10989101 00000000 .* + 12340010 00003412 00000000 08003412 00000000 .* diff --git a/ld/testsuite/ld-loongarch-elf/relr-addend.s b/ld/testsuite/ld-loongarch-elf/relr-addend.s new file mode 100644 index 00000000000..3d08f6ca0ae --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-addend.s @@ -0,0 +1,17 @@ +.data +.align 8 +x: + .quad 0x114514 +y: + .quad 0x1919810 +px: + .quad x +py: + .quad y + +.text +.align 2 +_start: + la.got $a0, x + la.got $a1, y + ret diff --git a/ld/testsuite/ld-loongarch-elf/relr-align.d b/ld/testsuite/ld-loongarch-elf/relr-align.d new file mode 100644 index 00000000000..d534243b2a5 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-align.d @@ -0,0 +1,22 @@ +#source: relr-align.s +#ld: -shared -z pack-relative-relocs -T relr-relocs.ld +#readelf: -rW + +Relocation section '\.rela.dyn' at offset 0x[0-9a-f]+ contains 3 entries: + Offset Info Type Symbol's Value Symbol's Name \+ Addend +0000000012340011 0000000000000003 R_LARCH_RELATIVE 10000 +0000000012340019 0000000000000003 R_LARCH_RELATIVE 10000 +0000000012340041 0000000000000003 R_LARCH_RELATIVE 10000 + +Relocation section '\.relr.dyn' at offset 0x[0-9a-f]+ contains 9 entries which relocate 10 locations: +Index: Entry Address Symbolic Address +0000: 0000000012340000 0000000012340000 double_0 +0001: 0000000000000003 0000000012340008 double_0 \+ 0x8 +0002: 0000000012340022 0000000012340022 double_2 +0003: 0000000000000003 000000001234002a double_2 \+ 0x8 +0004: 0000000012340038 0000000012340038 single_0 +0005: 000000001234004a 000000001234004a single_2 +0006: 0000000012340058 0000000012340058 big +0007: 8000000100000001 0000000012340158 big \+ 0x100 + 0000000012340250 big \+ 0x1f8 +0008: 0000000000000003 0000000012340258 big \+ 0x200 diff --git a/ld/testsuite/ld-loongarch-elf/relr-align.s b/ld/testsuite/ld-loongarch-elf/relr-align.s new file mode 100644 index 00000000000..ddd055ab74e --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-align.s @@ -0,0 +1,106 @@ +# Test DT_RELR with differently aligned relative relocs. + +.text +.global _start +_start: +foo: + +.data +.p2align 3 +double_0: +.quad foo +.quad foo +.byte 0 +double_1: +.quad foo +.quad foo +.byte 0 +double_2: +.quad foo +.quad foo +.byte 0 +.byte 0 +.byte 0 +.byte 0 +.byte 0 +.byte 0 +single_0: +.quad foo +.byte 0 +single_1: +.quad foo +.byte 0 +single_2: +.quad foo +.byte 0 +.byte 0 +.byte 0 +.byte 0 +.byte 0 +.byte 0 +big: +.quad foo +.quad 1 +.quad 2 +.quad 3 +.quad 4 +.quad 5 +.quad 6 +.quad 7 +.quad 8 +.quad 9 +.quad 10 +.quad 11 +.quad 12 +.quad 13 +.quad 14 +.quad 15 +.quad 16 +.quad 17 +.quad 18 +.quad 19 +.quad 20 +.quad 21 +.quad 22 +.quad 23 +.quad 24 +.quad 25 +.quad 26 +.quad 27 +.quad 28 +.quad 29 +.quad 30 +.quad 31 +.quad foo + 32 +.quad 33 +.quad 34 +.quad 35 +.quad 36 +.quad 37 +.quad 38 +.quad 39 +.quad 40 +.quad 41 +.quad 42 +.quad 43 +.quad 44 +.quad 45 +.quad 46 +.quad 47 +.quad 48 +.quad 49 +.quad 50 +.quad 51 +.quad 52 +.quad 53 +.quad 54 +.quad 55 +.quad 56 +.quad 57 +.quad 58 +.quad 59 +.quad 60 +.quad 61 +.quad 62 +.quad foo + 63 +.quad foo + 64 diff --git a/ld/testsuite/ld-loongarch-elf/relr-data-pie.d b/ld/testsuite/ld-loongarch-elf/relr-data-pie.d new file mode 100644 index 00000000000..20ef9ac1c84 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-data-pie.d @@ -0,0 +1,18 @@ +#source: relr-data.s +#ld: -pie -z pack-relative-relocs -T relr-relocs.ld +#readelf: -rW + +Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains 5 entries: + Offset Info Type Symbol's Value Symbol's Name \+ Addend +0000000012340000 0000000000000003 R_LARCH_RELATIVE 10004 +0000000012340008 0000000000000003 R_LARCH_RELATIVE 10008 +0000000012340010 0000000000000003 R_LARCH_RELATIVE 1000c +0000000012340018 0000000000000003 R_LARCH_RELATIVE 12340050 +0000000012340040 0000000c00000002 R_LARCH_64 0000000000000000 sym_weak_undef \+ 0 + +Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries which relocate 4 locations: +Index: Entry Address Symbolic Address +0000: 0000000012340020 0000000012340020 aligned_local +0001: 0000000000000027 0000000012340028 aligned_hidden + 0000000012340030 aligned_global + 0000000012340048 aligned_DYNAMIC diff --git a/ld/testsuite/ld-loongarch-elf/relr-data-shared.d b/ld/testsuite/ld-loongarch-elf/relr-data-shared.d new file mode 100644 index 00000000000..37e4c0da83e --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-data-shared.d @@ -0,0 +1,18 @@ +#source: relr-data.s +#ld: -shared -z pack-relative-relocs -T relr-relocs.ld +#readelf: -rW + +Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains 6 entries: + Offset Info Type Symbol's Value Symbol's Name \+ Addend +0000000012340000 0000000000000003 R_LARCH_RELATIVE 10004 +0000000012340008 0000000000000003 R_LARCH_RELATIVE 10008 +0000000012340018 0000000000000003 R_LARCH_RELATIVE 12340050 +0000000012340010 0000000d00000002 R_LARCH_64 000000000001000c sym_global \+ 0 +0000000012340030 0000000d00000002 R_LARCH_64 000000000001000c sym_global \+ 0 +0000000012340040 0000000c00000002 R_LARCH_64 0000000000000000 sym_weak_undef \+ 0 + +Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries which relocate 3 locations: +Index: Entry Address Symbolic Address +0000: 0000000012340020 0000000012340020 aligned_local +0001: 0000000000000023 0000000012340028 aligned_hidden + 0000000012340048 aligned_DYNAMIC diff --git a/ld/testsuite/ld-loongarch-elf/relr-data.s b/ld/testsuite/ld-loongarch-elf/relr-data.s new file mode 100644 index 00000000000..03673e0fbd2 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-data.s @@ -0,0 +1,71 @@ +# Test symbol references in .data when used with DT_RELR. +# Relocations for unaligned sections are currently not packed. + +.text +.global _start +_start: + nop + +sym_local: + nop + +.global sym_hidden +.hidden sym_hidden +sym_hidden: + nop + +.global sym_global +sym_global: + nop + +.global sym_global_abs +.set sym_global_abs, 42 + +.global sym_weak_undef +.weak sym_weak_undef + +.section .data.unaligned_local +unaligned_local: +.quad sym_local + +.section .data.unaligned_hidden +unaligned_hidden: +.quad sym_hidden + +.section .data.unaligned_global +unaligned_global: +.quad sym_global + +.section .data.unaligned_DYNAMIC +unaligned_DYNAMIC: +.quad _DYNAMIC + +.section .data.aligned_local +.p2align 1 +aligned_local: +.quad sym_local + +.section .data.aligned_hidden +.p2align 1 +aligned_hidden: +.quad sym_hidden + +.section .data.aligned_global +.p2align 1 +aligned_global: +.quad sym_global + +.section .data.aligned_global_abs +.p2align 1 +aligned_global_abs: +.quad sym_global_abs + +.section .data.aligned_weak_undef +.p2align 1 +aligned_weak_undef: +.quad sym_weak_undef + +.section .data.aligned_DYNAMIC +.p2align 1 +aligned_DYNAMIC: +.quad _DYNAMIC diff --git a/ld/testsuite/ld-loongarch-elf/relr-discard-pie.d b/ld/testsuite/ld-loongarch-elf/relr-discard-pie.d new file mode 100644 index 00000000000..4ea8ae5e7b4 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-discard-pie.d @@ -0,0 +1,8 @@ +#source: relr-discard.s +#ld: -pie -z pack-relative-relocs -T relr-discard.ld +#readelf: -rW + +Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries which relocate 2 locations: +Index: Entry Address Symbolic Address +0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8 +0001: 0000000000000003 0000000000020010 _GLOBAL_OFFSET_TABLE_ \+ 0x10 diff --git a/ld/testsuite/ld-loongarch-elf/relr-discard-shared.d b/ld/testsuite/ld-loongarch-elf/relr-discard-shared.d new file mode 100644 index 00000000000..8bfd8ba5add --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-discard-shared.d @@ -0,0 +1,11 @@ +#source: relr-discard.s +#ld: -shared -z pack-relative-relocs -T relr-discard.ld +#readelf: -rW + +Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains 1 entry: + Offset Info Type Symbol's Value Symbol's Name \+ Addend +0000000000020010 0000000300000002 R_LARCH_64 000000000001000c sym_global \+ 0 + +Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 1 entry which relocates 1 location: +Index: Entry Address Symbolic Address +0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8 diff --git a/ld/testsuite/ld-loongarch-elf/relr-discard.ld b/ld/testsuite/ld-loongarch-elf/relr-discard.ld new file mode 100644 index 00000000000..165f1ed2f11 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-discard.ld @@ -0,0 +1,13 @@ +OUTPUT_ARCH(loongarch64) +ENTRY(_start) +SECTIONS +{ + /DISCARD/ : { *(.discard.*) } + + . = 0x10000; + .text : { *(.text) } + . = 0x20000; + .got : { *(.got) *(.got.plt)} + . = 0x30000; + .data : { *(.data) *(.data.*) } +} diff --git a/ld/testsuite/ld-loongarch-elf/relr-discard.s b/ld/testsuite/ld-loongarch-elf/relr-discard.s new file mode 100644 index 00000000000..b52374a5498 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-discard.s @@ -0,0 +1,61 @@ +# Test DT_RELR with references in discarded sections. + +.text +.p2align 3 +.global _start +_start: + nop + +sym_local: + nop + +.global sym_hidden +.hidden sym_hidden +sym_hidden: + nop + +.global sym_global +sym_global: + nop + +.global sym_global_abs +.set sym_global_abs, 42 + +.global sym_weak_undef +.weak sym_weak_undef + +.section .discard.got_local,"ax" + la.got $a0, sym_local + +.section .discard.got_global,"ax" + la.got $a0, sym_global + +.section .discard.local,"a" +.p2align 1 +discard_local: +.quad sym_local + +.section .discard.hidden,"a" +.p2align 1 +discard_hidden: +.quad sym_hidden + +.section .discard.global,"a" +.p2align 1 +discard_global: +.quad sym_global + +.section .discard.global_abs,"a" +.p2align 1 +discard_global_abs: +.quad sym_global_abs + +.section .discard.weak_undef,"a" +.p2align 1 +discard_weak_undef: +.quad sym_weak_undef + +.section .discard._DYNAMIC,"a" +.p2align 1 +discard_DYNAMIC: +.quad _DYNAMIC diff --git a/ld/testsuite/ld-loongarch-elf/relr-got-pie.d b/ld/testsuite/ld-loongarch-elf/relr-got-pie.d new file mode 100644 index 00000000000..e994f2bfe01 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-got-pie.d @@ -0,0 +1,15 @@ +#source: relr-got.s +#ld: -pie -z pack-relative-relocs -T relr-relocs.ld +#readelf: -rW + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries: + Offset Info Type Symbol's Value Symbol's Name \+ Addend +0000000000000000 0000000000000000 R_LARCH_NONE 0 +0000000000020030 0000000200000002 R_LARCH_64 0000000000000000 sym_weak_undef \+ 0 + +Relocation section '.relr.dyn' at offset 0x[0-9a-f]+ contains 2 entries which relocate 4 locations: +Index: Entry Address Symbolic Address +0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8 +0001: 000000000000000f 0000000000020010 _GLOBAL_OFFSET_TABLE_ \+ 0x10 + 0000000000020018 _GLOBAL_OFFSET_TABLE_ \+ 0x18 + 0000000000020020 _GLOBAL_OFFSET_TABLE_ \+ 0x20 diff --git a/ld/testsuite/ld-loongarch-elf/relr-got-shared.d b/ld/testsuite/ld-loongarch-elf/relr-got-shared.d new file mode 100644 index 00000000000..169e0e5d69d --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-got-shared.d @@ -0,0 +1,15 @@ +#source: relr-got.s +#ld: -shared -z pack-relative-relocs -T relr-relocs.ld +#readelf: -rW + +Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains 3 entries: + Offset Info Type Symbol's Value Symbol's Name \+ Addend +0000000000020020 0000000300000002 R_LARCH_64 0000000000010034 sym_global \+ 0 +0000000000020028 0000000500000002 R_LARCH_64 000000000000002a sym_global_abs \+ 0 +0000000000020030 0000000200000002 R_LARCH_64 0000000000000000 sym_weak_undef \+ 0 + +Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries which relocate 3 locations: +Index: Entry Address Symbolic Address +0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8 +0001: 0000000000000007 0000000000020010 _GLOBAL_OFFSET_TABLE_ \+ 0x10 + 0000000000020018 _GLOBAL_OFFSET_TABLE_ \+ 0x18 diff --git a/ld/testsuite/ld-loongarch-elf/relr-got.s b/ld/testsuite/ld-loongarch-elf/relr-got.s new file mode 100644 index 00000000000..162528bc7e6 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-got.s @@ -0,0 +1,27 @@ +.text +.global _start +_start: + la.got $a0, sym_local + la.got $a1, sym_hidden + la.got $a2, sym_global + la.got $a3, sym_global_abs + la.got $a4, sym_weak_undef + la.got $a5, _DYNAMIC + +sym_local: + nop + +.global sym_hidden +.hidden sym_hidden +sym_hidden: + nop + +.global sym_global +sym_global: + nop + +.global sym_global_abs +.set sym_global_abs, 42 + +.global sym_weak_undef +.weak sym_weak_undef diff --git a/ld/testsuite/ld-loongarch-elf/relr-relocs.ld b/ld/testsuite/ld-loongarch-elf/relr-relocs.ld new file mode 100644 index 00000000000..ed83275b629 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-relocs.ld @@ -0,0 +1,24 @@ +/* Script for DT_RELR tests */ +OUTPUT_ARCH(loongarch64) +ENTRY(_start) +SECTIONS +{ + PROVIDE (__executable_start = 0x8000); . = 0x10000; + .text : + { + *(.before) + *(.text) + *(.after) + } =0 + . = 0x20000; + .got : + { + *(.got) + *(.got.plt) + } + . = 0x12340000; + .data : + { + *(.data) + } +} diff --git a/ld/testsuite/ld-loongarch-elf/relr-text-pie.d b/ld/testsuite/ld-loongarch-elf/relr-text-pie.d new file mode 100644 index 00000000000..8e34500fbd2 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-text-pie.d @@ -0,0 +1,14 @@ +#source: relr-text.s +#ld: -shared -z pack-relative-relocs -T relr-relocs.ld +#readelf: -drW + +#... + 0x0000000000000016 \(TEXTREL\) 0x0 +#... + 0x0000000000000024 \(RELR\) .* + 0x0000000000000023 \(RELRSZ\) 8 \(bytes\) + 0x0000000000000025 \(RELRENT\) 8 \(bytes\) +#... +Relocation section '\.relr\.dyn' .* contains 1 entry which relocates 1 location: +Index: Entry Address Symbolic Address +0000: 0000000000010000 0000000000010000 _start diff --git a/ld/testsuite/ld-loongarch-elf/relr-text-shared.d b/ld/testsuite/ld-loongarch-elf/relr-text-shared.d new file mode 100644 index 00000000000..8e34500fbd2 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-text-shared.d @@ -0,0 +1,14 @@ +#source: relr-text.s +#ld: -shared -z pack-relative-relocs -T relr-relocs.ld +#readelf: -drW + +#... + 0x0000000000000016 \(TEXTREL\) 0x0 +#... + 0x0000000000000024 \(RELR\) .* + 0x0000000000000023 \(RELRSZ\) 8 \(bytes\) + 0x0000000000000025 \(RELRENT\) 8 \(bytes\) +#... +Relocation section '\.relr\.dyn' .* contains 1 entry which relocates 1 location: +Index: Entry Address Symbolic Address +0000: 0000000000010000 0000000000010000 _start diff --git a/ld/testsuite/ld-loongarch-elf/relr-text.s b/ld/testsuite/ld-loongarch-elf/relr-text.s new file mode 100644 index 00000000000..47465f2d8c4 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-text.s @@ -0,0 +1,10 @@ +# Test DT_RELR with DT_TEXTREL and R_LARCH_ALIGN. + +.text +.p2align 5 +.global _start +_start: +.global foo +.hidden foo +foo: +.quad foo