]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: Added ld testcases for the medlow and medany code models.
authorNelson Chu <nelson.chu@sifive.com>
Tue, 14 Dec 2021 04:53:48 +0000 (12:53 +0800)
committerNelson Chu <nelson.chu@sifive.com>
Tue, 14 Dec 2021 05:21:20 +0000 (13:21 +0800)
There are two linker scripts, code-model-01.ld and code-model-02.ld,
which are corresponding to the two different memory layouts,

* code-model-01.ld: the text section is in the 32-bit address range, but
  the data section is far away from the text section, which means the data
  section is over the 32-bit address range.

* code-model-02.ld: the text section is over the 32-bit address range, but
  the data section is placed nearly zero address.

We use the two linker scripts, to test the current medlow and medany behaviors
of GNU ld, including the weak symbol references and the relaxations behaviors.
Besides, these testcases also show the limits of the current medlow and medany
code models, that is - we may get the truncated to fit errors when linking
with the above two linker scripts.

ld/
* testsuite/ld-riscv-elf/code-model-01.ld: New testcases to test the
behaviors of the current medlow and medany code models.
* testsuite/ld-riscv-elf/code-model-02.ld: Likewise.
* testsuite/ld-riscv-elf/code-model-medany-01.d: Likewise.
* testsuite/ld-riscv-elf/code-model-medany-02.d: Likewise.
* testsuite/ld-riscv-elf/code-model-medany-weakref-01.d: Likewise.
* testsuite/ld-riscv-elf/code-model-medany-weakref-02.d: Likewise.
* testsuite/ld-riscv-elf/code-model-medlow-01.d: Likewise.
* testsuite/ld-riscv-elf/code-model-medlow-02.d: Likewise.
* testsuite/ld-riscv-elf/code-model-medlow-weakref-01.d: Likewise.
* testsuite/ld-riscv-elf/code-model-medlow-weakref-02.d: Likewise.
* testsuite/ld-riscv-elf/code-model-relax-medany-01.d: Likewise.
* testsuite/ld-riscv-elf/code-model-relax-medany-02.d: Likewise.
* testsuite/ld-riscv-elf/code-model-relax-medany-weakref-01.d: Likewise.
* testsuite/ld-riscv-elf/code-model-relax-medany-weakref-02.d: Likewise.
* testsuite/ld-riscv-elf/code-model-relax-medlow-01.d: Likewise.
* testsuite/ld-riscv-elf/code-model-relax-medlow-02.d: Likewise.
* testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-01.d: Likewise.
* testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-02.d: Likewise.
* testsuite/ld-riscv-elf/code-model.s: Likewise.
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.

20 files changed:
ld/testsuite/ld-riscv-elf/code-model-01.ld [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-02.ld [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-medany-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-medany-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-medany-weakref-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-medany-weakref-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-medlow-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-medlow-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-medlow-weakref-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-medlow-weakref-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-relax-medany-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-relax-medany-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-relax-medany-weakref-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-relax-medany-weakref-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-relax-medlow-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-relax-medlow-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/code-model.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp

diff --git a/ld/testsuite/ld-riscv-elf/code-model-01.ld b/ld/testsuite/ld-riscv-elf/code-model-01.ld
new file mode 100644 (file)
index 0000000..676f084
--- /dev/null
@@ -0,0 +1,24 @@
+/* text: in the 32-bit address range.
+   data: far away from text. */
+
+ENTRY(_start)
+MEMORY
+{
+       rom (rx)  : ORIGIN = 0x10000, LENGTH = 0x1000
+       ram (!rx) : ORIGIN = 0x800000000, LENGTH = 0x1000
+}
+SECTIONS {
+       .text : {
+               *(.text*)
+       } >rom
+
+       .data : {
+               *(.data*)
+       } >ram
+
+       __global_pointer$ = .;
+
+       .got : {
+               *(.got*)
+       } > ram
+}
diff --git a/ld/testsuite/ld-riscv-elf/code-model-02.ld b/ld/testsuite/ld-riscv-elf/code-model-02.ld
new file mode 100644 (file)
index 0000000..af8a2fe
--- /dev/null
@@ -0,0 +1,24 @@
+/* text: over the 32-bit address range.
+   data: far away from text, and nearly-zero. */
+
+ENTRY(_start)
+MEMORY
+{
+       rom (rx)  : ORIGIN = 0x800000000, LENGTH = 0x1000
+       ram (!rx) : ORIGIN = 0x10, LENGTH = 0x1000
+}
+SECTIONS {
+       .text : {
+               *(.text*)
+       } >rom
+
+       .data : {
+               *(.data*)
+       } >ram
+
+       __global_pointer$ = .;
+
+       .got : {
+               *(.got*)
+       } > ram
+}
diff --git a/ld/testsuite/ld-riscv-elf/code-model-medany-01.d b/ld/testsuite/ld-riscv-elf/code-model-medany-01.d
new file mode 100644 (file)
index 0000000..071eee8
--- /dev/null
@@ -0,0 +1,4 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medany__=1
+#ld: -Tcode-model-01.ld -melf64lriscv --no-relax
+#error: .*relocation truncated to fit: R_RISCV_GOT_HI20 against symbol `symbolG'
diff --git a/ld/testsuite/ld-riscv-elf/code-model-medany-02.d b/ld/testsuite/ld-riscv-elf/code-model-medany-02.d
new file mode 100644 (file)
index 0000000..017a1dc
--- /dev/null
@@ -0,0 +1,17 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medany__=1
+#ld: -Tcode-model-02.ld -melf64lriscv --no-relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+800000000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x[0-9a-f]+
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+ld[   ]+t0,[0-9]+\(t0\) # [0-9a-f]+ <_GLOBAL_OFFSET_TABLE_\+0x[0-9a-f]+>
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x[0-9a-f]+
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,t0,[0-9]+ # [0-9a-f]+ <symbolL>
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x[0-9a-f]+
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,t0,[0-9]+ # [0-9a-f]+ <symbolG>
diff --git a/ld/testsuite/ld-riscv-elf/code-model-medany-weakref-01.d b/ld/testsuite/ld-riscv-elf/code-model-medany-weakref-01.d
new file mode 100644 (file)
index 0000000..0fe5c45
--- /dev/null
@@ -0,0 +1,4 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medany__=1 --defsym __undefweak__=1
+#ld: -Tcode-model-01.ld -melf64lriscv --no-relax
+#error: .*relocation truncated to fit: R_RISCV_GOT_HI20 against undefined symbol `symbolW'
diff --git a/ld/testsuite/ld-riscv-elf/code-model-medany-weakref-02.d b/ld/testsuite/ld-riscv-elf/code-model-medany-weakref-02.d
new file mode 100644 (file)
index 0000000..2b3aaae
--- /dev/null
@@ -0,0 +1,13 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medany__=1 --defsym __undefweak__=1
+#ld: -Tcode-model-02.ld -melf64lriscv --no-relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+800000000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x0
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+ld[   ]+t0,[0-9]+\(t0\) # [0-9a-f]+ <_GLOBAL_OFFSET_TABLE_\+0x[0-9a-f]+>
diff --git a/ld/testsuite/ld-riscv-elf/code-model-medlow-01.d b/ld/testsuite/ld-riscv-elf/code-model-medlow-01.d
new file mode 100644 (file)
index 0000000..a923893
--- /dev/null
@@ -0,0 +1,4 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medlow__=1
+#ld: -Tcode-model-01.ld -melf64lriscv --no-relax
+#error: .*relocation truncated to fit: R_RISCV_HI20 against `symbolL'
diff --git a/ld/testsuite/ld-riscv-elf/code-model-medlow-02.d b/ld/testsuite/ld-riscv-elf/code-model-medlow-02.d
new file mode 100644 (file)
index 0000000..1168863
--- /dev/null
@@ -0,0 +1,15 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medlow__=1
+#ld: -Tcode-model-02.ld -melf64lriscv --no-relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+800000000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x[0-9a-f]+
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,t0,[0-9]+ # [0-9a-f]+ <symbolL>
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x[0-9a-f]+
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,t0,[0-9]+ # [0-9a-f]+ <symbolG>
diff --git a/ld/testsuite/ld-riscv-elf/code-model-medlow-weakref-01.d b/ld/testsuite/ld-riscv-elf/code-model-medlow-weakref-01.d
new file mode 100644 (file)
index 0000000..28f8fe9
--- /dev/null
@@ -0,0 +1,13 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medlow__=1 --defsym __undefweak__=1
+#ld: -Tcode-model-01.ld -melf64lriscv --no-relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+10000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x0
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,t0,0 # 0 <.*>
diff --git a/ld/testsuite/ld-riscv-elf/code-model-medlow-weakref-02.d b/ld/testsuite/ld-riscv-elf/code-model-medlow-weakref-02.d
new file mode 100644 (file)
index 0000000..405b0fe
--- /dev/null
@@ -0,0 +1,13 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medlow__=1 --defsym __undefweak__=1
+#ld: -Tcode-model-02.ld -melf64lriscv --no-relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+800000000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x0
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,t0,0 # 0 <.*>
diff --git a/ld/testsuite/ld-riscv-elf/code-model-relax-medany-01.d b/ld/testsuite/ld-riscv-elf/code-model-relax-medany-01.d
new file mode 100644 (file)
index 0000000..afa24ef
--- /dev/null
@@ -0,0 +1,4 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medany__=1
+#ld: -Tcode-model-01.ld -melf64lriscv --relax
+#error: .*relocation truncated to fit: R_RISCV_GOT_HI20 against symbol `symbolG'
diff --git a/ld/testsuite/ld-riscv-elf/code-model-relax-medany-02.d b/ld/testsuite/ld-riscv-elf/code-model-relax-medany-02.d
new file mode 100644 (file)
index 0000000..7b5b9e9
--- /dev/null
@@ -0,0 +1,15 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medany__=1
+#ld: -Tcode-model-02.ld -melf64lriscv --relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+800000000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x[0-9a-f]+
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+ld[   ]+t0,[0-9]+\(t0\) # [0-9a-f]+ <_GLOBAL_OFFSET_TABLE_\+0x[0-9a-f]+>
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,zero,[0-9]+
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,zero,[0-9]+
diff --git a/ld/testsuite/ld-riscv-elf/code-model-relax-medany-weakref-01.d b/ld/testsuite/ld-riscv-elf/code-model-relax-medany-weakref-01.d
new file mode 100644 (file)
index 0000000..5b2d1ea
--- /dev/null
@@ -0,0 +1,4 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medany__=1 --defsym __undefweak__=1
+#ld: -Tcode-model-01.ld -melf64lriscv --relax
+#error: .*relocation truncated to fit: R_RISCV_GOT_HI20 against undefined symbol `symbolW'
diff --git a/ld/testsuite/ld-riscv-elf/code-model-relax-medany-weakref-02.d b/ld/testsuite/ld-riscv-elf/code-model-relax-medany-weakref-02.d
new file mode 100644 (file)
index 0000000..783be0c
--- /dev/null
@@ -0,0 +1,13 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medany__=1 --defsym __undefweak__=1
+#ld: -Tcode-model-02.ld -melf64lriscv --relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+800000000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+lui[  ]+t0,0x0
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+ld[   ]+t0,[0-9]+\(t0\) # [0-9a-f]+ <_GLOBAL_OFFSET_TABLE_\+0x[0-9a-f]+>
diff --git a/ld/testsuite/ld-riscv-elf/code-model-relax-medlow-01.d b/ld/testsuite/ld-riscv-elf/code-model-relax-medlow-01.d
new file mode 100644 (file)
index 0000000..eea2f7d
--- /dev/null
@@ -0,0 +1,13 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medlow__=1
+#ld: -Tcode-model-01.ld -melf64lriscv --relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+10000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,gp,\-[0-9]+ # [0-9a-f]+ <symbolL>
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,gp,\-[0-9]+ # [0-9a-f]+ <symbolG>
diff --git a/ld/testsuite/ld-riscv-elf/code-model-relax-medlow-02.d b/ld/testsuite/ld-riscv-elf/code-model-relax-medlow-02.d
new file mode 100644 (file)
index 0000000..adc81f5
--- /dev/null
@@ -0,0 +1,13 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medlow__=1
+#ld: -Tcode-model-02.ld -melf64lriscv --relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+800000000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,zero,[0-9]+
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,zero,[0-9]+
diff --git a/ld/testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-01.d b/ld/testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-01.d
new file mode 100644 (file)
index 0000000..b1f2203
--- /dev/null
@@ -0,0 +1,12 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medlow__=1 --defsym __undefweak__=1
+#ld: -Tcode-model-01.ld -melf64lriscv --relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+10000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,zero,0
diff --git a/ld/testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-02.d b/ld/testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-02.d
new file mode 100644 (file)
index 0000000..332046d
--- /dev/null
@@ -0,0 +1,12 @@
+#source: code-model.s
+#as: -march=rv64i -mabi=lp64 --defsym __medlow__=1 --defsym __undefweak__=1
+#ld: -Tcode-model-02.ld -melf64lriscv --relax
+#objdump: -d -Mno-aliases
+
+.*:[   ]+file format .*
+
+
+Disassembly of section .text:
+
+0+800000000 <_start>:
+[      ]+[0-9a-f]+:[   ]+[0-9a-f]+[    ]+addi[         ]+t0,zero,0
diff --git a/ld/testsuite/ld-riscv-elf/code-model.s b/ld/testsuite/ld-riscv-elf/code-model.s
new file mode 100644 (file)
index 0000000..a88301a
--- /dev/null
@@ -0,0 +1,47 @@
+       .text
+       .global _start
+_start:
+
+.ifdef __medany__
+       .option pic
+.ifdef __undefweak__
+       # Refer to undefined weak symbol by GOT_PCREL.
+       la      t0, symbolW
+       .option nopic
+.else
+       # Refer to global data symbol by GOT_PCREL.
+       la      t0, symbolG
+       .option nopic
+       # Refer to local data symbol by PCREL.
+       lla     t0, symbolL
+       # Refer to non-pic data global symbol by PCREL.
+       la      t0, symbolG
+.endif
+.endif
+
+.ifdef __medlow__
+.ifdef __undefweak__
+       # Refer to undefined weak symbol by absolutely access.
+       lui     t0, %hi(symbolW)
+       addi    t0, t0, %lo(symbolW)
+.else
+       # Refer to local data symbol by absolutely access.
+       lui     t0, %hi(symbolL)
+       addi    t0, t0, %lo(symbolL)
+       # Refer to global data symbol by absolutely access.
+       lui     t0, %hi(symbolG)
+       addi    t0, t0, %lo(symbolG)
+.endif
+.endif
+       .size   _start, .-_start
+
+       .data
+       .global symbolG
+symbolL:
+       .dword  0x1111222233334444
+symbolG:
+       .dword  0x5555666677778888
+
+.ifdef __undefweak__
+       .weak   symbolW
+.endif
index 3bd788208ed591c64b94316fe4c88df754243111..961f06433fa227b4f164a1d2b79d841cea42f118 100644 (file)
@@ -132,6 +132,22 @@ if [istarget "riscv*-*-*"] {
     run_dump_test "pcrel-lo-addend-3a"
     run_dump_test "pcrel-lo-addend-3b"
     run_dump_test "pcrel-lo-addend-3c"
+    run_dump_test "code-model-medlow-01"
+    run_dump_test "code-model-medlow-02"
+    run_dump_test "code-model-medlow-weakref-01"
+    run_dump_test "code-model-medlow-weakref-02"
+    run_dump_test "code-model-medany-01"
+    run_dump_test "code-model-medany-02"
+    run_dump_test "code-model-medany-weakref-01"
+    run_dump_test "code-model-medany-weakref-02"
+    run_dump_test "code-model-relax-medlow-01"
+    run_dump_test "code-model-relax-medlow-02"
+    run_dump_test "code-model-relax-medlow-weakref-01"
+    run_dump_test "code-model-relax-medlow-weakref-02"
+    run_dump_test "code-model-relax-medany-01"
+    run_dump_test "code-model-relax-medany-02"
+    run_dump_test "code-model-relax-medany-weakref-01"
+    run_dump_test "code-model-relax-medany-weakref-02"
     run_dump_test "attr-merge-arch-01"
     run_dump_test "attr-merge-arch-02"
     run_dump_test "attr-merge-arch-03"