diff options
Diffstat (limited to 'ld/testsuite')
196 files changed, 2575 insertions, 438 deletions
diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp index 8374920..9ffcc58 100644 --- a/ld/testsuite/config/default.exp +++ b/ld/testsuite/config/default.exp @@ -519,9 +519,9 @@ if { [check_compiler_available] } { cyglto_plugin-0.dll } foreach plug $plugin_names { - set plug_so [run_host_cmd $CC_FOR_TARGET "--print-prog-name $plug"] + set plug_so [string trim [run_host_cmd $CC_FOR_TARGET "--print-prog-name $plug"]] if { $plug_so eq $plug } then { - set plug_so [run_host_cmd $CC_FOR_TARGET "--print-file-name $plug"] + set plug_so [string trim [run_host_cmd $CC_FOR_TARGET "--print-file-name $plug"]] } if { $plug_so ne $plug } then { set plug_opt "--plugin $plug_so" diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp index 272d518..7fa4520 100644 --- a/ld/testsuite/ld-arm/arm-elf.exp +++ b/ld/testsuite/ld-arm/arm-elf.exp @@ -653,10 +653,10 @@ set armeabitests_nonacl { {{objdump -d thumb2-bl-bad.d}} "thumb2-bl-bad"} {"Branch to linker script symbol with BL for thumb-only target" "-T branch-lks-sym.ld" "" "" {thumb-bl-lks-sym.s} - {{objdump -d thumb-bl-lks-sym.d}} + {{ld thumb-bl-lks-sym.output} {objdump -d thumb-bl-lks-sym.d}} "thumb-bl-lks-sym"} {"Branch to linker script symbol with B for thumb-only target" "-T branch-lks-sym.ld" "" "" {thumb-b-lks-sym.s} - {{objdump -d thumb-b-lks-sym.d}} + {{ld thumb-b-lks-sym.output} {objdump -d thumb-b-lks-sym.d}} "thumb-b-lks-sym"} {"erratum 760522 fix (default for v6z)" "--section-start=.foo=0x2001014" "" @@ -1207,6 +1207,8 @@ run_dump_test "attr-merge-wchar-40-nowarn" run_dump_test "attr-merge-wchar-42-nowarn" run_dump_test "attr-merge-wchar-44-nowarn" run_dump_test "farcall-section" +run_dump_test "farcall-missing-type" +run_dump_test "farcall-missing-type-undefweak" run_dump_test "attr-merge-unknown-1" run_dump_test "attr-merge-unknown-2" run_dump_test "attr-merge-unknown-2r" diff --git a/ld/testsuite/ld-arm/attr-merge-arch-2b.s b/ld/testsuite/ld-arm/attr-merge-arch-2b.s index 5771835..f20522f 100644 --- a/ld/testsuite/ld-arm/attr-merge-arch-2b.s +++ b/ld/testsuite/ld-arm/attr-merge-arch-2b.s @@ -4,5 +4,6 @@ .align 2 .global foo .type foo, %function + .thumb_func foo: bx lr diff --git a/ld/testsuite/ld-arm/bfs-1.s b/ld/testsuite/ld-arm/bfs-1.s index 2b72819..1e31d44 100644 --- a/ld/testsuite/ld-arm/bfs-1.s +++ b/ld/testsuite/ld-arm/bfs-1.s @@ -4,6 +4,7 @@ .thumb .global _start .global target +.type target, %function _start: target: add r0, r0, r1 diff --git a/ld/testsuite/ld-arm/branch-futures.d b/ld/testsuite/ld-arm/branch-futures.d index 427ecce..bc9ae8e 100644 --- a/ld/testsuite/ld-arm/branch-futures.d +++ b/ld/testsuite/ld-arm/branch-futures.d @@ -5,13 +5,13 @@ Disassembly of section .text: 0[0-9a-f]+ <future>: - [0-9a-f]+: f2c0 e807 bf a, 8012 <_start> - [0-9a-f]+: f182 e805 bfcsel 6, 8012 <_start>, a, eq - [0-9a-f]+: f080 c803 bfl 2, 8012 <_start> + [0-9a-f]+: f2c0 e807 bf a, 8012 <target> + [0-9a-f]+: f182 e805 bfcsel 6, 8012 <target>, a, eq + [0-9a-f]+: f080 c803 bfl 2, 8012 <target> [0-9a-f]+: 4408 add r0, r1 0[0-9a-f]+ <branch>: - [0-9a-f]+: f000 b800 b.w 8012 <_start> + [0-9a-f]+: f000 b800 b.w 8012 <target> -0[0-9a-f]+ <_start>: +0[0-9a-f]+ <target>: [0-9a-f]+: 4408 add r0, r1 diff --git a/ld/testsuite/ld-arm/farcall-missing-type-bad.s b/ld/testsuite/ld-arm/farcall-missing-type-bad.s new file mode 100644 index 0000000..e087992 --- /dev/null +++ b/ld/testsuite/ld-arm/farcall-missing-type-bad.s @@ -0,0 +1,7 @@ + .thumb + .cpu cortex-m33 + .syntax unified + .section .text.bar + .global bad @ untyped +# .type bad, function +bad: bx lr diff --git a/ld/testsuite/ld-arm/farcall-missing-type-main-undefweak.s b/ld/testsuite/ld-arm/farcall-missing-type-main-undefweak.s new file mode 100644 index 0000000..cf72722 --- /dev/null +++ b/ld/testsuite/ld-arm/farcall-missing-type-main-undefweak.s @@ -0,0 +1,10 @@ + .thumb + .cpu cortex-m33 + .syntax unified + .global __start + .weak bad + .type __start, function +__start: + push {r4, lr} + bl bad + pop {r4, pc} diff --git a/ld/testsuite/ld-arm/farcall-missing-type-main.s b/ld/testsuite/ld-arm/farcall-missing-type-main.s new file mode 100644 index 0000000..c97df0c --- /dev/null +++ b/ld/testsuite/ld-arm/farcall-missing-type-main.s @@ -0,0 +1,9 @@ + .thumb + .cpu cortex-m33 + .syntax unified + .global __start + .type __start, function +__start: + push {r4, lr} + bl bad + pop {r4, pc} diff --git a/ld/testsuite/ld-arm/farcall-missing-type-undefweak.d b/ld/testsuite/ld-arm/farcall-missing-type-undefweak.d new file mode 100644 index 0000000..b6e123f --- /dev/null +++ b/ld/testsuite/ld-arm/farcall-missing-type-undefweak.d @@ -0,0 +1,11 @@ +#source: farcall-missing-type-main-undefweak.s +#as: +#ld:-T farcall-missing-type.ld +#objdump: -dr +#... +Disassembly of section .text: + +.* <__start>: + +[0-9a-f]+: .... .... push {r4, lr} + +[0-9a-f]+: .... .... nop.w + +[0-9a-f]+: .... .... pop {r4, pc} diff --git a/ld/testsuite/ld-arm/farcall-missing-type.d b/ld/testsuite/ld-arm/farcall-missing-type.d new file mode 100644 index 0000000..9766bf1 --- /dev/null +++ b/ld/testsuite/ld-arm/farcall-missing-type.d @@ -0,0 +1,5 @@ +#source: farcall-missing-type-main.s +#source: farcall-missing-type-bad.s +#as: +#ld:-T farcall-missing-type.ld +#error: .* .*/farcall-missing-type-bad.o\(bad\): Unknown destination type \(ARM/Thumb\) in .*/farcall-missing-type-main.o diff --git a/ld/testsuite/ld-arm/farcall-missing-type.ld b/ld/testsuite/ld-arm/farcall-missing-type.ld new file mode 100644 index 0000000..b1136de --- /dev/null +++ b/ld/testsuite/ld-arm/farcall-missing-type.ld @@ -0,0 +1,23 @@ +/* Linker script to configure memory regions. */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000 /* 256k */ + FLASH2 (rx) : ORIGIN = 0x200001e0, LENGTH = 0x4000 +} + +ENTRY(__start) + +SECTIONS +{ + .far_away_section : + { + *(.text.bar) + } > FLASH2 + + .text : + { + *(.text*) + + } > FLASH + +} diff --git a/ld/testsuite/ld-arm/thumb-b-lks-sym.output b/ld/testsuite/ld-arm/thumb-b-lks-sym.output new file mode 100644 index 0000000..4961204 --- /dev/null +++ b/ld/testsuite/ld-arm/thumb-b-lks-sym.output @@ -0,0 +1 @@ +.* \(extFunc\): Forcing branch to absolute symbol in Thumb mode \(Thumb-only CPU\) in tmpdir/thumb-b-lks-sym.o diff --git a/ld/testsuite/ld-arm/thumb-bl-lks-sym.output b/ld/testsuite/ld-arm/thumb-bl-lks-sym.output new file mode 100644 index 0000000..7c5e354 --- /dev/null +++ b/ld/testsuite/ld-arm/thumb-bl-lks-sym.output @@ -0,0 +1 @@ +.* \(extFunc\): Forcing branch to absolute symbol in Thumb mode \(Thumb-only CPU\) in tmpdir/thumb-bl-lks-sym.o diff --git a/ld/testsuite/ld-ctf/diag-parname.d b/ld/testsuite/ld-ctf/diag-parname.d index f8fcd68..4672f71 100644 --- a/ld/testsuite/ld-ctf/diag-parname.d +++ b/ld/testsuite/ld-ctf/diag-parname.d @@ -2,4 +2,4 @@ #source: diag-parname.s #ld: -shared --ctf-variables #name: Diagnostics - No parent dictionary -#warning: CTF linking failed; output will have no CTF section: The parent CTF dictionary is unavailable +#warning: CTF linking failed; output will have no CTF section: The parent CTF dictionary is needed but unavailable diff --git a/ld/testsuite/ld-elf/build-id.exp b/ld/testsuite/ld-elf/build-id.exp index 1bf258b..6bf8f3d 100644 --- a/ld/testsuite/ld-elf/build-id.exp +++ b/ld/testsuite/ld-elf/build-id.exp @@ -36,42 +36,71 @@ if { !([istarget *-*-linux*] return } -run_ld_link_tests [list \ - [list \ - "pr28639a.o" \ - "-r --build-id=md5" \ - "" \ - "" \ - {start.s} \ - {{readelf {--notes} pr28639a.rd}} \ - "pr28639a.o" \ - ] \ - [list \ - "pr28639a.o" \ - "-r --build-id" \ - "" \ - "" \ - {dummy.s} \ - {{readelf {--notes} pr28639b.rd}} \ - "pr28639b.o" \ - ] \ - [list \ - "pr28639a" \ - "--build-id tmpdir/pr28639a.o tmpdir/pr28639b.o" \ - "" \ - "" \ - {dummy.s} \ - {{readelf {--notes} pr28639b.rd} \ - {readelf {--notes} pr28639c.rd}} \ - "pr28639a" \ - ] \ - [list \ - "pr28639b" \ - "--build-id=none tmpdir/pr28639a.o tmpdir/pr28639b.o" \ - "" \ - "" \ - {dummy.s} \ - {{readelf {--notes} pr28639d.rd}} \ - "pr28639b" \ - ] \ -] + +set stylelist {"" "--build-id" "--build-id=none" "--build-id=md5" + "--build-id=sha1" "--build-id=guid" "--build-id=0xdeadbeef"} + +run_ld_link_tests { + { + "pr28639a.o" + "-r --build-id=md5" + "" + "" + {start.s} + {{readelf {--notes} pr28639a.rd}} + "pr28639a.o" + } + { + "pr28639b.o" + "-r --build-id" + "" + "" + {dummy.s} + {{readelf {--notes} pr28639b.rd}} + "pr28639b.o" + } + { + "pr28639a.o deadbeef" + "-r --build-id=0xdeadbeef" + "" + "" + {start.s} + {{readelf {--notes} pr28639e.rd}} + "pr28639a.o" + } + { + "pr28639a" + "--build-id tmpdir/pr28639a.o tmpdir/pr28639b.o" + "" + "" + {dummy.s} + {{readelf {--notes} pr28639b.rd} + {readelf {--notes} pr28639c.rd}} + "pr28639a" + } + { + "pr28639b" + "--build-id=none tmpdir/pr28639a.o tmpdir/pr28639b.o" + "" + "" + {dummy.s} + {{readelf {--notes} pr28639d.rd}} + "pr28639b" + } +} + +# see if linker supports xx style also +catch "exec $ld --help | grep -A2 -- --build-id | grep Styles" tmp +if {[string first ",xx," $tmp] >= 0} then { + run_ld_link_tests { + { + "pr28639a.o xx" + "-r --build-id=xx" + "" + "" + {start.s} + {{readelf {--notes} pr28639a.rd}} # 16 bytes + "pr28639a.o" + } + } +} diff --git a/ld/testsuite/ld-elf/dwarf.exp b/ld/testsuite/ld-elf/dwarf.exp index 1ca1ec5..670551f 100644 --- a/ld/testsuite/ld-elf/dwarf.exp +++ b/ld/testsuite/ld-elf/dwarf.exp @@ -52,9 +52,6 @@ set build_tests { {"DWARF parse during linker error" "" "-g -fno-toplevel-reorder" {dwarf2a.c dwarf2b.c} {{error_output "dwarf2.err"}} "dwarf2.x"} -} - -set build_tests_dwarf3 { {"Handle no DWARF information" "" "-g0" {dwarf3.c} {{error_output "dwarf3.err"}} "dwarf3.x"} @@ -75,8 +72,6 @@ set run_tests { set old_CFLAGS "$CFLAGS_FOR_TARGET" append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS" run_cc_link_tests $build_tests -setup_xfail loongarch*-*-* -run_cc_link_tests $build_tests_dwarf3 run_ld_link_exec_tests $run_tests set CFLAGS_FOR_TARGET "$old_CFLAGS" diff --git a/ld/testsuite/ld-elf/pr21884.d b/ld/testsuite/ld-elf/pr21884.d index e289b41..3d44ccf 100644 --- a/ld/testsuite/ld-elf/pr21884.d +++ b/ld/testsuite/ld-elf/pr21884.d @@ -3,7 +3,7 @@ #ld: -T pr21884.t #objdump: -b binary -s #xfail: aarch64*-*-* arm*-*-* avr-*-* ia64-*-* m68hc1*-*-* nds32*-*-* -#xfail: riscv*-*-* score-*-* v850-*-* loongarch*-*-* +#xfail: riscv*-*-* score-*-* v850-*-* # Skip targets which can't change output format to binary. .*: file format binary diff --git a/ld/testsuite/ld-elf/pr22393-1e.d b/ld/testsuite/ld-elf/pr22393-1e.d index 51d74fa..55f7e9a 100644 --- a/ld/testsuite/ld-elf/pr22393-1e.d +++ b/ld/testsuite/ld-elf/pr22393-1e.d @@ -2,7 +2,7 @@ #ld: -z separate-code #readelf: -l --wide #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi -#xfail: h8300-*-* rx-*-linux* +#xfail: rx-*-linux* #failif #... diff --git a/ld/testsuite/ld-elf/pr22393-1f.d b/ld/testsuite/ld-elf/pr22393-1f.d index 2a44955..bc61b63 100644 --- a/ld/testsuite/ld-elf/pr22393-1f.d +++ b/ld/testsuite/ld-elf/pr22393-1f.d @@ -2,7 +2,7 @@ #ld: -z separate-code #readelf: -l --wide #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi -#xfail: h8300-*-* rx-*-linux* +#xfail: rx-*-linux* #failif #... diff --git a/ld/testsuite/ld-elf/pr22393-2a.rd b/ld/testsuite/ld-elf/pr22393-2a.rd index 0050f1b..a9c5478 100644 --- a/ld/testsuite/ld-elf/pr22393-2a.rd +++ b/ld/testsuite/ld-elf/pr22393-2a.rd @@ -1,5 +1,5 @@ #source: pr22393-1.s -#ld: -shared -z separate-code +#ld: -shared -z separate-code --no-rosegment #readelf: -l --wide #target: *-*-linux-gnu *-*-gnu* *-*-nacl* diff --git a/ld/testsuite/ld-elf/pr22393-2b.rd b/ld/testsuite/ld-elf/pr22393-2b.rd index 0050f1b..a9c5478 100644 --- a/ld/testsuite/ld-elf/pr22393-2b.rd +++ b/ld/testsuite/ld-elf/pr22393-2b.rd @@ -1,5 +1,5 @@ #source: pr22393-1.s -#ld: -shared -z separate-code +#ld: -shared -z separate-code --no-rosegment #readelf: -l --wide #target: *-*-linux-gnu *-*-gnu* *-*-nacl* diff --git a/ld/testsuite/ld-elf/pr23658-1a.d b/ld/testsuite/ld-elf/pr23658-1a.d index 10c6ef3..c2caf49 100644 --- a/ld/testsuite/ld-elf/pr23658-1a.d +++ b/ld/testsuite/ld-elf/pr23658-1a.d @@ -3,16 +3,13 @@ #source: pr23658-1c.s #source: pr23658-1d.s #source: start.s -#ld: --build-id +#ld: --build-id --no-rosegment #readelf: -l --wide # Since generic linker targets don't place SHT_NOTE sections as orphan, # SHT_NOTE sections aren't grouped nor sorted. #xfail: [uses_genelf] -#xfail: m68hc12-* -# The following targets don't support --build-id. -#xfail: cr16-* crx-* visium-* # The following targets place .note.gnu.build-id in unusual places. -#xfail: pru-* +#xfail: d10v-* pru-* #... +[0-9]+ +\.note\.4 \.note\.1 + diff --git a/ld/testsuite/ld-elf/pr23658-1c.d b/ld/testsuite/ld-elf/pr23658-1c.d index 87aceca..6ab72dc 100644 --- a/ld/testsuite/ld-elf/pr23658-1c.d +++ b/ld/testsuite/ld-elf/pr23658-1c.d @@ -3,7 +3,7 @@ #source: pr23658-1c.s #source: pr23658-1d.s #source: start.s -#ld: --build-id -shared +#ld: --build-id --no-rosegment -shared #readelf: -l --wide #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi #xfail: ![check_shared_lib_support] diff --git a/ld/testsuite/ld-elf/pr23658-1e.d b/ld/testsuite/ld-elf/pr23658-1e.d new file mode 100644 index 0000000..dbb05e6 --- /dev/null +++ b/ld/testsuite/ld-elf/pr23658-1e.d @@ -0,0 +1,25 @@ +#source: pr23658-1a.s +#source: pr23658-1b.s +#source: pr23658-1c.s +#source: pr23658-1d.s +#source: start.s +#ld: --build-id -z separate-code --rosegment +#readelf: -l --wide +# Since generic linker targets don't place SHT_NOTE sections as orphan, +# SHT_NOTE sections aren't grouped nor sorted. .note.gnu.build-id is +# placed before text sections and there should no other note sections +# between .note.gnu.build-id and text sections. +#xfail: [uses_genelf] +# The following targets don't support --build-id. +#xfail: cr16-* crx-* visium-* +# The following targets place .note.gnu.build-id in unusual places. +#xfail: *-*-hpux* +#xfail: arc*-* avr-* m68hc1*-* microblaze*-* nds32*-* spu-*-* xstormy16-*-* +#noxfail: microblaze*-linux* + +#... + +[0-9]+ +\.note.gnu.build-id + +#... + +[0-9]+ +\.note\.4 \.note\.1 + + +[0-9]+ +\.note\.2 \.note\.3 + +#pass diff --git a/ld/testsuite/ld-elf/pr23658-1f.d b/ld/testsuite/ld-elf/pr23658-1f.d new file mode 100644 index 0000000..1823111 --- /dev/null +++ b/ld/testsuite/ld-elf/pr23658-1f.d @@ -0,0 +1,17 @@ +#source: pr23658-1a.s +#source: pr23658-1b.s +#source: pr23658-1c.s +#source: pr23658-1d.s +#source: start.s +#ld: --build-id -z separate-code --rosegment -shared +# .note.gnu.build-id is placed before text sections and there should +# no other note sections between .note.gnu.build-id and text sections. +#readelf: -l --wide +#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi +#xfail: ![check_shared_lib_support] + +#... + +[0-9]+ +\.note.gnu.build-id + + +[0-9]+ +\.note\.4 \.note\.1 + + +[0-9]+ +\.note\.2 \.note\.3 + +#pass diff --git a/ld/testsuite/ld-elf/pr25207.d b/ld/testsuite/ld-elf/pr25207.d new file mode 100644 index 0000000..945bae2 --- /dev/null +++ b/ld/testsuite/ld-elf/pr25207.d @@ -0,0 +1,11 @@ +#source: pr25207.s +#ld: -z separate-code --no-rosegment -Ttext-segment=0x120000 -z max-page-size=0x10000 +#readelf: -l --wide +#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi +# changing -Ttext-segment behaviour will break --image-base (pr25207) +# -Ttext-segment=<ADDR> should set the first segment address, +# not necessarily the first executable segment. + +#... + LOAD +0x0+ 0x0*120000 0x0*120000 0x[0-9a-f]+ 0x[0-9a-f]+ R .* +#pass diff --git a/ld/testsuite/ld-elf/pr25207.s b/ld/testsuite/ld-elf/pr25207.s new file mode 100644 index 0000000..6cfdfd0 --- /dev/null +++ b/ld/testsuite/ld-elf/pr25207.s @@ -0,0 +1,13 @@ + .section .text, "ax" + .globl main + .globl start + .globl _start + .globl __start +main: +start: +_start: +__start: + .byte 0 + + .section .rodata + .byte 0 diff --git a/ld/testsuite/ld-elf/pr28639e.rd b/ld/testsuite/ld-elf/pr28639e.rd new file mode 100644 index 0000000..15157ba --- /dev/null +++ b/ld/testsuite/ld-elf/pr28639e.rd @@ -0,0 +1,6 @@ +#... +Displaying notes found in: \.note\.gnu\.build-id + Owner Data size Description + GNU 0x00000004 NT_GNU_BUILD_ID \(unique build ID bitstring\) + Build ID: deadbeef +#pass diff --git a/ld/testsuite/ld-elf/pr30508.d b/ld/testsuite/ld-elf/pr30508.d index 325ff40..1692780 100644 --- a/ld/testsuite/ld-elf/pr30508.d +++ b/ld/testsuite/ld-elf/pr30508.d @@ -2,7 +2,7 @@ #objcopy_linked_file: -R .foo #readelf: -lW #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi -#xfail: h8300-*-* mips*-*-* rx-*-linux* +#xfail: mips*-*-* rx-*-linux* #... Section to Segment mapping: diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index 97ca778..e13e7e0 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -1410,7 +1410,7 @@ if { [istarget *-*-linux*] ] \ [list \ "Build pr22393-2a.so" \ - "-shared -Wl,-z,separate-code" \ + "-shared -Wl,-z,separate-code,--no-rosegment" \ "-fPIC" \ {pr22393-2a.c} \ {{readelf -lW pr22393-2a.rd} \ @@ -1419,7 +1419,7 @@ if { [istarget *-*-linux*] ] \ [list \ "Build pr22393-2a-now.so" \ - "-shared -Wl,-z,separate-code,-z,now" \ + "-shared -Wl,-z,separate-code,-z,now,--no-rosegment" \ "-fPIC" \ {pr22393-2a.c} \ {{readelf -lW pr22393-2a.rd} \ @@ -1428,7 +1428,7 @@ if { [istarget *-*-linux*] ] \ [list \ "Build pr22393-2" \ - "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \ + "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-rosegment,--no-as-needed tmpdir/pr22393-2a.so" \ "$NOPIE_CFLAGS" \ {pr22393-2b.c} \ {{readelf -lW pr22393-2a.rd} \ @@ -1437,7 +1437,7 @@ if { [istarget *-*-linux*] ] \ [list \ "Build pr22393-2 (PIE)" \ - "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \ + "-pie -Wl,-z,separate-code,--no-rosegment,--no-as-needed tmpdir/pr22393-2a-now.so" \ "-fPIE" \ {pr22393-2b.c} \ {{readelf -lW pr22393-2a.rd} \ @@ -1446,7 +1446,7 @@ if { [istarget *-*-linux*] ] \ [list \ "Build pr22393-2 (static)" \ - "-static -Wl,-z,separate-code" \ + "-static -Wl,-z,separate-code,--no-rosegment" \ "" \ {pr22393-2a.c pr22393-2b.c} \ {{readelf -lW pr22393-2a.rd} \ @@ -1687,7 +1687,7 @@ proc mix_pic_and_non_pic {xfails cflags ldflags exe} { } set exec_output [run_host_cmd "tmpdir/$exe" ""] - if {![string match "PASS" $exec_output]} { + if {![string match "PASS\n" $exec_output]} { fail "Run $exe fun undefined" } else { pass "Run $exe fun undefined" diff --git a/ld/testsuite/ld-i386/code16.d b/ld/testsuite/ld-i386/code16.d index c44fb03..cca8e8f 100644 --- a/ld/testsuite/ld-i386/code16.d +++ b/ld/testsuite/ld-i386/code16.d @@ -1,6 +1,6 @@ #name: i386 R_386_PC16 reloc in 16-bit mode #as: --32 -mx86-used-note=no --generate-missing-build-notes=no -#source: ${srcdir}/../../../gas/testsuite/gas/i386/code16-2.s +#source: ../../../gas/testsuite/gas/i386/code16-2.s #ld: -T code16.t #objdump: -dw -Mi8086 diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index f96c514..9029322 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -314,6 +314,7 @@ run_dump_test "tlsie2" run_dump_test "tlsie3" run_dump_test "tlsie4" run_dump_test "tlsie5" +run_dump_test "tlsle1" run_dump_test "hidden1" run_dump_test "hidden2" run_dump_test "hidden3" @@ -513,6 +514,7 @@ run_dump_test "pr28870" run_dump_test "pr28894" run_dump_test "pr30787" run_dump_test "pr31047" +run_dump_test "pr32191" if { !([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"] @@ -544,6 +546,9 @@ run_dump_test "pr27998b" run_dump_test "pr31868a" run_dump_test "pr31868b" run_dump_test "pr31868c" +run_dump_test "tlsgdesc1" +run_dump_test "tlsgdesc2" +run_dump_test "tlsgdesc3" proc undefined_weak {cflags ldflags} { set testname "Undefined weak symbol" @@ -553,9 +558,9 @@ proc undefined_weak {cflags ldflags} { if { [string match "*-fPIE*" $cflags] && ![string match "*-z nodynamic-undefined-weak*" $ldflags] } { - set weak_symbol "Weak defined" + set weak_symbol "Weak defined\n" } else { - set weak_symbol "Weak undefined" + set weak_symbol "Weak undefined\n" } run_cc_link_tests [list \ @@ -1321,6 +1326,14 @@ if { [isnative] {{error_output "pr21997-1.err"}} \ "pr21997-1" \ ] \ + [list \ + "Build pr32067" \ + "-Wl,--oformat,binary -nostdlib -nostartfiles" \ + "" \ + { start.s ../ld-x86-64/pr32067.s } \ + {} \ + "pr32067" \ + ] \ ] # The musl C library does not support TEXTRELs. diff --git a/ld/testsuite/ld-i386/pr32191.d b/ld/testsuite/ld-i386/pr32191.d new file mode 100644 index 0000000..8d7838a --- /dev/null +++ b/ld/testsuite/ld-i386/pr32191.d @@ -0,0 +1,9 @@ +#source: ../ld-x86-64/pr32191.s +#as: --32 -mx86-used-note=yes +#ld: -shared -m elf_i386 -z separate-code --build-id --rosegment +#readelf: -lW + +#... + +[0-9]+ +\.note\.gnu\.build-id \.text + +[0-9]+ +\..* \.note\.gnu\.property .* +#pass diff --git a/ld/testsuite/ld-i386/start.s b/ld/testsuite/ld-i386/start.s index 80301c6..4262a33 100644 --- a/ld/testsuite/ld-i386/start.s +++ b/ld/testsuite/ld-i386/start.s @@ -1,3 +1,4 @@ .globl _start _start: jmp foo + .section .note.GNU-stack diff --git a/ld/testsuite/ld-i386/tlsgdesc1.d b/ld/testsuite/ld-i386/tlsgdesc1.d new file mode 100644 index 0000000..0c853ab --- /dev/null +++ b/ld/testsuite/ld-i386/tlsgdesc1.d @@ -0,0 +1,4 @@ +#name: TLS GDesc->LE transition check (LEA) +#as: --32 -mtls-check=no +#ld: -melf_i386 +#error: .*: relocation R_386_TLS_GOTDESC against `foo' must be used in LEA only diff --git a/ld/testsuite/ld-i386/tlsgdesc1.s b/ld/testsuite/ld-i386/tlsgdesc1.s new file mode 100644 index 0000000..c30f752 --- /dev/null +++ b/ld/testsuite/ld-i386/tlsgdesc1.s @@ -0,0 +1,11 @@ + .text + .globl _start +_start: + movl foo@tlsdesc(%ebx), %eax + call *foo@tlscall(%eax) + .section .tdata,"awT",@progbits + .align 4 + .type foo, @object + .size foo, 4 +foo: + .long 100 diff --git a/ld/testsuite/ld-i386/tlsgdesc2.d b/ld/testsuite/ld-i386/tlsgdesc2.d new file mode 100644 index 0000000..99e1b18 --- /dev/null +++ b/ld/testsuite/ld-i386/tlsgdesc2.d @@ -0,0 +1,4 @@ +#name: TLS GDesc->LE transition check (indirect CALL) +#as: --32 -mtls-check=no +#ld: -melf_i386 +#error: .*: relocation R_386_TLS_DESC_CALL against `foo' must be used in indirect CALL with EAX register only diff --git a/ld/testsuite/ld-i386/tlsgdesc2.s b/ld/testsuite/ld-i386/tlsgdesc2.s new file mode 100644 index 0000000..5d3d0b8 --- /dev/null +++ b/ld/testsuite/ld-i386/tlsgdesc2.s @@ -0,0 +1,11 @@ + .text + .globl _start +_start: + leal foo@tlsdesc(%ebx), %ecx + call *foo@tlscall(%ecx) + .section .tdata,"awT",@progbits + .align 4 + .type foo, @object + .size foo, 4 +foo: + .long 100 diff --git a/ld/testsuite/ld-i386/tlsgdesc3.d b/ld/testsuite/ld-i386/tlsgdesc3.d new file mode 100644 index 0000000..4bb99c4 --- /dev/null +++ b/ld/testsuite/ld-i386/tlsgdesc3.d @@ -0,0 +1,5 @@ +#source: tlsgdesc2.s +#name: TLS GDesc call (indirect CALL) +#as: --32 -mtls-check=no +#ld: -shared -melf_i386 +#error: .*: relocation R_386_TLS_DESC_CALL against `foo' must be used in indirect CALL with EAX register only diff --git a/ld/testsuite/ld-i386/tlsie2.d b/ld/testsuite/ld-i386/tlsie2.d index ebb85fd..4e7dc6e 100644 --- a/ld/testsuite/ld-i386/tlsie2.d +++ b/ld/testsuite/ld-i386/tlsie2.d @@ -1,4 +1,4 @@ #name: TLS IE->LE transition check (R_386_TLS_GOTIE with %eax) -#as: --32 +#as: --32 -mtls-check=no #ld: -melf_i386 -#error: .*TLS transition from R_386_TLS_GOTIE to R_386_TLS_LE_32 against `foo'.*failed.* +#error: .*: relocation R_386_TLS_GOTIE against `foo' must be used in ADD, SUB or MOV only diff --git a/ld/testsuite/ld-i386/tlsie3.d b/ld/testsuite/ld-i386/tlsie3.d index d993f30..6bfc78e 100644 --- a/ld/testsuite/ld-i386/tlsie3.d +++ b/ld/testsuite/ld-i386/tlsie3.d @@ -1,4 +1,4 @@ #name: TLS IE->LE transition check (R_386_TLS_GOTIE) -#as: --32 +#as: --32 -mtls-check=no #ld: -melf_i386 -#error: .*TLS transition from R_386_TLS_GOTIE to R_386_TLS_LE_32 against `foo'.*failed.* +#error: .*: relocation R_386_TLS_GOTIE against `foo' must be used in ADD, SUB or MOV only diff --git a/ld/testsuite/ld-i386/tlsie4.d b/ld/testsuite/ld-i386/tlsie4.d index 3ca8fdd..98293f4 100644 --- a/ld/testsuite/ld-i386/tlsie4.d +++ b/ld/testsuite/ld-i386/tlsie4.d @@ -1,4 +1,4 @@ #name: TLS IE->LE transition check (R_386_TLS_IE with %eax) -#as: --32 +#as: --32 -mtls-check=no #ld: -melf_i386 -#error: .*TLS transition from R_386_TLS_IE to R_386_TLS_LE_32 against `foo'.*failed.* +#error: .*: relocation R_386_TLS_IE against `foo' must be used in ADD or MOV only diff --git a/ld/testsuite/ld-i386/tlsie5.d b/ld/testsuite/ld-i386/tlsie5.d index 3febeb1..4e9c9a8 100644 --- a/ld/testsuite/ld-i386/tlsie5.d +++ b/ld/testsuite/ld-i386/tlsie5.d @@ -1,4 +1,4 @@ #name: TLS IE->LE transition check (R_386_TLS_IE) -#as: --32 +#as: --32 -mtls-check=no #ld: -melf_i386 -#error: .*TLS transition from R_386_TLS_IE to R_386_TLS_LE_32 against `foo'.*failed.* +#error: .*: relocation R_386_TLS_IE against `foo' must be used in ADD or MOV only diff --git a/ld/testsuite/ld-i386/tlsle1.d b/ld/testsuite/ld-i386/tlsle1.d new file mode 100644 index 0000000..d1b65f2 --- /dev/null +++ b/ld/testsuite/ld-i386/tlsle1.d @@ -0,0 +1,15 @@ +#name: TLS LE with kmovd +#as: --32 +#ld: -melf_i386 +#objdump: -dw + +.*: +file format .* + +Disassembly of section \.text: + +.* <_start>: +.*: 65 c4 e1 f9 90 05 04 00 00 00 kmovd %gs:0x4,%k0 +.*: c4 e1 f9 90 80 04 00 00 00 kmovd 0x4\(%eax\),%k0 +.*: 65 c4 e1 f9 90 05 fc ff ff ff kmovd %gs:0xfffffffc,%k0 +.*: c4 e1 f9 90 80 fc ff ff ff kmovd -0x4\(%eax\),%k0 +#pass diff --git a/ld/testsuite/ld-i386/tlsle1.s b/ld/testsuite/ld-i386/tlsle1.s new file mode 100644 index 0000000..283b903 --- /dev/null +++ b/ld/testsuite/ld-i386/tlsle1.s @@ -0,0 +1,14 @@ + .text + .globl _start +_start: + kmovd %gs:foo@tpoff,%k0 + kmovd foo@tpoff(%eax),%k0 + kmovd %gs:foo@ntpoff,%k0 + kmovd foo@ntpoff(%eax),%k0 + .globl foo + .section .tdata,"awT",@progbits + .align 4 + .type foo, @object + .size foo, 4 +foo: + .long 100 diff --git a/ld/testsuite/ld-loongarch-elf/abs-global.out b/ld/testsuite/ld-loongarch-elf/abs-global.out new file mode 100644 index 0000000..3656652 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/abs-global.out @@ -0,0 +1 @@ +abba diff --git a/ld/testsuite/ld-loongarch-elf/abs-global.s b/ld/testsuite/ld-loongarch-elf/abs-global.s new file mode 100644 index 0000000..93a5da6 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/abs-global.s @@ -0,0 +1,5 @@ +.text +.globl get_sym +get_sym: + la.global $a0, sym + ret diff --git a/ld/testsuite/ld-loongarch-elf/abssym.s b/ld/testsuite/ld-loongarch-elf/abssym.s new file mode 100644 index 0000000..3eacc76 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/abssym.s @@ -0,0 +1,3 @@ +.section .data,"aw" +.quad _size8 +.word _size4 diff --git a/ld/testsuite/ld-loongarch-elf/abssym_pie.d b/ld/testsuite/ld-loongarch-elf/abssym_pie.d new file mode 100644 index 0000000..dfc3e35 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/abssym_pie.d @@ -0,0 +1,6 @@ +#source: abssym.s +#ld: -pie -e 0 --defsym _size8=0 --defsym _size4=0 +#readelf: -r +#... +There are no relocations in this file. +#... diff --git a/ld/testsuite/ld-loongarch-elf/abssym_shared.d b/ld/testsuite/ld-loongarch-elf/abssym_shared.d new file mode 100644 index 0000000..2db7e89 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/abssym_shared.d @@ -0,0 +1,6 @@ +#source: abssym.s +#ld: -shared --defsym _size8=0 --defsym _size4=0 +#readelf: -r +#... +There are no relocations in this file. +#... diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d new file mode 100644 index 0000000..6ecefd1 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d @@ -0,0 +1,5 @@ +#name: PC-relative relocation making shared +#source: bad_pcala_hi20_global.s +#target: [check_shared_lib_support] +#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20 +#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -fPIC diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.s b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.s new file mode 100644 index 0000000..d8189e4 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.s @@ -0,0 +1,8 @@ + .hidden global_a + .text + .align 2 +main: + # Symbols defined .hidden are bound local and + # the linker should differenciate them. + la.pcrel $a0, global_a + la.pcrel $a0, global_b diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d new file mode 100644 index 0000000..cefc42c --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d @@ -0,0 +1,5 @@ +#name: PC-relative relocation making shared +#source: bad_pcala_hi20_weak.s +#target: [check_shared_lib_support] +#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20 +#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -fPIC diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.s b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.s new file mode 100644 index 0000000..73c6ec5 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.s @@ -0,0 +1,9 @@ + .hidden global_a + .weak global_b + .text + .align 2 +main: + # Symbols defined .hidden are bound local and + # the linker should differenciate them. + la.pcrel $a0, global_a + la.pcrel $a0, global_b diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d new file mode 100644 index 0000000..8e063df --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d @@ -0,0 +1,5 @@ +#name: PC-relative relocation making shared +#source: bad_pcrel20_s2_global.s +#target: [check_shared_lib_support] +#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20 +#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -fPIC diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.s b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.s new file mode 100644 index 0000000..39cedbd --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.s @@ -0,0 +1,8 @@ + .hidden global_a + .text + .align 2 +main: + # Symbols defined .hidden are bound local and + # the linker should differenciate them. + pcaddi $a0, %pcrel_20(global_a) + pcaddi $a0, %pcrel_20(global_b) diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d new file mode 100644 index 0000000..605df24 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d @@ -0,0 +1,5 @@ +#name: PC-relative relocation making shared +#source: bad_pcrel20_s2_weak.s +#target: [check_shared_lib_support] +#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20 +#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -fPIC diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.s b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.s new file mode 100644 index 0000000..82faa5b --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.s @@ -0,0 +1,9 @@ + .hidden global_a + .weak global_b + .text + .align 2 +main: + # Symbols defined .hidden are bound local and + # the linker should differenciate them. + pcaddi $a0, %pcrel_20(global_a) + pcaddi $a0, %pcrel_20(global_b) diff --git a/ld/testsuite/ld-loongarch-elf/binary.ld b/ld/testsuite/ld-loongarch-elf/binary.ld new file mode 100644 index 0000000..73cd4f2 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/binary.ld @@ -0,0 +1 @@ +OUTPUT_FORMAT(binary); diff --git a/ld/testsuite/ld-loongarch-elf/binary.s b/ld/testsuite/ld-loongarch-elf/binary.s new file mode 100644 index 0000000..b0aeb62 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/binary.s @@ -0,0 +1,4 @@ +.text + ret +.data + .4byte 0x12345678 diff --git a/ld/testsuite/ld-loongarch-elf/data-plt.s b/ld/testsuite/ld-loongarch-elf/data-plt.s index faff052..6c1a8ea 100644 --- a/ld/testsuite/ld-loongarch-elf/data-plt.s +++ b/ld/testsuite/ld-loongarch-elf/data-plt.s @@ -2,6 +2,7 @@ # R_LARCH_PCALA_HI20 only need to generate PLT entry for function symbols. .text .globl a + .hidden a .data .align 2 diff --git a/ld/testsuite/ld-loongarch-elf/get_abs_global_sym.c b/ld/testsuite/ld-loongarch-elf/get_abs_global_sym.c new file mode 100644 index 0000000..29781ad --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/get_abs_global_sym.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +extern int get_sym(); +int main() { + printf("%x\n", get_sym()); + return 0; +} diff --git a/ld/testsuite/ld-loongarch-elf/ifunc-reloc.d b/ld/testsuite/ld-loongarch-elf/ifunc-reloc.d new file mode 100644 index 0000000..968e756 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/ifunc-reloc.d @@ -0,0 +1,19 @@ +#ld: -shared +#readelf: -Wr + +#... +.*'\.rela\.dyn'.* +#... +.* R_LARCH_RELATIVE .* +.* R_LARCH_IRELATIVE .* +.* R_LARCH_IRELATIVE .* +.* R_LARCH_IRELATIVE .* +.* R_LARCH_IRELATIVE .* +#... +.*'\.rela\.plt'.* +#... +.* R_LARCH_JUMP_SLOT .* +.* R_LARCH_JUMP_SLOT .* +.* R_LARCH_JUMP_SLOT .* +.* R_LARCH_JUMP_SLOT .* +.* R_LARCH_JUMP_SLOT .* diff --git a/ld/testsuite/ld-loongarch-elf/ifunc-reloc.s b/ld/testsuite/ld-loongarch-elf/ifunc-reloc.s new file mode 100644 index 0000000..e59f2b2 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/ifunc-reloc.s @@ -0,0 +1,55 @@ +.globl foo +.globl foo_hidden1 +.globl foo_hidden2 +.globl foo_protected + +.type foo, %gnu_indirect_function +.type foo_hidden1, %gnu_indirect_function +.type foo_hidden2, %gnu_indirect_function +.type foo_protected, %gnu_indirect_function +.type foo_internal, %gnu_indirect_function + +.hidden foo_hidden1 +.hidden foo_hidden2 + +.protected foo_protected + +.globl ext_ifunc1 +.globl ext_ifunc2 +.type ext_ifunc1, %gnu_indirect_function +.type ext_ifunc2, %gnu_indirect_function + +.text +.align 2 +foo: + ret + +foo_hidden1: + ret + +foo_hidden2: + ret + +foo_protected: + ret + +foo_internal: + ret + +test: + la.got $a0, num + # The order is deliberately shuffled. + bl ext_ifunc1 + bl foo + bl foo_hidden1 + bl ext_func1 + bl foo_protected + bl foo_internal + bl foo_hidden2 + bl ext_func2 + bl ext_ifunc2 + +.data +.align 3 +num: + .quad 114514 diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp index 2d67c4f..4e0068d 100644 --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp @@ -118,6 +118,30 @@ if [istarget "loongarch64-*-*"] { "abi1_max_imm" \ ] \ ] + + run_ld_link_tests \ + [list \ + [list \ + "binary output format" \ + "-T binary.ld" "" \ + "" \ + {binary.s} \ + {} \ + "a.binary" \ + ] \ + ] + + + run_ld_link_exec_tests [list \ + [list \ + "get global abs symbol test" \ + "-Wl,-z norelro -Wl,--defsym sym=0xabba" \ + "" \ + { abs-global.s get_abs_global_sym.c} \ + "abs-global" \ + "abs-global.out" \ + ] \ + ] } if [istarget "loongarch64-*-*"] { @@ -132,10 +156,30 @@ if [istarget "loongarch64-*-*"] { run_dump_test "reloc_le_with_shared" run_dump_test "reloc_ler_with_shared" run_dump_test "reloc_abs_with_shared" + 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" + run_dump_test "abssym_shared" + run_dump_test "bad_pcala_hi20_global" + run_dump_test "bad_pcala_hi20_weak" + run_dump_test "bad_pcrel20_s2_global" + run_dump_test "bad_pcrel20_s2_weak" } 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-got-start" + run_dump_test "relr-text-pie" + run_dump_test "abssym_pie" } run_dump_test "max_imm_b16" @@ -156,5 +200,8 @@ if [istarget "loongarch64-*-*"] { run_dump_test "ie-le-relax" run_dump_test "tlsdesc_abs" run_dump_test "tlsdesc_extreme" + run_dump_test "provide_abs" + run_dump_test "provide_noabs" + } diff --git a/ld/testsuite/ld-loongarch-elf/pic.exp b/ld/testsuite/ld-loongarch-elf/pic.exp index bcea5a3..64c3160 100644 --- a/ld/testsuite/ld-loongarch-elf/pic.exp +++ b/ld/testsuite/ld-loongarch-elf/pic.exp @@ -93,17 +93,6 @@ set link_tests [list \ "nopic-global" \ ] \ [list \ - "$testname readelf -s/-r nopic-global-so" \ - "-L./tmpdir -lnopic-global -L/usr/lib -lc" "" \ - "" \ - {nopic-global.s} \ - [list \ - [list readelf -s nopic-global-so.sd] \ - [list readelf -r nopic-global-so.rd] \ - ] \ - "nopic-global-so" \ - ] \ - [list \ "$testname readelf -s/-x nopic-weak-global" \ "-T pic.ld" "" \ "" \ @@ -114,19 +103,35 @@ set link_tests [list \ ] \ "nopic-weak-global" \ ] \ +] + +# Since the c library path may be different in different +# Distributions, the test program can link to the c library +# using the gcc instead of ld to avoid system impact. +run_ld_link_tests $link_tests + + + +set link_tests_libc [list \ + [list \ + "$testname readelf -s/-r nopic-global-so" \ + "-L./tmpdir -lnopic-global -L/usr/lib -lc" "" \ + {nopic-global.s} \ + {{readelf {-s} nopic-global-so.sd} \ + {readelf {-r} nopic-global-so.rd}} \ + "nopic-global-so" \ + ] \ [list \ "$testname readelf -s/-x nopic-weak-global-so" \ "-L./tmpdir -lnopic-global -L/usr/lib -lc" "" \ - "" \ {nopic-weak-global.s} \ - [list \ - [list readelf -s nopic-weak-global-so.sd] \ - [list readelf -r nopic-weak-global-so.rd] \ - ] \ + {{readelf {-s} nopic-weak-global-so.sd} \ + {readelf {-r} nopic-weak-global-so.rd}} \ "nopic-weak-global-so" \ ] \ ] + # 0:name # 1:ld/ar leading options, placed before object files # 2:ld/ar trailing options, placed after object files @@ -135,7 +140,9 @@ set link_tests [list \ # 5:list of actions, options and expected outputs. # 6:name of output file # 7:compiler flags (optional) -run_ld_link_tests $link_tests +run_cc_link_tests $link_tests_libc + + set testname "nopic link exec test" diff --git a/ld/testsuite/ld-loongarch-elf/protected-func.d b/ld/testsuite/ld-loongarch-elf/protected-func.d new file mode 100644 index 0000000..501c7cb --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/protected-func.d @@ -0,0 +1,6 @@ +#ld: -shared +#readelf: -Wr + +#... +.* R_LARCH_RELATIVE .* +.* R_LARCH_RELATIVE .* diff --git a/ld/testsuite/ld-loongarch-elf/protected-func.s b/ld/testsuite/ld-loongarch-elf/protected-func.s new file mode 100644 index 0000000..8f28f92 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/protected-func.s @@ -0,0 +1,17 @@ +# protected function should be non-preemptible and relocated with +# R_LARCH_RELATIVE in shared library, for both GOT and pointer data + +.globl x +.protected x +.type x, @function +x: + ret + +.globl _start +_start: + la.got $a0, x + ret + +.data +p: + .quad x diff --git a/ld/testsuite/ld-loongarch-elf/provide_abs.d b/ld/testsuite/ld-loongarch-elf/provide_abs.d new file mode 100644 index 0000000..1514fb1 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/provide_abs.d @@ -0,0 +1,12 @@ +#source: provide_sym.s +#as: +#ld: -T provide_abs.ld +#objdump: -d + +.*: +file format .* + +#... + 0: 58001085 beq \$a0, \$a1, 16 # 10 <fun1> + 4: 40000c80 beqz \$a0, 12 # 10 <fun1> + 8: 54000800 bl 8 # 10 <fun1> +#pass diff --git a/ld/testsuite/ld-loongarch-elf/provide_abs.ld b/ld/testsuite/ld-loongarch-elf/provide_abs.ld new file mode 100644 index 0000000..473476c --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/provide_abs.ld @@ -0,0 +1 @@ +PROVIDE(fun1 = 0x10); diff --git a/ld/testsuite/ld-loongarch-elf/provide_noabs.d b/ld/testsuite/ld-loongarch-elf/provide_noabs.d new file mode 100644 index 0000000..7d6bc4d --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/provide_noabs.d @@ -0,0 +1,13 @@ +#source: provide_sym.s +#as: +#ld: -T provide_noabs.ld +#objdump: -d + +.*: +file format .* + + +#... + 0: 58001085 beq \$a0, \$a1, 16 # 10 <fun1> + 4: 40000c80 beqz \$a0, 12 # 10 <fun1> + 8: 54000800 bl 8 # 10 <fun1> +#pass diff --git a/ld/testsuite/ld-loongarch-elf/provide_noabs.ld b/ld/testsuite/ld-loongarch-elf/provide_noabs.ld new file mode 100644 index 0000000..0154c6f --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/provide_noabs.ld @@ -0,0 +1,7 @@ +SECTIONS +{ + .text : + { + PROVIDE(fun1 = 0x10); + } +} diff --git a/ld/testsuite/ld-loongarch-elf/provide_sym.s b/ld/testsuite/ld-loongarch-elf/provide_sym.s new file mode 100644 index 0000000..6610894 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/provide_sym.s @@ -0,0 +1,7 @@ + .text + .globl main + .type main, @function +main: + beq $a0,$a1,%b16(fun1) + beqz $a0,%b21(fun1) + bl %b26(fun1) diff --git a/ld/testsuite/ld-loongarch-elf/r_larch_32_elf64.d b/ld/testsuite/ld-loongarch-elf/r_larch_32_elf64.d new file mode 100644 index 0000000..3431329 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/r_larch_32_elf64.d @@ -0,0 +1,4 @@ +#name: R_LARCH_32 in ELFCLASS64 +#source: r_larch_32_elf64.s +#ld: -shared -melf64loongarch +#error: R_LARCH_32 .* cannot be used in ELFCLASS64 diff --git a/ld/testsuite/ld-loongarch-elf/r_larch_32_elf64.s b/ld/testsuite/ld-loongarch-elf/r_larch_32_elf64.s new file mode 100644 index 0000000..6649f2b --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/r_larch_32_elf64.s @@ -0,0 +1,3 @@ +.data +x: + .4byte x diff --git a/ld/testsuite/ld-loongarch-elf/relax-call36-exe.s b/ld/testsuite/ld-loongarch-elf/relax-call36-exe.s new file mode 100644 index 0000000..26cff4d --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-call36-exe.s @@ -0,0 +1,32 @@ +ldd: # local define default +call36 ldd # ldd + +ldh: # local define hidden +.hidden ldh +call36 ldh # ldh + +gdd: +.global gdd # global define default +call36 gdd # gdd@plt + +gdh: +.global gdh # global define hidden +.hidden gdh +call36 gdh # gdh + +wdd: +.weak wdd # weak define default +call36 wdd # wdd@plt + +.weak wud # weak undefine default +call36 wud # wud@plt + +wdh: +.weak wdh # weak define hidden +.hidden wdh +call36 wdh # wdh + +.weak wuh # weak undefine hidden +.hidden wuh +call36 wuh # wuh + diff --git a/ld/testsuite/ld-loongarch-elf/relax-call36-so.s b/ld/testsuite/ld-loongarch-elf/relax-call36-so.s new file mode 100644 index 0000000..050273b --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-call36-so.s @@ -0,0 +1,35 @@ +ldd: # local define default +call36 ldd # ldd + +ldh: # local define hidden +.hidden ldh +call36 ldh # ldh + +gdd: +.global gdd # global define default +call36 gdd # gdd@plt + +.global gud # global undefine default +call36 gud # gud@plt + +gdh: +.global gdh # global define hidden +.hidden gdh +call36 gdh # gdh + +wdd: +.weak wdd # weak define default +call36 wdd # wdd@plt + +.weak wud # weak undefine default +call36 wud # wud@plt + +wdh: +.weak wdh # weak define hidden +.hidden wdh +call36 wdh # wdh + +.weak wuh # weak undefine hidden +.hidden wuh +call36 wuh # wuh + diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp index 4771f1e..aef7448 100644 --- a/ld/testsuite/ld-loongarch-elf/relax.exp +++ b/ld/testsuite/ld-loongarch-elf/relax.exp @@ -52,6 +52,111 @@ if [istarget loongarch64-*-*] { run_partial_linking_align_test run_ld_link_tests \ + [list \ + [list \ + "loongarch relax call36 .so build" \ + "-shared" "" \ + "" \ + {relax-call36-so.s} \ + {} \ + "relax-call36.so" \ + ] \ + ] + + if [file exist "tmpdir/relax-call36.so"] { + set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36.so"] + if { [ regexp "pcaddu18i" $objdump_output] } { + fail "loongarch relax call36 so" + } { + pass "loongarch relax call36 so" + } + } + + run_ld_link_tests \ + [list \ + [list \ + "loongarch relax call36 dyn exe build" \ + "-pie -e 0" "" \ + "" \ + {relax-call36-exe.s} \ + {} \ + "relax-call36-d.exe" \ + ] \ + ] + + if [file exist "tmpdir/relax-call36-d.exe"] { + set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-d.exe"] + if { [ regexp "pcaddu18i" $objdump_output] } { + fail "loongarch relax call36 dyn exe" + } { + pass "loongarch relax call36 dyn exe" + } + } + + run_ld_link_tests \ + [list \ + [list \ + "loongarch relax call36 dyn-pie exe build" \ + "-pie -e 0" "" \ + "" \ + {relax-call36-exe.s} \ + {} \ + "relax-call36-dp.exe" \ + ] \ + ] + + if [file exist "tmpdir/relax-call36-dp.exe"] { + set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-dp.exe"] + if { [ regexp "pcaddu18i" $objdump_output] } { + fail "loongarch relax call36 dyn-pie exe" + } { + pass "loongarch relax call36 dyn-pie exe" + } + } + + run_ld_link_tests \ + [list \ + [list \ + "loongarch relax call36 static exe build" \ + "-static -e 0" "" \ + "" \ + {relax-call36-exe.s} \ + {} \ + "relax-call36-s.exe" \ + ] \ + ] + + if [file exist "tmpdir/relax-call36-s.exe"] { + set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-s.exe"] + if { [ regexp "pcaddu18i" $objdump_output] } { + fail "loongarch relax call36 static exe" + } { + pass "loongarch relax call36 static exe" + } + } + + run_ld_link_tests \ + [list \ + [list \ + "loongarch relax call36 static-pie exe build" \ + "-static -pie --no-dynamic-linker -e 0" "" \ + "" \ + {relax-call36-exe.s} \ + {} \ + "relax-call36-sp.exe" \ + ] \ + ] + + if [file exist "tmpdir/relax-call36-sp.exe"] { + set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-sp.exe"] + if { [ regexp "pcaddu18i" $objdump_output] } { + fail "loongarch relax call36 static-pie exe" + } { + pass "loongarch relax call36 static-pie exe" + } + } + + run_ld_link_tests \ [list \ [list \ "loongarch relax ttext" \ 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 0000000..da13c2c --- /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 0000000..3d08f6c --- /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 0000000..d534243 --- /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 0000000..ddd055a --- /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 0000000..20ef9ac --- /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 0000000..37e4c0d --- /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 0000000..03673e0 --- /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 0000000..4ea8ae5 --- /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 0000000..8bfd8ba --- /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 0000000..165f1ed --- /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 0000000..b52374a --- /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 0000000..e994f2b --- /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 0000000..169e0e5 --- /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-start.d b/ld/testsuite/ld-loongarch-elf/relr-got-start.d new file mode 100644 index 0000000..0b1a5b9 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-got-start.d @@ -0,0 +1,7 @@ +#source: relr-got-start.s +#ld: -pie -z pack-relative-relocs -T relr-relocs.ld +#readelf: -rW + +Relocation section '\.relr\.dyn' at offset 0x[a-z0-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-got-start.s b/ld/testsuite/ld-loongarch-elf/relr-got-start.s new file mode 100644 index 0000000..c89fb42 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-got-start.s @@ -0,0 +1,5 @@ +.globl _start +_start: + pcalau12i $r5,%got_pc_hi20(_start) + ld.d $r5,$r5,%got_pc_lo12(_start) + ret 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 0000000..162528b --- /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 0000000..ed83275 --- /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 0000000..5121313 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relr-text-pie.d @@ -0,0 +1,14 @@ +#source: relr-text.s +#ld: -pie -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 0000000..8e34500 --- /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 0000000..47465f2 --- /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 diff --git a/ld/testsuite/ld-pe/exclude-symbols-def-i386.d b/ld/testsuite/ld-pe/exclude-symbols-def-i386.d index 91426c5..512b9ab 100644 --- a/ld/testsuite/ld-pe/exclude-symbols-def-i386.d +++ b/ld/testsuite/ld-pe/exclude-symbols-def-i386.d @@ -4,7 +4,9 @@ #objdump: -p #... -.*\[[ ]*0\].*sym1 -.*\[[ ]*1\].*sym3 -.*\[[ ]*2\].*sym5 +.* Ordinal Hint Name +.*\+base\[ 1\] 0000 sym1 +.*\+base\[ 2\] 0001 sym3 +.*\+base\[ 3\] 0002 sym5 + #pass diff --git a/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d b/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d index e3f0698..d17de41 100644 --- a/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d +++ b/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d @@ -4,7 +4,9 @@ #objdump: -p #... -.*\[[ ]*0\].*sym1 -.*\[[ ]*1\].*sym3 -.*\[[ ]*2\].*sym5 +.* Ordinal Hint Name +.*\+base\[ 1\] 0000 sym1 +.*\+base\[ 2\] 0001 sym3 +.*\+base\[ 3\] 0002 sym5 + #pass diff --git a/ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d b/ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d index fd79a7c..89ca6e6 100644 --- a/ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d +++ b/ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d @@ -4,7 +4,9 @@ #objdump: -p #... -.*\[[ ]*0\].*sym1 -.*\[[ ]*1\].*sym3 -.*\[[ ]*2\].*sym5 +.* Ordinal Hint Name +.*\+base\[ 1\] 0000 sym1 +.*\+base\[ 2\] 0001 sym3 +.*\+base\[ 3\] 0002 sym5 + #pass diff --git a/ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d b/ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d index 780482e..5bbda0f 100644 --- a/ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d +++ b/ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d @@ -4,7 +4,9 @@ #objdump: -p #... -.*\[[ ]*0\].*sym1 -.*\[[ ]*1\].*sym3 -.*\[[ ]*2\].*sym5 +.* Ordinal Hint Name +.*\+base\[ 1\] 0000 sym1 +.*\+base\[ 2\] 0001 sym3 +.*\+base\[ 3\] 0002 sym5 + #pass diff --git a/ld/testsuite/ld-pe/pdb-inlineelines1-c13-info2.d b/ld/testsuite/ld-pe/pdb-inlineelines1-c13-info2.d new file mode 100644 index 0000000..ac4e49b --- /dev/null +++ b/ld/testsuite/ld-pe/pdb-inlineelines1-c13-info2.d @@ -0,0 +1,10 @@ + +tmpdir/pdb-inlineelines1-c13-info2: file format binary + +Contents of section .data: + 0000 f4000000 30000000 02000000 10016745 ....0.........gE + 0010 2301efcd ab8998ba dcfe1023 45670000 #..........#Eg.. + 0020 08000000 100198ba dcfe1023 45676745 ...........#EggE + 0030 2301efcd ab890000 f6000000 1c000000 #............... + 0040 00000000 02100000 00000000 2a000000 ............*... + 0050 03100000 18000000 1c000000 ............ diff --git a/ld/testsuite/ld-pe/pdb-inlineelines1a.s b/ld/testsuite/ld-pe/pdb-inlineelines1a.s new file mode 100644 index 0000000..1ab2617 --- /dev/null +++ b/ld/testsuite/ld-pe/pdb-inlineelines1a.s @@ -0,0 +1,20 @@ +.equ CV_SIGNATURE_C13, 4 + +.equ LF_STRING_ID, 0x1605 + +.equ CV_INLINEE_SOURCE_LINE_SIGNATURE, 0 + +.section ".debug$T", "rn" + +.long CV_SIGNATURE_C13 + +/* Type 1000, string "hello" */ +.string1: +.short .types_end - .string1 - 2 +.short LF_STRING_ID +.long 0 /* sub-string */ +.asciz "hello" +.byte 0xf2 /* padding */ +.byte 0xf1 /* padding */ + +.types_end: diff --git a/ld/testsuite/ld-pe/pdb-inlineelines1b.s b/ld/testsuite/ld-pe/pdb-inlineelines1b.s new file mode 100644 index 0000000..d8d9170 --- /dev/null +++ b/ld/testsuite/ld-pe/pdb-inlineelines1b.s @@ -0,0 +1,160 @@ +.equ CV_SIGNATURE_C13, 4 + +.equ DEBUG_S_STRINGTABLE, 0xf3 +.equ DEBUG_S_FILECHKSMS, 0xf4 +.equ DEBUG_S_INLINEELINES, 0xf6 +.equ CHKSUM_TYPE_MD5, 1 + +.equ NUM_MD5_BYTES, 16 + +.equ T_VOID, 0x0003 +.equ T_UINT4, 0x0075 + +.equ LF_ARGLIST, 0x1201 +.equ LF_PROCEDURE, 0x1008 +.equ LF_FUNC_ID, 0x1601 +.equ LF_STRING_ID, 0x1605 + +.equ CV_INLINEE_SOURCE_LINE_SIGNATURE, 0 + +.section ".debug$T", "rn" + +.long CV_SIGNATURE_C13 + +/* Type 1000, string "world" */ +.string1: +.short .arglist1 - .string1 - 2 +.short LF_STRING_ID +.long 0 /* sub-string */ +.asciz "world" +.byte 0xf2 /* padding */ +.byte 0xf1 /* padding */ + +/* Type 1001, arglist (uint32_t) */ +.arglist1: +.short .proctype1 - .arglist1 - 2 +.short LF_ARGLIST +.long 1 /* no. entries */ +.long T_UINT4 + +/* Type 1002, procedure (return type T_VOID, arglist 1001) */ +.proctype1: +.short .funcid1 - .proctype1 - 2 +.short LF_PROCEDURE +.long T_VOID +.byte 0 /* calling convention */ +.byte 0 /* attributes */ +.short 1 /* no. parameters */ +.long 0x1001 + +/* Type 1003, func ID for proc1 */ +.funcid1: +.short .funcid2 - .funcid1 - 2 +.short LF_FUNC_ID +.long 0 /* parent scope */ +.long 0x1002 /* type */ +.asciz "proc1" +.byte 0xf2 /* padding */ +.byte 0xf1 /* padding */ + +/* Type 1004, func ID for proc2 */ +.funcid2: +.short .types_end - .funcid2 - 2 +.short LF_FUNC_ID +.long 0 /* parent scope */ +.long 0x1002 /* type */ +.asciz "proc2" +.byte 0xf2 /* padding */ +.byte 0xf1 /* padding */ + +.types_end: + +.section ".debug$S", "rn" +.long CV_SIGNATURE_C13 + +/* + *** STRINGTABLE + + 00000000 + 00000001 foo.c + 00000007 bar.c +*/ + +.long DEBUG_S_STRINGTABLE +.long .strings_end - .strings_start + +.strings_start: + +.asciz "" + +.src1: +.asciz "foo.c" + +.src2: +.asciz "bar.c" + +.strings_end: + +.balign 4 + +/* + *** FILECHKSUMS + + FileId St.Offset Cb Type ChksumBytes + 0 00000001 10 MD5 67452301EFCDAB8998BADCFE10234567 + 18 00000007 10 MD5 98BADCFE1023456767452301EFCDAB89 +*/ + +.long DEBUG_S_FILECHKSMS +.long .chksms_end - .chksms_start + +.chksms_start: + +.file1: +.long .src1 - .strings_start +.byte NUM_MD5_BYTES +.byte CHKSUM_TYPE_MD5 +.long 0x01234567 +.long 0x89abcdef +.long 0xfedcba98 +.long 0x67452310 +.short 0 /* padding */ + +.file2: +.long .src2 - .strings_start +.byte NUM_MD5_BYTES +.byte CHKSUM_TYPE_MD5 +.long 0xfedcba98 +.long 0x67452310 +.long 0x01234567 +.long 0x89abcdef +.short 0 /* padding */ + +.chksms_end: + +.balign 4 + +/* + *** INLINEE LINES + + InlineeId FileId StaringLine + 1003 0 42 + 1004 18 28 +*/ + +.long DEBUG_S_INLINEELINES +.long .lines_end - .lines_start + +.lines_start: + +.long CV_INLINEE_SOURCE_LINE_SIGNATURE + +.long 0x1003 +.long .file1 - .chksms_start +.long 42 + +.long 0x1004 +.long .file2 - .chksms_start +.long 28 + +.lines_end: diff --git a/ld/testsuite/ld-pe/pdb-strings.d b/ld/testsuite/ld-pe/pdb-strings.d index 8be853e..2c9cd2e 100644 --- a/ld/testsuite/ld-pe/pdb-strings.d +++ b/ld/testsuite/ld-pe/pdb-strings.d @@ -7,4 +7,4 @@ Contents of section .data: 0020 7578000c 00000001 0000000a 00000000 ux.............. 0030 00000000 00000000 00000012 00000000 ................ 0040 00000000 00000002 00000006 00000000 ................ - 0050 0000000e 00000006 000000 ...........
\ No newline at end of file + 0050 0000000e 00000006 000000 ........... diff --git a/ld/testsuite/ld-pe/pdb-syms1-globals.d b/ld/testsuite/ld-pe/pdb-syms1-globals.d index 356c5de..59f067b 100644 --- a/ld/testsuite/ld-pe/pdb-syms1-globals.d +++ b/ld/testsuite/ld-pe/pdb-syms1-globals.d @@ -2,20 +2,20 @@ *: file format binary Contents of section .data: - 0000 ffffffff 1a092ff1 d0000000 64020000 ....../.....d... - 0010 fd000000 01000000 35010000 01000000 ........5....... - 0020 15000000 01000000 19010000 01000000 ................ - 0030 c1000000 01000000 b9010000 01000000 ................ - 0040 d5000000 01000000 61010000 01000000 ........a....... - 0050 e9000000 01000000 11020000 01000000 ................ - 0060 e9010000 01000000 d5010000 01000000 ................ - 0070 49010000 01000000 a5010000 01000000 I............... - 0080 99010000 01000000 85000000 01000000 ................ - 0090 01000000 01000000 99000000 01000000 ................ - 00a0 7d010000 01000000 ad000000 01000000 }............... - 00b0 5d000000 01000000 49000000 01000000 ].......I....... - 00c0 21000000 02000000 35000000 01000000 !.......5....... - 00d0 fd010000 01000000 71000000 01000000 ........q....... + 0000 ffffffff 1a092ff1 d0000000 60020000 ....../.....`... + 0010 15000000 01000000 b9010000 01000000 ................ + 0020 a5010000 01000000 fd000000 01000000 ................ + 0030 11020000 01000000 71000000 01000000 ........q....... + 0040 fd010000 01000000 5d000000 01000000 ........]....... + 0050 d5010000 01000000 e9010000 01000000 ................ + 0060 21000000 02000000 35000000 01000000 !.......5....... + 0070 49000000 01000000 7d010000 01000000 I.......}....... + 0080 99010000 01000000 19010000 01000000 ................ + 0090 35010000 01000000 d5000000 01000000 5............... + 00a0 c1000000 01000000 e9000000 01000000 ................ + 00b0 85000000 01000000 ad000000 01000000 ................ + 00c0 49010000 01000000 01000000 01000000 I............... + 00d0 99000000 01000000 61010000 01000000 ........a....... 00e0 00000000 00000000 00000000 00000000 ................ 00f0 00000000 00000000 00000000 00000000 ................ 0100 00000000 00000000 00000000 00000000 ................ @@ -23,35 +23,34 @@ Contents of section .data: 0120 00000000 00000000 00000000 00000000 ................ 0130 00000000 00000000 00000000 00000000 ................ 0140 00000000 00000000 00000000 00000000 ................ - 0150 00000002 00000000 00000000 00000000 ................ + 0150 00000000 00000000 00000000 00000000 ................ 0160 00000000 00000000 00000000 00000000 ................ - 0170 00000000 00020000 00000000 00000000 ................ - 0180 00000000 00000000 00000000 00000000 ................ - 0190 00000000 00000001 00000000 00000000 ................ - 01a0 00000000 00000000 00000000 00000000 ................ + 0170 00000000 00000000 00000000 00000000 ................ + 0180 00000001 00100040 00000000 00000000 .......@........ + 0190 00000000 00000000 00000000 00000000 ................ + 01a0 00000004 00000000 00000000 00000000 ................ 01b0 00000000 00000000 00000000 00000000 ................ 01c0 00000000 00000000 00000000 00000000 ................ 01d0 00000000 00000000 00000000 00000000 ................ - 01e0 08001000 00000000 00000000 00000040 ...............@ - 01f0 04002000 00000000 00000000 00000000 .. ............. - 0200 00000000 00000001 00000000 00000000 ................ + 01e0 00000000 0000b499 00000000 00000000 ................ + 01f0 00000000 00000000 00000000 00000000 ................ + 0200 00000000 00000000 00000000 00000000 ................ 0210 00000000 00000000 00000000 00000000 ................ 0220 00000000 00000000 00000000 00000000 ................ - 0230 00000000 00000000 00080000 00004000 ..............@. - 0240 00000000 00000000 00100010 00000000 ................ - 0250 40000000 00000000 00000000 00000000 @............... - 0260 00000000 00000800 00000000 00000000 ................ - 0270 00000008 00000000 00000000 00000000 ................ - 0280 00000000 02004000 00000000 00000000 ......@......... - 0290 00000000 00008000 00000000 00000000 ................ - 02a0 00000000 00000000 10000000 00000000 ................ - 02b0 00000000 00000000 00000000 00800000 ................ - 02c0 00000000 00000000 00002000 00010000 .......... ..... - 02d0 00000000 00000000 00000000 00000040 ...............@ + 0230 00000001 00000000 00000000 00000000 ................ + 0240 01000000 00000000 00000000 00000000 ................ + 0250 00000000 00000000 00000000 00000000 ................ + 0260 00000000 00000000 00000000 00000000 ................ + 0270 00000001 00000000 00000000 10db0000 ................ + 0280 00000000 00000000 00000000 00000000 ................ + 0290 00000001 00000000 00000000 00000000 ................ + 02a0 00000000 00000000 00000000 00000000 ................ + 02b0 00000000 00000000 00000000 00000000 ................ + 02c0 00000000 00000000 00000000 00000000 ................ + 02d0 00000000 00000000 00000000 00000000 ................ 02e0 00000000 00000000 0c000000 18000000 ................ 02f0 24000000 30000000 3c000000 48000000 $...0...<...H... 0300 54000000 60000000 6c000000 78000000 T...`...l...x... - 0310 84000000 90000000 9c000000 a8000000 ................ - 0320 b4000000 c0000000 d8000000 e4000000 ................ - 0330 f0000000 fc000000 08010000 20010000 ............ ... - 0340 2c010000 ,...
\ No newline at end of file + 0310 90000000 9c000000 a8000000 b4000000 ................ + 0320 c0000000 cc000000 d8000000 e4000000 ................ + 0330 f0000000 fc000000 14010000 2c010000 ............,... diff --git a/ld/testsuite/ld-pe/pdb-syms1-records.d b/ld/testsuite/ld-pe/pdb-syms1-records.d index bbf6d7f..a0852ec 100644 --- a/ld/testsuite/ld-pe/pdb-syms1-records.d +++ b/ld/testsuite/ld-pe/pdb-syms1-records.d @@ -27,7 +27,7 @@ Contents of section .data: 0160 1a002711 00000000 98020000 0200666f ..'...........fo 0170 6f3a3a6d 6574686f 64330000 1a002711 o::method3....'. 0180 00000000 d0020000 0200666f 6f3a3a6d ..........foo::m - 0190 6574686f 64340000 0a000811 0a100000 ethod4.......... + 0190 6574686f 64340000 0a000811 09100000 ethod4.......... 01a0 666f6f00 12000711 75000000 2a00616e foo.....u...*.an 01b0 73776572 00f3f2f1 1a000711 23000000 swer........#... 01c0 0a80efcd ab896745 2301616e 73776572 ......gE#.answer @@ -58,4 +58,4 @@ Contents of section .data: 0350 1c000000 02006776 61723300 12000e11 ......gvar3..... 0360 00000000 08000000 03006776 61723400 ..........gvar4. 0370 12000e11 02000000 00000000 01006d61 ..............ma - 0380 696e0000 in..
\ No newline at end of file + 0380 696e0000 in.. diff --git a/ld/testsuite/ld-pe/pdb-syms1-symbols1.d b/ld/testsuite/ld-pe/pdb-syms1-symbols1.d index 4de22ac..4c56508 100644 --- a/ld/testsuite/ld-pe/pdb-syms1-symbols1.d +++ b/ld/testsuite/ld-pe/pdb-syms1-symbols1.d @@ -5,4 +5,4 @@ Contents of section .data: 0000 04000000 2e001011 00000000 34000000 ............4... 0010 00000000 01000000 00000000 00000000 ................ 0020 02100000 06000000 01000070 726f6332 ...........proc2 - 0030 00f3f2f1 02000600 00000000 ............
\ No newline at end of file + 0030 00f3f2f1 02000600 00000000 ............ diff --git a/ld/testsuite/ld-pe/pdb-syms1-symbols2.d b/ld/testsuite/ld-pe/pdb-syms1-symbols2.d index f134637..22c2f30 100644 --- a/ld/testsuite/ld-pe/pdb-syms1-symbols2.d +++ b/ld/testsuite/ld-pe/pdb-syms1-symbols2.d @@ -9,48 +9,48 @@ Contents of section .data: 0040 12000c11 00100000 00000000 03006c76 ..............lv 0050 61723200 2e001011 00000000 84000000 ar2............. 0060 00000000 01000000 00000000 00000000 ................ - 0070 05100000 0c000000 03000070 726f6331 ...........proc1 + 0070 02100000 0c000000 03000070 726f6331 ...........proc1 0080 00f3f2f1 02000600 2e001011 00000000 ................ 0090 ec000000 00000000 01000000 00000000 ................ - 00a0 00000000 05100000 06000000 01000070 ...............p + 00a0 00000000 02100000 06000000 01000070 ...............p 00b0 726f6332 00f3f2f1 0a000811 04100000 roc2............ 00c0 62617200 12000c11 00100000 10000000 bar............. 00d0 02006c76 61723300 12001211 00100000 ..lvar3......... 00e0 14000000 02006c76 61723400 02000600 ......lvar4..... 00f0 2e000f11 00000000 20010000 00000000 ........ ....... - 0100 01000000 00000000 00000000 05100000 ................ + 0100 01000000 00000000 00000000 02100000 ................ 0110 0d000000 03000070 726f6333 00f3f2f1 .......proc3.... 0120 02000600 2e000f11 00000000 54010000 ............T... 0130 00000000 01000000 00000000 00000000 ................ - 0140 05100000 07000000 01000070 726f6334 ...........proc4 + 0140 02100000 07000000 01000070 726f6334 ...........proc4 0150 00f3f2f1 02000600 2e001011 00000000 ................ 0160 88010000 00000000 01000000 00000000 ................ - 0170 00000000 05100000 0e000000 03000070 ...............p + 0170 00000000 02100000 0e000000 03000070 ...............p 0180 726f6335 00f3f2f1 02000600 2e001011 roc5............ 0190 00000000 bc010000 00000000 01000000 ................ - 01a0 00000000 00000000 05100000 08000000 ................ + 01a0 00000000 00000000 02100000 08000000 ................ 01b0 01000070 726f6336 00f3f2f1 02000600 ...proc6........ 01c0 32001011 00000000 f4010000 00000000 2............... - 01d0 01000000 00000000 00000000 05100000 ................ + 01d0 01000000 00000000 00000000 02100000 ................ 01e0 0f000000 03000066 6f6f3a3a 6d657468 .......foo::meth 01f0 6f6400f1 02000600 32001011 00000000 od......2....... 0200 2c020000 00000000 01000000 00000000 ,............... - 0210 00000000 05100000 09000000 01000066 ...............f + 0210 00000000 02100000 09000000 01000066 ...............f 0220 6f6f3a3a 6d657468 6f643200 02000600 oo::method2..... 0230 2e000f11 00000000 60020000 00000000 ........`....... - 0240 01000000 00000000 00000000 05100000 ................ + 0240 01000000 00000000 00000000 02100000 ................ 0250 10000000 03000070 726f6339 00f3f2f1 .......proc9.... 0260 02000600 2e001011 00000000 94020000 ................ 0270 00000000 01000000 00000000 00000000 ................ - 0280 05100000 0a000000 01000070 726f6331 ...........proc1 + 0280 02100000 0a000000 01000070 726f6331 ...........proc1 0290 3000f2f1 02000600 32000f11 00000000 0.......2....... 02a0 cc020000 00000000 01000000 00000000 ................ - 02b0 00000000 05100000 11000000 03000066 ...............f + 02b0 00000000 02100000 11000000 03000066 ...............f 02c0 6f6f3a3a 6d657468 6f643300 02000600 oo::method3..... 02d0 32000f11 00000000 04030000 00000000 2............... - 02e0 01000000 00000000 00000000 05100000 ................ + 02e0 01000000 00000000 00000000 02100000 ................ 02f0 0b000000 01000066 6f6f3a3a 6d657468 .......foo::meth 0300 6f643400 02000600 12001211 00100000 od4............. 0310 20000000 02006c76 61723500 12001211 .....lvar5..... 0320 00100000 12000000 03006c76 61723600 ..........lvar6. - 0330 00000000 ....
\ No newline at end of file + 0330 00000000 .... diff --git a/ld/testsuite/ld-pe/pdb-syms1a.s b/ld/testsuite/ld-pe/pdb-syms1a.s index d076bbc..c947676 100644 --- a/ld/testsuite/ld-pe/pdb-syms1a.s +++ b/ld/testsuite/ld-pe/pdb-syms1a.s @@ -1,6 +1,7 @@ .equ CV_SIGNATURE_C13, 4 .equ DEBUG_S_SYMBOLS, 0xf1 +.equ T_VOID, 0x0003 .equ T_UINT4, 0x0075 .equ LF_MODIFIER, 0x1001 diff --git a/ld/testsuite/ld-pe/pdb-syms2-symbols1.d b/ld/testsuite/ld-pe/pdb-syms2-symbols1.d index 34132d1..028545b 100644 --- a/ld/testsuite/ld-pe/pdb-syms2-symbols1.d +++ b/ld/testsuite/ld-pe/pdb-syms2-symbols1.d @@ -35,4 +35,4 @@ Contents of section .data: 01e0 02000600 1e000211 48000000 04020000 ........H....... 01f0 00000000 06000000 01000100 00746875 .............thu 0200 6e6b00f1 02000600 0e005e11 04000000 nk........^..... - 0210 01000100 02100000 02000600 00000000 ................
\ No newline at end of file + 0210 01000100 02100000 02000600 00000000 ................ diff --git a/ld/testsuite/ld-pe/pdb-types1-hashlist.d b/ld/testsuite/ld-pe/pdb-types1-hashlist.d index 7d314ed..f9d8a74 100644 --- a/ld/testsuite/ld-pe/pdb-types1-hashlist.d +++ b/ld/testsuite/ld-pe/pdb-types1-hashlist.d @@ -12,4 +12,4 @@ Contents of section .data: 0070 4d5e0200 8a940200 4b710300 6aa90300 * 0080 0a2c0300 67e10300 4a3d0300 fa460300 * 0090 db020200 ec4e0100 131e0300 fb120300 * - 00a0 aece0200 1db70100 99a30000 a8010100 *
\ No newline at end of file + 00a0 aece0200 1db70100 99a30000 a8010100 * diff --git a/ld/testsuite/ld-pe/pdb-types1-skiplist.d b/ld/testsuite/ld-pe/pdb-types1-skiplist.d index 52c10fa..f13b1d8 100644 --- a/ld/testsuite/ld-pe/pdb-types1-skiplist.d +++ b/ld/testsuite/ld-pe/pdb-types1-skiplist.d @@ -2,4 +2,4 @@ *: file format binary Contents of section .data: - 0000 00100000 00000000 *
\ No newline at end of file + 0000 00100000 00000000 * diff --git a/ld/testsuite/ld-pe/pdb-types1-typelist.d b/ld/testsuite/ld-pe/pdb-types1-typelist.d index 248dda5..e97c4f7 100644 --- a/ld/testsuite/ld-pe/pdb-types1-typelist.d +++ b/ld/testsuite/ld-pe/pdb-types1-typelist.d @@ -77,4 +77,9 @@ Contents of section .data: 0480 3a001d15 2a100000 00000000 00000000 :...*........... 0490 27000000 49556e6b 6e6f776e 00517565 '...IUnknown.Que 04a0 7279496e 74657266 61636500 41646452 ryInterface.AddR - 04b0 65660052 656c6561 736500f1 ef.Release..
\ No newline at end of file + 04b0 65660052 656c6561 736500f1 02000312 ef.Release...... + 04c0 22000515 00000000 2c100000 00000000 ".......,....... + 04d0 00000000 0100656d 7074795f 73747275 ......empty_stru + 04e0 637400f1 12000210 11100000 6c000100 ct..........l... + 04f0 0d100000 0500f2f1 12000210 75000000 ............u... + 0500 4c000100 0d100000 0100f2f1 L........... diff --git a/ld/testsuite/ld-pe/pdb-types1b.s b/ld/testsuite/ld-pe/pdb-types1b.s index e26b190..0cb301c 100644 --- a/ld/testsuite/ld-pe/pdb-types1b.s +++ b/ld/testsuite/ld-pe/pdb-types1b.s @@ -40,6 +40,12 @@ .equ CV_PTR_NEAR32, 0xa .equ CV_PTR_64, 0xc +.equ CV_PTR_MODE_PMEM, 0x40 +.equ CV_PTR_MODE_PMFUNC, 0x60 + +.equ CV_PMTYPE_D_Single, 0x01 +.equ CV_PMTYPE_F_Single, 0x05 + .section ".debug$T", "rn" .long CV_SIGNATURE_C13 @@ -593,7 +599,7 @@ /* Type 102a, virtual function table */ .vftable1: -.short .types_end - .vftable1 - 2 +.short .fieldlist12 - .vftable1 - 2 .short LF_VFTABLE .long 0x1029 /* type */ .long 0 /* base vftable */ @@ -607,4 +613,44 @@ .vftable1_names_end: .byte 0xf1 /* padding */ +/* Type 102b, empty LF_FIELDLIST */ +.fieldlist12: +.short .struct7 - .fieldlist12 - 2 +.short LF_FIELDLIST + +/* Type 102c, empty struct */ +.struct7: +.short .ptr5 - .struct7 - 2 +.short LF_STRUCTURE +.short 0 /* no. members */ +.short 0 /* property */ +.long 0x102b /* field list */ +.long 0 /* type derived from */ +.long 0 /* type of vshape table */ +.short 1 /* size */ +.asciz "empty_struct" /* name */ +.byte 0xf1 /* padding */ + +/* Type 102d, pointer to member function method2 in struct foo */ +.ptr5: +.short .ptr6 - .ptr5 - 2 +.short LF_POINTER +.long 0x1010 /* base type */ +.long (8 << 13) | CV_PTR_MODE_PMFUNC | CV_PTR_64 /* attributes */ +.long 0x100c /* containing class */ +.short CV_PMTYPE_F_Single /* member function, single inheritance */ +.byte 0xf2 /* padding */ +.byte 0xf1 /* padding */ + +/* Type 102e, pointer to member num in struct foo */ +.ptr6: +.short .types_end - .ptr6 - 2 +.short LF_POINTER +.long T_UINT4 /* base type */ +.long (8 << 13) | CV_PTR_MODE_PMEM | CV_PTR_64 /* attributes */ +.long 0x100c /* containing class */ +.short CV_PMTYPE_D_Single /* member data, single inheritance */ +.byte 0xf2 /* padding */ +.byte 0xf1 /* padding */ + .types_end: diff --git a/ld/testsuite/ld-pe/pdb-types2-hashlist.d b/ld/testsuite/ld-pe/pdb-types2-hashlist.d index 71d9045..d09fb3e 100644 --- a/ld/testsuite/ld-pe/pdb-types2-hashlist.d +++ b/ld/testsuite/ld-pe/pdb-types2-hashlist.d @@ -5,4 +5,4 @@ Contents of section .data: 0000 75cf0100 8d660300 f2a20300 aea00000 * 0010 ef990300 223d0000 d6b60000 24070100 * 0020 7f220100 f6d10200 16100200 010a0300 * - 0030 0b4f0300 12690300 a56d0300 *
\ No newline at end of file + 0030 0b4f0300 12690300 a56d0300 * diff --git a/ld/testsuite/ld-pe/pdb-types2-skiplist.d b/ld/testsuite/ld-pe/pdb-types2-skiplist.d index 52c10fa..f13b1d8 100644 --- a/ld/testsuite/ld-pe/pdb-types2-skiplist.d +++ b/ld/testsuite/ld-pe/pdb-types2-skiplist.d @@ -2,4 +2,4 @@ *: file format binary Contents of section .data: - 0000 00100000 00000000 *
\ No newline at end of file + 0000 00100000 00000000 * diff --git a/ld/testsuite/ld-pe/pdb-types2-typelist.d b/ld/testsuite/ld-pe/pdb-types2-typelist.d index d0fd26e..d8a36cc 100644 --- a/ld/testsuite/ld-pe/pdb-types2-typelist.d +++ b/ld/testsuite/ld-pe/pdb-types2-typelist.d @@ -17,4 +17,4 @@ Contents of section .data: 00c0 6500f2f1 12000116 00000000 01100000 e............... 00d0 66756e63 3100f2f1 12000116 0b100000 func1........... 00e0 01100000 66756e63 3200f2f1 12000216 ....func2....... - 00f0 02100000 04100000 6d657468 6f6400f1 ........method..
\ No newline at end of file + 00f0 02100000 04100000 6d657468 6f6400f1 ........method.. diff --git a/ld/testsuite/ld-pe/pdb-types3-hashlist.d b/ld/testsuite/ld-pe/pdb-types3-hashlist.d index 4a3775b..eda23d7 100644 --- a/ld/testsuite/ld-pe/pdb-types3-hashlist.d +++ b/ld/testsuite/ld-pe/pdb-types3-hashlist.d @@ -2,4 +2,4 @@ *: file format binary Contents of section .data: - 0000 d4d90000 0c1c0000 *
\ No newline at end of file + 0000 d4d90000 0c1c0000 * diff --git a/ld/testsuite/ld-pe/pdb-types3-skiplist.d b/ld/testsuite/ld-pe/pdb-types3-skiplist.d index 52c10fa..f13b1d8 100644 --- a/ld/testsuite/ld-pe/pdb-types3-skiplist.d +++ b/ld/testsuite/ld-pe/pdb-types3-skiplist.d @@ -2,4 +2,4 @@ *: file format binary Contents of section .data: - 0000 00100000 00000000 *
\ No newline at end of file + 0000 00100000 00000000 * diff --git a/ld/testsuite/ld-pe/pdb-types3-typelist.d b/ld/testsuite/ld-pe/pdb-types3-typelist.d index d6ffaad..48d7dbd 100644 --- a/ld/testsuite/ld-pe/pdb-types3-typelist.d +++ b/ld/testsuite/ld-pe/pdb-types3-typelist.d @@ -4,4 +4,4 @@ Contents of section .data: 0000 0e000516 00000000 666f6f2e 6800f2f1 ........foo.h... 0010 10000716 01100000 01000000 2a000000 ............*... - 0020 0100 ..
\ No newline at end of file + 0020 0100 .. diff --git a/ld/testsuite/ld-pe/pdb.exp b/ld/testsuite/ld-pe/pdb.exp index 1247651..803ec8a 100644 --- a/ld/testsuite/ld-pe/pdb.exp +++ b/ld/testsuite/ld-pe/pdb.exp @@ -611,26 +611,6 @@ proc test_mod_info { mod_info } { if { [expr $off % 4] != 0 } { set off [expr $off + 4 - ($off % 4)] } - - incr off 64 - - set obj3 [string range $mod_info $off [expr [string first \000 $mod_info $off] - 1]] - incr off [expr [string length $obj3] + 1] - - set ar3 [string range $mod_info $off [expr [string first \000 $mod_info $off] - 1]] - incr off [expr [string length $ar3] + 1] - - if [string equal $obj3 "* Linker *"] { - pass "Correct name for dummy object file" - } else { - fail "Incorrect name for dummy object file" - } - - if [string equal $ar3 ""] { - pass "Correct archive name for dummy object file" - } else { - fail "Incorrect archive name for dummy object file" - } } proc test_section_contrib { section_contrib } { @@ -677,7 +657,7 @@ proc test2 { } { return } - if ![ld_link $ld "tmpdir/pdb2.exe" "--pdb=tmpdir/pdb2.pdb --gc-sections -e foo tmpdir/pdb2a.o tmpdir/pdb2b.a"] { + if ![ld_link $ld "tmpdir/pdb2.exe" "--pdb=tmpdir/pdb2.pdb --gc-sections --disable-reloc-section -e foo tmpdir/pdb2a.o tmpdir/pdb2b.a"] { unsupported "Create PE image with PDB file" return } @@ -1036,7 +1016,7 @@ proc test5 { } { binary scan $data i end_type # end_type is one greater than the last type in the stream - if { $end_type != 0x102c } { + if { $end_type != 0x1030 } { fail "Incorrect end type value in TPI stream." } else { pass "Correct end type value in TPI stream." @@ -1764,6 +1744,99 @@ proc test9 { } { } } +proc test10 { } { + global as + global ar + global ld + global objdump + global srcdir + global subdir + + if ![ld_assemble $as $srcdir/$subdir/pdb-inlineelines1a.s tmpdir/pdb-inlineelines1a.o] { + unsupported "Build pdb-inlineelines1a.o" + return + } + + if ![ld_assemble $as $srcdir/$subdir/pdb-inlineelines1b.s tmpdir/pdb-inlineelines1b.o] { + unsupported "Build pdb-inlineelines1a.o" + return + } + + if ![ld_link $ld "tmpdir/pdb-inlineelines1.exe" "--pdb=tmpdir/pdb-inlineelines1.pdb tmpdir/pdb-inlineelines1a.o tmpdir/pdb-inlineelines1b.o"] { + unsupported "Create PE image with PDB file" + return + } + + # read relevant bits from DBI stream + + set exec_output [run_host_cmd "$ar" "x --output tmpdir tmpdir/pdb-inlineelines1.pdb 0003"] + + if ![string match "" $exec_output] { + fail "Could not extract DBI stream" + return + } else { + pass "Extracted DBI stream" + } + + set fi [open tmpdir/0003] + fconfigure $fi -translation binary + + seek $fi 24 + + # read substream sizes + + set data [read $fi 4] + binary scan $data i mod_info_size + + seek $fi 36 current + + set mod_info [read $fi $mod_info_size] + + close $fi + + # check C13 info in second module + + # We're interested here that the inlinee function IDs get rewritten: + # 1003 -> 1002, 1004 -> 1003. The numbers are lower because linking splits + # the types into two separate streams, numbered individually. + + # This is what cvdump.exe -inll pdb-inlineelines1.pdb should look like: + + # *** INLINEE LINES + # + # InlineeId FileId StaringLine + # 1002 0 42 + # 1003 1 28 + + # For some reason it numbers file IDs in bytes for object files but as an + # index for PDBs, but they're stored on disk the same way. + + set fn1_end [string first \000 $mod_info 64] + set fn2_end [string first \000 $mod_info [expr $fn1_end + 1]] + + set off [expr $fn2_end + 1] + + if { [expr $off % 4] != 0 } { + set off [expr $off + 4 - ($off % 4)] + } + + set c13_info [extract_c13_info "tmpdir/pdb-inlineelines1.pdb" [string range $mod_info $off [expr $off + 63]]] + + set fi [open tmpdir/pdb-inlineelines1-c13-info2 w] + fconfigure $fi -translation binary + puts -nonewline $fi $c13_info + close $fi + + set exp [file_contents "$srcdir/$subdir/pdb-inlineelines1-c13-info2.d"] + set got [run_host_cmd "$objdump" "-s --target=binary tmpdir/pdb-inlineelines1-c13-info2"] + + if [string match $exp $got] { + pass "Correct C13 info for second module" + } else { + fail "Incorrect C13 info for second module" + } +} + test1 test2 test3 @@ -1773,3 +1846,4 @@ test6 test7 test8 test9 +test10 diff --git a/ld/testsuite/ld-pe/pdb1-publics.d b/ld/testsuite/ld-pe/pdb1-publics.d index f7df2d9..0882f1b 100644 --- a/ld/testsuite/ld-pe/pdb1-publics.d +++ b/ld/testsuite/ld-pe/pdb1-publics.d @@ -38,4 +38,4 @@ Contents of section .data: 0210 00000000 00000000 00000000 00000000 ................ 0220 00000000 00000000 00000000 00000000 ................ 0230 00000000 00000000 00000000 00000000 ................ - 0240 00000000 0c000000 00000000 14000000 ................
\ No newline at end of file + 0240 00000000 0c000000 00000000 14000000 ................ diff --git a/ld/testsuite/ld-pe/pdb1-sym-record.d b/ld/testsuite/ld-pe/pdb1-sym-record.d index 2078a5e..88cc21e 100644 --- a/ld/testsuite/ld-pe/pdb1-sym-record.d +++ b/ld/testsuite/ld-pe/pdb1-sym-record.d @@ -4,4 +4,4 @@ Contents of section .data: 0000 12000e11 02000000 08000000 0100666f ..............fo 0010 6f000000 12000e11 00000000 04000000 o............... - 0020 02006261 72000000 ..bar...
\ No newline at end of file + 0020 02006261 72000000 ..bar... diff --git a/ld/testsuite/ld-pe/pdb2-section-contrib.d b/ld/testsuite/ld-pe/pdb2-section-contrib.d index 65ed76d..214eb11 100644 --- a/ld/testsuite/ld-pe/pdb2-section-contrib.d +++ b/ld/testsuite/ld-pe/pdb2-section-contrib.d @@ -7,6 +7,4 @@ Contents of section .data: 0020 01000000 10000000 10000000 20000060 ............ ..` 0030 01000000 00000000 00000000 02000000 ................ 0040 00000000 3d000000 40000040 00000000 ....=...@..@.... - 0050 00000000 00000000 04000000 00000000 ................ - 0060 0c000000 40000042 02000000 00000000 ....@..B........ - 0070 00000000 ....
\ No newline at end of file + 0050 00000000 00000000 ........ diff --git a/ld/testsuite/ld-pe/pdb3-c13-info1.d b/ld/testsuite/ld-pe/pdb3-c13-info1.d index 5a4f948..8c2f320 100644 --- a/ld/testsuite/ld-pe/pdb3-c13-info1.d +++ b/ld/testsuite/ld-pe/pdb3-c13-info1.d @@ -11,4 +11,4 @@ Contents of section .data: 0060 04000000 02000080 18000000 02000000 ................ 0070 1c000000 08000000 03000080 0c000000 ................ 0080 04000080 00000000 01000000 14000000 ................ - 0090 10000000 05000080 ........
\ No newline at end of file + 0090 10000000 05000080 ........ diff --git a/ld/testsuite/ld-pe/pdb3-c13-info2.d b/ld/testsuite/ld-pe/pdb3-c13-info2.d index 1c33ce1..f74af2f 100644 --- a/ld/testsuite/ld-pe/pdb3-c13-info2.d +++ b/ld/testsuite/ld-pe/pdb3-c13-info2.d @@ -5,4 +5,4 @@ Contents of section .data: 0000 f4000000 30000000 06000000 100198ba ....0........... 0010 dcfe1023 45676745 2301efcd ab890000 ...#EggE#....... 0020 0a000000 10013b2a 19087f6e 5d4c4c5d ......;*...n]LL] - 0030 6e7f0819 2a3b0000 n...*;..
\ No newline at end of file + 0030 6e7f0819 2a3b0000 n...*;.. diff --git a/ld/testsuite/ld-pe/pdb3-source-info.d b/ld/testsuite/ld-pe/pdb3-source-info.d index 5b7d58c..4239c1c 100644 --- a/ld/testsuite/ld-pe/pdb3-source-info.d +++ b/ld/testsuite/ld-pe/pdb3-source-info.d @@ -4,4 +4,4 @@ Contents of section .data: 0000 03000300 00000100 02000200 02000000 ................ 0010 00000000 04000000 04000000 08000000 ................ - 0020 666f6f00 62617200 62617a00 foo.bar.baz.
\ No newline at end of file + 0020 666f6f00 62617200 62617a00 foo.bar.baz. diff --git a/ld/testsuite/ld-pe/pe.exp b/ld/testsuite/ld-pe/pe.exp index 6a30366..725b58c 100644 --- a/ld/testsuite/ld-pe/pe.exp +++ b/ld/testsuite/ld-pe/pe.exp @@ -29,6 +29,7 @@ if {[istarget i*86-*-cygwin*] || [istarget i*86-*-pe] || [istarget i*86-*-mingw*] || [istarget x86_64-*-mingw*] + || [istarget x86_64-*-cygwin*] || [istarget arm-wince-pe] } { if {[istarget x86_64-*-mingw*] } { @@ -37,6 +38,25 @@ if {[istarget i*86-*-cygwin*] {{objdump -s secrel_64.d}} "secrel.x"} {".secidx" "--disable-reloc-section" "" "" {secidx1.s secidx2.s} {{objdump -s secidx_64.d}} "secidx.x"} + {".secrel32 w/ relocs" "--enable-reloc-section" "" "" {secrel1.s secrel2.s} + {{objdump -p secrel-reloc.d}} "secrel.x"} + {".secidx w/ relocs" "--enable-reloc-section" "" "" {secidx1.s secidx2.s} + {{objdump -p secidx-reloc.d}} "secidx.x"} + {"Empty export table" "" "" "" "exports.s" + {{objdump -p exports64.d}} "exports.dll"} + {"TLS directory entry" "" "" "" "tlssec.s" + {{objdump -p tlssec64.d}} "tlssec.dll"} + } + } elseif {[istarget x86_64-*-cygwin*]} { + set pe_tests { + {".secrel32" "--disable-auto-import --disable-reloc-section" "" "" {secrel1.s secrel2.s} + {{objdump -s secrel_64.d}} "secrel.x"} + {".secidx" "--disable-auto-import --disable-reloc-section" "" "" {secidx1.s secidx2.s} + {{objdump -s secidx_64.d}} "secidx.x"} + {".secrel32 w/ relocs" "--disable-auto-import --enable-reloc-section" "" "" {secrel1.s secrel2.s} + {{objdump -p secrel-reloc.d}} "secrel.x"} + {".secidx w/ relocs" "--disable-auto-import --enable-reloc-section" "" "" {secidx1.s secidx2.s} + {{objdump -p secidx-reloc.d}} "secidx.x"} {"Empty export table" "" "" "" "exports.s" {{objdump -p exports64.d}} "exports.dll"} {"TLS directory entry" "" "" "" "tlssec.s" @@ -48,6 +68,10 @@ if {[istarget i*86-*-cygwin*] {{objdump -s secrel.d}} "secrel.x"} {".secidx" "--disable-auto-import --disable-reloc-section" "" "" {secidx1.s secidx2.s} {{objdump -s secidx.d}} "secidx.x"} + {".secrel32 w/ relocs" "--disable-auto-import --enable-reloc-section" "" "" {secrel1.s secrel2.s} + {{objdump -p secrel-reloc.d}} "secrel-reloc.x"} + {".secidx w/ relocs" "--disable-auto-import --enable-reloc-section" "" "" {secidx1.s secidx2.s} + {{objdump -p secidx-reloc.d}} "secidx-reloc.x"} {"Empty export table" "" "" "" "exports.s" {{objdump -p exports.d}} "exports.dll"} {"TLS directory entry" "" "" "" "tlssec.s" @@ -57,6 +81,8 @@ if {[istarget i*86-*-cygwin*] set pe_tests { {".secrel32" "--disable-reloc-section" "" "" {secrel1.s secrel2.s} {{objdump -s secrel.d}} "secrel.x"} + {".secrel32 w/ relocs" "" "" "" {secrel1.s secrel2.s} + {{objdump -p secrel-reloc.d}} "secrel-reloc.x"} {"Empty export table" "" "" "" "exports.s" {{objdump -p exports.d}} "exports.dll"} {"TLS directory entry" "" "" "" "tlssec.s" @@ -68,6 +94,10 @@ if {[istarget i*86-*-cygwin*] {{objdump -s secrel.d}} "secrel.x"} {".secidx" "--disable-reloc-section" "" "" {secidx1.s secidx2.s} {{objdump -s secidx.d}} "secidx.x"} + {".secrel32 w/ relocs" " --enable-reloc-section" "" "" {secrel1.s secrel2.s} + {{objdump -p secrel-reloc.d}} "secrel-reloc.x"} + {".secidx w/ relocs" " --enable-reloc-section" "" "" {secidx1.s secidx2.s} + {{objdump -p secidx-reloc.d}} "secidx-reloc.x"} {"Empty export table" "" "" "" "exports.s" {{objdump -p exports.d}} "exports.dll"} {"TLS directory entry" "" "" "" "tlssec.s" @@ -144,3 +174,18 @@ run_dump_test "exclude-symbols-embedded-i386" run_dump_test "exclude-symbols-embedded-x86_64" run_dump_test "exclude-symbols-def-i386" run_dump_test "exclude-symbols-def-x86_64" + +if [check_shared_lib_support] { + set old_ASFLAGS $ASFLAGS + if [is_underscore_target] { + append ASFLAGS " --defsym UNDERSCORE=1" + } + run_dump_test "symbols-ordinals-hints-exports-ld" + # no dlltool for these two + setup_xfail aarch64-*-* sh-*-* + run_dump_test "symbols-ordinals-hints-exports-dlltool" + run_dump_test "symbols-ordinals-hints-imports-ld" + setup_xfail aarch64-*-* sh-*-* + run_dump_test "symbols-ordinals-hints-imports-dlltool" + set ASFLAGS $old_ASFLAGS +} diff --git a/ld/testsuite/ld-pe/secidx-reloc.d b/ld/testsuite/ld-pe/secidx-reloc.d new file mode 100644 index 0000000..043182d --- /dev/null +++ b/ld/testsuite/ld-pe/secidx-reloc.d @@ -0,0 +1,5 @@ +#... +The Data Directory +#... +Entry 5 0+ 0+ Base Relocation Directory \[\.reloc\] +#... diff --git a/ld/testsuite/ld-pe/secrel-reloc.d b/ld/testsuite/ld-pe/secrel-reloc.d new file mode 100644 index 0000000..043182d --- /dev/null +++ b/ld/testsuite/ld-pe/secrel-reloc.d @@ -0,0 +1,5 @@ +#... +The Data Directory +#... +Entry 5 0+ 0+ Base Relocation Directory \[\.reloc\] +#... diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-call-imports.s b/ld/testsuite/ld-pe/symbols-ordinals-hints-call-imports.s new file mode 100644 index 0000000..57fd3ed --- /dev/null +++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-call-imports.s @@ -0,0 +1,17 @@ +.ifdef UNDERSCORE + .global _func +_func: + .dc.a __imp__sym1 + .dc.a __imp__sym2 + .dc.a __imp__sym3 + .dc.a __imp__sym4 + .dc.a __imp__sym5 +.else + .global func +func: + .dc.a __imp_sym1 + .dc.a __imp_sym2 + .dc.a __imp_sym3 + .dc.a __imp_sym4 + .dc.a __imp_sym5 +.endif diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-dlltool.d b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-dlltool.d new file mode 100644 index 0000000..fad59ea --- /dev/null +++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-dlltool.d @@ -0,0 +1,21 @@ +#source: symbols-ordinals-hints-exports.s +#dlltool: -d ${srcdir}/${subdir}/symbols-ordinals-hints.def -e tmpdir/exports-dlltool.o +#ld: -shared tmpdir/exports-dlltool.o +#objdump: -p + +# Rules for Ordinal/Name Pointer Table: +# - Table rows must be lexicographically sorted by symbol names +# - Hint numbers must be in sequence starting from zero +# - Ordinal numbers must match the @ordinal keyword from .def file +# - Symbols in .def file without @ordinal keyword have assigned the first free ordinal starting from 1 +# - Symbols in .def file with NONAME keyword must not be present in Name Pointer Table + +#... +.*\[Ordinal/Name Pointer\] Table -- Ordinal Base.* +.* Ordinal Hint Name +.*\+base\[ 2\] 0000 sym1 +.*\+base\[ 5\] 0001 sym2 +.*\+base\[ 3\] 0002 sym4 +.*\+base\[ 4\] 0003 sym5 + +#pass diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-ld.d b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-ld.d new file mode 100644 index 0000000..0e7dcac --- /dev/null +++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-ld.d @@ -0,0 +1,20 @@ +#source: symbols-ordinals-hints-exports.s +#ld: -shared ${srcdir}/${subdir}/symbols-ordinals-hints.def +#objdump: -p + +# Rules for Ordinal/Name Pointer Table: +# - Table rows must be lexicographically sorted by symbol names +# - Hint numbers must be in sequence starting from zero +# - Ordinal numbers must match the @ordinal keyword from .def file +# - Symbols in .def file without @ordinal keyword have assigned the first free ordinal starting from 1 +# - Symbols in .def file with NONAME keyword must not be present in Name Pointer Table + +#... +.*\[Ordinal/Name Pointer\] Table -- Ordinal Base.* +.* Ordinal Hint Name +.*\+base\[ 2\] 0000 sym1 +.*\+base\[ 5\] 0001 sym2 +.*\+base\[ 3\] 0002 sym4 +.*\+base\[ 4\] 0003 sym5 + +#pass diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-exports.s b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports.s new file mode 100644 index 0000000..26ee52b --- /dev/null +++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports.s @@ -0,0 +1,25 @@ +# define symbols in no specific order +.ifdef UNDERSCORE + .global _sym2 + .global _sym5 + .global _sym3 + .global _sym1 + .global _sym4 +_sym2: +_sym5: +_sym3: +_sym1: +_sym4: +.else + .global sym2 + .global sym5 + .global sym3 + .global sym1 + .global sym4 +sym2: +sym5: +sym3: +sym1: +sym4: +.endif + .nop diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-dlltool.d b/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-dlltool.d new file mode 100644 index 0000000..5f3702e --- /dev/null +++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-dlltool.d @@ -0,0 +1,27 @@ +#source: symbols-ordinals-hints-call-imports.s +#dlltool: -d ${srcdir}/${subdir}/symbols-ordinals-hints.def -l tmpdir/libimports-dlltool.a +#ld: -shared +#ld_after_inputfiles: tmpdir/libimports-dlltool.a +#objdump: -p + +# Rules for Import Tables: +# - Ordinal, Hint and Member-Name (what is present) match Ordinal/Name Pointer Table of +# the external DLL (from corresponding symbols-ordinals-hints-exports-*.d test) +# - Symbols in .def file with NONAME keyword have only Ordinal, must no have Hint and Member-Name +# - Symbols in .def file without NONAME keyword have Hint and Member-Name, must not have Ordinal + +#... +The Import Tables \(interpreted \.idata section contents\) + vma: Hint Time Forward DLL First + Table Stamp Chain Name Thunk +.* + +.*DLL Name:.* +.* Ordinal Hint Member-Name Bound-To +.* <none> 0000 sym1 +.* <none> 0001 sym2 +.* 1 <none> <none> +.* <none> 0002 sym4 +.* <none> 0003 sym5 + +#pass diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-ld.d b/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-ld.d new file mode 100644 index 0000000..7b7cdaa --- /dev/null +++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-ld.d @@ -0,0 +1,26 @@ +#source: symbols-ordinals-hints-exports.s +#ld: -shared ${srcdir}/${subdir}/symbols-ordinals-hints.def --out-implib tmpdir/libimports-ld.a +#ld_after_inputfiles: && $AS $ASFLAGS ${srcdir}/${subdir}/symbols-ordinals-hints-call-imports.s -o tmpdir/call-imports-ld.o && $LD -shared tmpdir/call-imports-ld.o tmpdir/libimports-ld.a -o tmpdir/dump +#objdump: -p + +# Rules for Import Tables: +# - Ordinal, Hint and Member-Name (what is present) match Ordinal/Name Pointer Table of +# the external DLL (from corresponding symbols-ordinals-hints-exports-*.d test) +# - Symbols in .def file with NONAME keyword have only Ordinal, must no have Hint and Member-Name +# - Symbols in .def file without NONAME keyword have Hint and Member-Name, must not have Ordinal + +#... +The Import Tables \(interpreted \.idata section contents\) + vma: Hint Time Forward DLL First + Table Stamp Chain Name Thunk +.* + +.*DLL Name:.* +.* Ordinal Hint Member-Name Bound-To +.* <none> 0000 sym1 +.* <none> 0001 sym2 +.* 1 <none> <none> +.* <none> 0002 sym4 +.* <none> 0003 sym5 + +#pass diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints.def b/ld/testsuite/ld-pe/symbols-ordinals-hints.def new file mode 100644 index 0000000..5b79a48 --- /dev/null +++ b/ld/testsuite/ld-pe/symbols-ordinals-hints.def @@ -0,0 +1,9 @@ +LIBRARY "symbols-ordinals-hints.dll" +EXPORTS +; define symbols in no specific order +; define ordinals also in no specific order +sym2 @5 +sym5 +sym3 @1 NONAME +sym1 @2 +sym4 diff --git a/ld/testsuite/ld-plugin/common-1.c b/ld/testsuite/ld-plugin/common-1.c new file mode 100644 index 0000000..b4f616a --- /dev/null +++ b/ld/testsuite/ld-plugin/common-1.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +int foo; + +int main() +{ + if (foo == 1) + printf ("PASS\n"); + + return 0; +} diff --git a/ld/testsuite/ld-plugin/common-2a.c b/ld/testsuite/ld-plugin/common-2a.c new file mode 100644 index 0000000..fccfca7 --- /dev/null +++ b/ld/testsuite/ld-plugin/common-2a.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +int foo; + +int main() +{ + if (foo == 0) + printf ("PASS\n"); + + return 0; +} diff --git a/ld/testsuite/ld-plugin/common-2b.c b/ld/testsuite/ld-plugin/common-2b.c new file mode 100644 index 0000000..c014c67 --- /dev/null +++ b/ld/testsuite/ld-plugin/common-2b.c @@ -0,0 +1,6 @@ +int foo; + +void +func (void) +{ +} diff --git a/ld/testsuite/ld-plugin/definition-1.c b/ld/testsuite/ld-plugin/definition-1.c new file mode 100644 index 0000000..a244740 --- /dev/null +++ b/ld/testsuite/ld-plugin/definition-1.c @@ -0,0 +1 @@ +int foo = 1; diff --git a/ld/testsuite/ld-plugin/libdep-a.c b/ld/testsuite/ld-plugin/libdep-a.c deleted file mode 100644 index 5a01ce8..0000000 --- a/ld/testsuite/ld-plugin/libdep-a.c +++ /dev/null @@ -1,7 +0,0 @@ -extern int g (void); - -int -f (void) -{ - return g(); -} diff --git a/ld/testsuite/ld-plugin/libdep-b.c b/ld/testsuite/ld-plugin/libdep-b.c deleted file mode 100644 index d2ca7e0..0000000 --- a/ld/testsuite/ld-plugin/libdep-b.c +++ /dev/null @@ -1,5 +0,0 @@ -int -g (void) -{ - return 4; -} diff --git a/ld/testsuite/ld-plugin/libdep-main.c b/ld/testsuite/ld-plugin/libdep-main.c deleted file mode 100644 index 7563a7d..0000000 --- a/ld/testsuite/ld-plugin/libdep-main.c +++ /dev/null @@ -1,7 +0,0 @@ -extern int f (void); - -int -main (void) -{ - return f(); -} diff --git a/ld/testsuite/ld-plugin/libdep.exp b/ld/testsuite/ld-plugin/libdep.exp deleted file mode 100644 index 6e56b6b..0000000 --- a/ld/testsuite/ld-plugin/libdep.exp +++ /dev/null @@ -1,124 +0,0 @@ -# Expect script for ld-plugin LIBDEP tests -# Copyright (C) 2024 Free Software Foundation, Inc. -# -# This file is part of the GNU Binutils. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, -# MA 02110-1301, USA. - -# These tests require the plugin API. -if { ![check_plugin_api_available] } { - return -} - -# Check to see if the C compiler works -# FIXME: This is being lazy, we could create assembler equivalents instead. -if { ![check_compiler_available] } { - return -} - -proc run_test { } { - global CC_FOR_TARGET - global srcdir - global subdir - global ar - global ld - global libdep - global base_dir - - set testname "libdep test" - - # Create temporary directories if they do not already exist. - file mkdir -p libdep-a libdep-b - - # Delete old versions of the files we are about to build, just in case. - file delete libdep-a/a.o libdep-a/liba.a libdep-b/b.o libdep-b/libc.a libdep-main.o - - # Build object files. - if {![ld_compile $CC_FOR_TARGET $srcdir/$subdir/libdep-a.c libdep-a/a.o]} { - fail "$testname: could not compile source file 1" - return - } - if {![ld_compile $CC_FOR_TARGET $srcdir/$subdir/libdep-b.c libdep-b/b.o]} { - fail "$testname: could not compile source file 2" - return - } - if {![ld_compile $CC_FOR_TARGET $srcdir/$subdir/libdep-main.c libdep-main.o]} { - fail "$testname: could not compile source file 3" - return - } - - # Create static archives from the objects. - - # For the first archive we add a libdep element that loads the second library. - if {![ar_simple_create $ar {--record-libdeps "-Llibdep-b -lc"} libdep-a/liba.a libdep-a/a.o]} { - fail "$testname: could not create archive 1" - return - } - - # For the second archive we choose a name - libc.a - that is likely to clash - # with a system library. This will help to check that the library loaded by - # following the libdep element in the first library is the one that we expect. - if {![ar_simple_create $ar {} libdep-b/libc.a libdep-b/b.o]} { - fail "$testname: could not create archive 2" - return - } - - # Find the libdep plugin. - # Use libtool to find the path to the plugin rather - # than worrying about run paths or anything like that. - catch "exec $base_dir/libtool --config" lt_config - verbose "Full lt config: $lt_config" 2 - # Look for "objdir=.libs" - regexp -line "^objdir=.*$" "$lt_config" lt_objdir - verbose "lt_objdir line is '$lt_objdir'" 2 - set lt_objdir [regsub "objdir=" "$lt_objdir" ""] - - if { [ file exists "$base_dir/$lt_objdir/libdep.so" ] } { - set libdep_plugin "$base_dir/$lt_objdir/libdep.so" - } else { - # FIXME: Check in the system bfd-plugin directory ? - fail "$testname - could not locate libdep plugin" - return - } - - verbose "Full plugin path: $libdep_plugin" 1 - - # Link the main object file with the liba.a library. - # Use the libdep plugin to read the __.LIBDEP element in the liba.a library - # and so bring in the libdep-b.o object file from the libc.a library. - # Failure to locate the libc.a library, or loading the wrong libc.a library - # will result in an unresolved reference error. - set exec_output [run_host_cmd "$ld" "-plugin $libdep_plugin -o libdep.exe libdep-main.o -L libdep-a -la -e 0"] - set exec_output [prune_warnings $exec_output] - - set expected_output "got deps for library libdep-a/liba.a: -Llibdep-b -lc" - - if ![string match $expected_output $exec_output] then { - fail "$testname: did not get expected output from the linker" - return - } - - regsub -all "$expected_output" $exec_output "\\1" exec_output - - if {![string match "" $exec_output]} { - fail "$testname: unexpected output from linker: $exec_output" - return - } - - pass "$testname" -} - -run_test diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index 7b4b349..6424ba4 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -231,6 +231,30 @@ set lto_link_tests [list \ "$plug_opt" "-flto $lto_no_fat -fcommon" \ {pr26389.c} \ [list [list "nm" "$plug_opt" "pr26389.d"]]] \ + [list "Build libdefinition-1.a" \ + "$plug_opt" \ + "-O2 -fcommon -flto $lto_no_fat" \ + {definition-1.c} \ + {} \ + "libdefinition-1.a" \ + ] \ + [list \ + "Build common-2a.o" \ + "" \ + "-O2 -fcommon -flto $lto_no_fat" \ + {common-2a.c} \ + {} \ + "" \ + "c" \ + ] \ + [list \ + "Build libcommon-2.a" \ + "$plug_opt" \ + "-O2 -fcommon -flto $lto_no_fat" \ + {common-2b.c} \ + {} \ + "libcommon-2.a" \ + ] \ ] if { [at_least_gcc_version 10 0] && [check_lto_shared_available] } { @@ -531,6 +555,38 @@ set lto_link_elf_tests [list \ "pr29086" \ ] \ [list \ + "PR ld/31956 (a)" \ + "-Wl,--wrap=parse_line" \ + "-O2 -flto" \ + {pr31956a.c pr31956b.c} \ + {} \ + "pr31956a" \ + ] \ + [list \ + "PR ld/31956 (b)" \ + "-Wl,--wrap=parse_line" \ + "-O2 -flto" \ + {pr31956b.c pr31956a.c} \ + {} \ + "pr31956b" \ + ] \ + [list \ + "PR ld/31956 (malloc)" \ + "-Wl,--wrap=malloc" \ + "-O2 -flto" \ + {pr31956c.c} \ + {} \ + "pr31956c" \ + ] \ + [list \ + "PR ld/31956 (unused)" \ + "-Wl,--wrap=parse_line" \ + "-O2 -flto" \ + {pr31956d.c} \ + {{"nm" {} "pr31956d.d"}} \ + "pr31956d" \ + ] \ + [list \ "Build pr30281.so" \ "-shared -Wl,--version-script,pr30281.t \ -O2 -fPIC -flto-partition=max -flto=2" \ @@ -731,6 +787,17 @@ set lto_run_tests [list \ {pr26262a.c} "pr26262b" "pass.out" \ "-flto -O2" "c" "" \ ""] \ + [list "Run common-1" \ + "-O2 -flto" \ + "" \ + {common-1.c} \ + "common-1" \ + "pass.out" \ + "-O2 -fcommon -flto $lto_no_fat" \ + "c" \ + "" \ + "tmpdir/libdefinition-1.a" \ + ] \ ] if { [at_least_gcc_version 4 7] } { @@ -830,6 +897,26 @@ run_cc_link_tests $lto_link_tests # by some elf tests besides shared libs tests. So, always compile them. run_cc_link_tests $lto_compile_elf_tests +# Xfail PR ld/32083 test for GCC without the fix: +# +# commit a98dd536b1017c2b814a3465206c6c01b2890998 +# Author: H.J. Lu <hjl.tools@gmail.com> +# Date: Wed Aug 21 07:25:25 2024 -0700 +# +# Update LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook +# +set exec_output [run_host_cmd "$CC_FOR_TARGET" \ + "-O2 -fcommon -flto -o tmpdir/common-2 \ + tmpdir/common-2a.o tmpdir/libcommon-2.a \ + tmpdir/libcommon-2.a"] +if [string match "" $exec_output] then { + pass "PR ld/32083" +} elseif { [ regexp "lto1: fatal error: multiple prevailing defs for 'func'" $exec_output ] } { + xfail "PR ld/32083" +} else { + fail "PR ld/32083" +} + # Restrict these to ELF targets that support shared libs and PIC. if { [is_elf_format] && [check_lto_shared_available] } { run_cc_link_tests $lto_link_elf_tests @@ -879,7 +966,7 @@ set exec_output [prune_warnings $exec_output] if [string match "" $exec_output] then { if { [isnative] } { set exec_output [run_host_cmd "tmpdir/pr28138" ""] - if [string match "PASS" $exec_output] then { + if [string match "PASS\n" $exec_output] then { pass "PR ld/28138 (build & run)" } else { fail "PR ld/28138 (built ok, run failed)" diff --git a/ld/testsuite/ld-plugin/pr31956a.c b/ld/testsuite/ld-plugin/pr31956a.c new file mode 100644 index 0000000..48df8c5 --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31956a.c @@ -0,0 +1,3 @@ +extern void parse_line(void); +void _cmocka_run_group_tests(void *) {} +void argv_parse_cmd(void) { parse_line(); } diff --git a/ld/testsuite/ld-plugin/pr31956b.c b/ld/testsuite/ld-plugin/pr31956b.c new file mode 100644 index 0000000..1b06931 --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31956b.c @@ -0,0 +1,23 @@ +struct CMUnitTest { + void *test_func; +}; + +extern void _cmocka_run_group_tests(void *); + +extern void argv_parse_cmd(void); +void __wrap_parse_line(void) {}; + +void foo (void) { + argv_parse_cmd(); +} + +struct CMUnitTest main_tests = { + foo +}; + +int +main (void) +{ + _cmocka_run_group_tests (&main_tests); + return 0; +} diff --git a/ld/testsuite/ld-plugin/pr31956c.c b/ld/testsuite/ld-plugin/pr31956c.c new file mode 100644 index 0000000..4a46b2b --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31956c.c @@ -0,0 +1,19 @@ +#include <stdlib.h> + +extern void *__real_malloc (size_t); + +void * +__wrap_malloc (size_t n) +{ + if (n == 0) + return NULL; + else + return __real_malloc (n); +}; + +int +main (void) +{ + void *ptr = malloc (30); + return ptr == NULL ? 1 : 0; +} diff --git a/ld/testsuite/ld-plugin/pr31956d.c b/ld/testsuite/ld-plugin/pr31956d.c new file mode 100644 index 0000000..cb7f2d5 --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31956d.c @@ -0,0 +1,7 @@ +void __wrap_parse_line(void) {}; + +int +main (void) +{ + return 0; +} diff --git a/ld/testsuite/ld-plugin/pr31956d.d b/ld/testsuite/ld-plugin/pr31956d.d new file mode 100644 index 0000000..b579cdc --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31956d.d @@ -0,0 +1,4 @@ +#failif +#... +[0-9a-f]+ T .*parse_line +#... diff --git a/ld/testsuite/ld-riscv-elf/relax-max-align-gp.d b/ld/testsuite/ld-riscv-elf/relax-max-align-gp.d index b62d388..5832835 100644 --- a/ld/testsuite/ld-riscv-elf/relax-max-align-gp.d +++ b/ld/testsuite/ld-riscv-elf/relax-max-align-gp.d @@ -7,7 +7,7 @@ Disassembly of section .text: -0+[0-9a-f]+ <_start>: +0+[0-9a-f]+00 <_start>: .*:[ ]+[0-9a-f]+[ ]+addi[ ]+.*<gdata> .*:[ ]+[0-9a-f]+[ ]+jal[ ]+.* .*:[ ]+[0-9a-f]+[ ]+j[ ]+.* @@ -41,6 +41,32 @@ Disassembly of section .text: .*:[ ]+[0-9a-f]+[ ]+nop .*:[ ]+[0-9a-f]+[ ]+nop -0+[0-9a-f]+ <func>: +0+[0-9a-f]+80 <func>: .*:[ ]+[0-9a-f]+[ ]+ret -[ ]+... +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop +.*:[ ]+[0-9a-f]+[ ]+nop diff --git a/ld/testsuite/ld-s390/s390.exp b/ld/testsuite/ld-s390/s390.exp index eb9ea35..ac62d7a 100644 --- a/ld/testsuite/ld-s390/s390.exp +++ b/ld/testsuite/ld-s390/s390.exp @@ -95,9 +95,12 @@ set s390xtests { "-m64" {pltoffset-1.s} {{objdump "-dzrj.text --stop-address=16" pltoffset-1.dd}} "pltoffset-1"} - {"WEAKUNDEF1: overflow test" + {"WEAKUNDEF1: overflow test (PC32DBL)" "-m elf64_s390 -dT 8GB.ld --no-error-rwx-segments" "" "-m64" {weakundef-1.s} {{objdump "-dzrj.text" weakundef-1.dd}} "weakundef-1"} + {"WEAKUNDEF2: overflow test (PLT32DBL)" + "-m elf64_s390 -dT 8GB.ld --no-error-rwx-segments -no-pie" "" "-m64" {weakundef-2.s} + {{objdump "-dzrj.text" weakundef-2.dd}} "weakundef-2"} } if [istarget "s390-*-*"] { diff --git a/ld/testsuite/ld-s390/weakundef-1.dd b/ld/testsuite/ld-s390/weakundef-1.dd index e514524..04d53c9 100644 --- a/ld/testsuite/ld-s390/weakundef-1.dd +++ b/ld/testsuite/ld-s390/weakundef-1.dd @@ -3,13 +3,13 @@ tmpdir/weakundef-1: file format elf64-s390 Disassembly of section .text: .* <foo>: -.*: c0 10 00 00 00 1e [ ]*larl %r1,20000003c <d> -.*: c0 10 00 00 00 1f [ ]*larl %r1,200000044 <wd> +.*: c0 10 00 00 00 1c [ ]*larl %r1,200000038 <d> +.*: c0 10 00 00 00 1d [ ]*larl %r1,200000040 <wd> .*: e3 10 00 00 00 71 [ ]*lay %r1,0 .*: c0 f4 00 00 00 01 [ ]*jg .* .*: c0 f4 00 00 00 01 [ ]*jg .* .*: c0 f4 00 00 00 01 [ ]*jg .* .*: c0 f4 00 00 00 01 [ ]*jg .* .*: c0 f4 00 00 00 01 [ ]*jg .* -.*: c0 f4 00 00 00 01 [ ]*jg .* .*: c0 04 00 00 00 00 [ ]*jgnop .* +.*: 07 07 [ ]*nopr %r7 diff --git a/ld/testsuite/ld-s390/weakundef-1.s b/ld/testsuite/ld-s390/weakundef-1.s index aeaef8d..db90932 100644 --- a/ld/testsuite/ld-s390/weakundef-1.s +++ b/ld/testsuite/ld-s390/weakundef-1.s @@ -9,7 +9,6 @@ foo: lrl %r1,wu strl %r1,wu exrl %r1,wu - brcth %r1,wu pfdrl %r1,wu .weak wd .weak wu diff --git a/ld/testsuite/ld-s390/weakundef-2.dd b/ld/testsuite/ld-s390/weakundef-2.dd new file mode 100644 index 0000000..e7f0e22 --- /dev/null +++ b/ld/testsuite/ld-s390/weakundef-2.dd @@ -0,0 +1,17 @@ +tmpdir/weakundef-2: file format elf64-s390 + +Disassembly of section .text: + +0+200000000 <foo>: +.*: c0 10 00 00 00 12 [ ]*larl %r1,200000024 <d> +.*: c0 10 00 00 00 10 [ ]*larl %r1,200000026 <wd> +.*: e3 10 00 00 00 71 [ ]*lay %r1,0 +.*: c0 e5 00 00 00 09 [ ]*brasl %r14,200000024 <d> +.*: c0 e5 00 00 00 07 [ ]*brasl %r14,200000026 <wd> +.*: c0 f4 00 00 00 01 [ ]*jg .* + +0+200000024 <d>: +.*: 07 fe [ ]*br %r14 + +0+200000026 <wd>: +.*: 07 fe [ ]*br %r14 diff --git a/ld/testsuite/ld-s390/weakundef-2.s b/ld/testsuite/ld-s390/weakundef-2.s new file mode 100644 index 0000000..d147b53 --- /dev/null +++ b/ld/testsuite/ld-s390/weakundef-2.s @@ -0,0 +1,17 @@ +.text + .globl foo +foo: + larl %r1,d@PLT + larl %r1,wd@PLT + larl %r1,wu@PLT + brasl %r14,d@PLT + brasl %r14,wd@PLT + brasl %r14,wu@PLT + .weak wu + .type d,@function +d: + br %r14 + .weak wd + .type wd,@function +wd: + br %r14 diff --git a/ld/testsuite/ld-sframe/discard.s b/ld/testsuite/ld-sframe/discard.s index a438b42..5591a50 100644 --- a/ld/testsuite/ld-sframe/discard.s +++ b/ld/testsuite/ld-sframe/discard.s @@ -5,7 +5,6 @@ foo: .cfi_startproc .cfi_def_cfa_offset 16 - .cfi_def_cfa 7, 8 .cfi_endproc .globl _start diff --git a/ld/testsuite/ld-unique/pr21529.d b/ld/testsuite/ld-unique/pr21529.d index 896f872..fb63794 100644 --- a/ld/testsuite/ld-unique/pr21529.d +++ b/ld/testsuite/ld-unique/pr21529.d @@ -1,6 +1,6 @@ #ld: --oformat binary -T pr21529.ld -e main #objdump: -s -b binary -#xfail: aarch64*-*-* arm*-*-* avr-*-* ia64-*-* m68hc1*-*-* nds32*-*-* riscv*-*-* score-*-* v850-*-* loongarch*-*-* +#xfail: aarch64*-*-* arm*-*-* avr-*-* ia64-*-* m68hc1*-*-* nds32*-*-* riscv*-*-* score-*-* v850-*-* # Skip targets which can't change output format to binary. #pass diff --git a/ld/testsuite/ld-x86-64/code16.d b/ld/testsuite/ld-x86-64/code16.d index 5b83681..ff21913 100644 --- a/ld/testsuite/ld-x86-64/code16.d +++ b/ld/testsuite/ld-x86-64/code16.d @@ -1,6 +1,6 @@ #name: x86-64 R_X86_64_PC16 reloc in 16-bit mode #as: --64 -mx86-used-note=no --generate-missing-build-notes=no -#source: ${srcdir}/../../../gas/testsuite/gas/i386/code16-2.s +#source: ../../../gas/testsuite/gas/i386/code16-2.s #ld: -T code16.t #objdump: -dw -Mi8086 diff --git a/ld/testsuite/ld-x86-64/hidden6.d b/ld/testsuite/ld-x86-64/hidden6.d new file mode 100644 index 0000000..c4c843b --- /dev/null +++ b/ld/testsuite/ld-x86-64/hidden6.d @@ -0,0 +1,3 @@ +#as: --64 +#ld: -shared -melf_x86_64 +#error: .*relocation R_X86_64_PC32 against undefined hidden symbol `foo' can not be used when making a shared object diff --git a/ld/testsuite/ld-x86-64/hidden6.s b/ld/testsuite/ld-x86-64/hidden6.s new file mode 100644 index 0000000..807422b --- /dev/null +++ b/ld/testsuite/ld-x86-64/hidden6.s @@ -0,0 +1,7 @@ + .text +.globl bar + .type bar, @function +bar: + mov foo(%rip), %eax + .size bar, .-bar + .hidden foo diff --git a/ld/testsuite/ld-x86-64/lam-u48.rd b/ld/testsuite/ld-x86-64/lam-u48.rd index ad31262..8fac904 100644 --- a/ld/testsuite/ld-x86-64/lam-u48.rd +++ b/ld/testsuite/ld-x86-64/lam-u48.rd @@ -1,3 +1,4 @@ +#... Displaying notes found in: .note.gnu.property [ ]+Owner[ ]+Data size[ ]+Description GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0 diff --git a/ld/testsuite/ld-x86-64/lam-u57.rd b/ld/testsuite/ld-x86-64/lam-u57.rd index 8b77e63..dd8d1da 100644 --- a/ld/testsuite/ld-x86-64/lam-u57.rd +++ b/ld/testsuite/ld-x86-64/lam-u57.rd @@ -1,3 +1,4 @@ +#... Displaying notes found in: .note.gnu.property [ ]+Owner[ ]+Data size[ ]+Description GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0 diff --git a/ld/testsuite/ld-x86-64/plt3.s b/ld/testsuite/ld-x86-64/plt3.s new file mode 100644 index 0000000..c3a29b5 --- /dev/null +++ b/ld/testsuite/ld-x86-64/plt3.s @@ -0,0 +1,27 @@ + .text + .global _start +_start: + movq $foo@PLT, %rax + leaq -11(%rip), %rbx + leaq (%rbx, %rax), %rax + call *%rax + + # Write out "PASS\n". + movl $5, %edx + movl $.LC0, %esi + movl $1, %edi + movl $1, %eax + syscall + + # exit + movq $60, %rax + movq $0, %rdi + syscall + +foo: + ret + + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "PASS\n" + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-x86-64/pr22393-3a.rd b/ld/testsuite/ld-x86-64/pr22393-3a.rd index b17e09b..4027ed3 100644 --- a/ld/testsuite/ld-x86-64/pr22393-3a.rd +++ b/ld/testsuite/ld-x86-64/pr22393-3a.rd @@ -1,5 +1,5 @@ #source: pr22393-1.s -#ld: -shared -z separate-code +#ld: -shared -z separate-code --no-rosegment #readelf: -l --wide #target: *-*-linux-gnu *-*-gnu* diff --git a/ld/testsuite/ld-x86-64/pr22393-3b.rd b/ld/testsuite/ld-x86-64/pr22393-3b.rd index b17e09b..4027ed3 100644 --- a/ld/testsuite/ld-x86-64/pr22393-3b.rd +++ b/ld/testsuite/ld-x86-64/pr22393-3b.rd @@ -1,5 +1,5 @@ #source: pr22393-1.s -#ld: -shared -z separate-code +#ld: -shared -z separate-code --no-rosegment #readelf: -l --wide #target: *-*-linux-gnu *-*-gnu* diff --git a/ld/testsuite/ld-x86-64/pr27590.rd b/ld/testsuite/ld-x86-64/pr27590.rd index 1946984..55ed17d 100644 --- a/ld/testsuite/ld-x86-64/pr27590.rd +++ b/ld/testsuite/ld-x86-64/pr27590.rd @@ -1,11 +1,11 @@ #... - \[[ 0-9]+\] .gnu.debuglto_.debug_info PROGBITS +0+ 0+28a 0+42 00 +E 0 +0 1 - \[[ 0-9]+\] .rela.gnu.debuglto_.debug_info RELA +0+ 0+810 0+f0 18 +I 26 17 8 - \[[ 0-9]+\] .gnu.debuglto_.debug_abbrev PROGBITS +0+ 0+2cc 0+26 00 +E 0 +0 1 - \[[ 0-9]+\] .gnu.debuglto_.debug_macro PROGBITS +0+ 0+2f2 0+2a 00 +E 0 +0 1 - \[[ 0-9]+\] .rela.gnu.debuglto_.debug_macro RELA +0+ 0+900 0+60 18 +I 26 20 8 - \[[ 0-9]+\] .gnu.debuglto_.debug_macro PROGBITS +0+ 0+31c 0+10 00 GE 0 +0 1 - \[[ 0-9]+\] .rela.gnu.debuglto_.debug_macro RELA +0+ 0+960 0+30 18 IG 26 22 8 - \[[ 0-9]+\] .gnu.debuglto_.debug_line PROGBITS +0+ 0+32c 0+8a 00 +E 0 +0 1 - \[[ 0-9]+\] .gnu.debuglto_.debug_str PROGBITS +0+ 0+3b6 0+15c 01 MSE 0 +0 1 + \[[ 0-9]+\] .gnu.debuglto_.debug_info PROGBITS +0+ [0-9a-f]+ 0+42 00 +E 0 +0 1 + \[[ 0-9]+\] .rela.gnu.debuglto_.debug_info RELA +0+ [0-9a-f]+ 0+f0 18 +I 26 17 8 + \[[ 0-9]+\] .gnu.debuglto_.debug_abbrev PROGBITS +0+ [0-9a-f]+ 0+26 00 +E 0 +0 1 + \[[ 0-9]+\] .gnu.debuglto_.debug_macro PROGBITS +0+ [0-9a-f]+ 0+2a 00 +E 0 +0 1 + \[[ 0-9]+\] .rela.gnu.debuglto_.debug_macro RELA +0+ [0-9a-f]+ 0+60 18 +I 26 20 8 + \[[ 0-9]+\] .gnu.debuglto_.debug_macro PROGBITS +0+ [0-9a-f]+ 0+10 00 GE 0 +0 1 + \[[ 0-9]+\] .rela.gnu.debuglto_.debug_macro RELA +0+ [0-9a-f]+ 0+30 18 IG 26 22 8 + \[[ 0-9]+\] .gnu.debuglto_.debug_line PROGBITS +0+ [0-9a-f]+ 0+8a 00 +E 0 +0 1 + \[[ 0-9]+\] .gnu.debuglto_.debug_str PROGBITS +0+ [0-9a-f]+ 0+15c 01 MSE 0 +0 1 #pass diff --git a/ld/testsuite/ld-x86-64/pr32067.s b/ld/testsuite/ld-x86-64/pr32067.s new file mode 100644 index 0000000..40878a9 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr32067.s @@ -0,0 +1,5 @@ + .text + .globl foo +foo: + ret + .section .note.GNU-stack diff --git a/ld/testsuite/ld-x86-64/pr32189.s b/ld/testsuite/ld-x86-64/pr32189.s new file mode 100644 index 0000000..3d0f682 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr32189.s @@ -0,0 +1,35 @@ + .text + .global _start +_start: + leaq 1f(%rip), %r11 +1: + movabs $_GLOBAL_OFFSET_TABLE_, %r15 + leaq (%r11,%r15), %r15 + + movabs $ptr@GOT, %rax + movabs $Ldst@GOTOFF, %rdx + movq (%rax,%r15), %rax + leaq (%rdx,%r15), %rcx + movq %rcx, (%rax) + + # Write out "PASS\n". + movl $5, %edx + movl $.LC0, %esi + movl $1, %edi + movl $1, %eax + syscall + + # exit + movq $60, %rax + movq $0, %rdi + syscall + + .data +Ldst: + .quad 0 +ptr: + .quad 0 + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "PASS\n" + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-x86-64/pr32191-x32.d b/ld/testsuite/ld-x86-64/pr32191-x32.d new file mode 100644 index 0000000..19e06a2 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr32191-x32.d @@ -0,0 +1,9 @@ +#source: pr32191.s +#as: --x32 -mx86-used-note=yes +#ld: -shared -m elf32_x86_64 -z separate-code --build-id --rosegment +#readelf: -lW + +#... + +[0-9]+ +\.note\.gnu\.build-id \.text + +[0-9]+ +\..* \.note\.gnu\.property .* +#pass diff --git a/ld/testsuite/ld-x86-64/pr32191.d b/ld/testsuite/ld-x86-64/pr32191.d new file mode 100644 index 0000000..9038ccd --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr32191.d @@ -0,0 +1,9 @@ +#source: pr32191.s +#as: --64 -mx86-used-note=yes +#ld: -shared -m elf_x86_64 -z separate-code --build-id --rosegment +#readelf: -lW + +#... + +[0-9]+ +\.note\.gnu\.build-id \.text + +[0-9]+ +\..* \.note\.gnu\.property .* +#pass diff --git a/ld/testsuite/ld-x86-64/pr32191.s b/ld/testsuite/ld-x86-64/pr32191.s new file mode 100644 index 0000000..953f0de --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr32191.s @@ -0,0 +1,5 @@ + .text + .global foo +foo: + .nops 4 + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-x86-64/rela.d b/ld/testsuite/ld-x86-64/rela.d index 20bb7e3..94bcc7f 100644 --- a/ld/testsuite/ld-x86-64/rela.d +++ b/ld/testsuite/ld-x86-64/rela.d @@ -1,6 +1,6 @@ #name: x86-64 rela relocs w/ non-zero relocated fields #as: --64 -#source: ${srcdir}/../../../gas/testsuite/gas/i386/rela.s +#source: ../../../gas/testsuite/gas/i386/rela.s #ld: -melf_x86_64 #objdump: -sj .data diff --git a/ld/testsuite/ld-x86-64/sframe-ibt-plt-1.d b/ld/testsuite/ld-x86-64/sframe-ibt-plt-1.d new file mode 100644 index 0000000..26be4df --- /dev/null +++ b/ld/testsuite/ld-x86-64/sframe-ibt-plt-1.d @@ -0,0 +1,33 @@ +#as: --gsframe +#source: ibt-plt-3.s +#objdump: --sframe=.sframe +#ld: -shared -z ibtplt --no-rosegment +#name: SFrame for IBT PLT .plt.sec + +.*: +file format .* + +Contents of the SFrame section .sframe: + Header : + + Version: SFRAME_VERSION_2 + Flags: SFRAME_F_FDE_SORTED + CFA fixed RA offset: \-8 +#... + + Function Index : + + func idx \[0\]: pc = 0x1000, size = 16 bytes + STARTPC +CFA +FP +RA + + 0+1000 +sp\+16 +u +f + + 0+1006 +sp\+24 +u +f + + + func idx \[1\]: pc = 0x1010, size = 32 bytes + STARTPC\[m\] +CFA +FP +RA + + 0+0000 +sp\+8 +u +f + + 0+0009 +sp\+16 +u +f + + + func idx \[2\]: pc = 0x1030, size = 32 bytes + STARTPC\[m\] +CFA +FP +RA + + 0+0000 +sp\+8 +u +f + + +#... diff --git a/ld/testsuite/ld-x86-64/sframe-plt-1.d b/ld/testsuite/ld-x86-64/sframe-plt-1.d index ca82cf2..52bca18 100644 --- a/ld/testsuite/ld-x86-64/sframe-plt-1.d +++ b/ld/testsuite/ld-x86-64/sframe-plt-1.d @@ -12,18 +12,19 @@ Contents of the SFrame section .sframe: Version: SFRAME_VERSION_2 Flags: SFRAME_F_FDE_SORTED + CFA fixed RA offset: \-8 #... Function Index : func idx \[0\]: pc = 0x1000, size = 16 bytes STARTPC +CFA +FP +RA + - 0+1000 +sp\+16 +u +u + - 0+1006 +sp\+24 +u +u + + 0+1000 +sp\+16 +u +f + + 0+1006 +sp\+24 +u +f + func idx \[1\]: pc = 0x1010, size = 16 bytes STARTPC\[m\] +CFA +FP +RA + - 0+0000 +sp\+8 +u +u + - 0+000b +sp\+16 +u +u + + 0+0000 +sp\+8 +u +f + + 0+000b +sp\+16 +u +f + #... diff --git a/ld/testsuite/ld-x86-64/sframe-pltgot-1.d b/ld/testsuite/ld-x86-64/sframe-pltgot-1.d new file mode 100644 index 0000000..23ff5d5 --- /dev/null +++ b/ld/testsuite/ld-x86-64/sframe-pltgot-1.d @@ -0,0 +1,28 @@ +#as: --gsframe +#source: sframe-pltgot-1.s +#objdump: --sframe=.sframe +#ld: -shared -z ibtplt --no-rosegment +#name: SFrame for IBT .plt.got + +.*: +file format .* + +Contents of the SFrame section .sframe: + Header : + + Version: SFRAME_VERSION_2 + Flags: SFRAME_F_FDE_SORTED + CFA fixed RA offset: \-8 +#... + + Function Index : + + func idx \[0\]: pc = 0x1000, size = 16 bytes + STARTPC +CFA +FP +RA + + 0+1000 +sp\+16 +u +f + + 0+1006 +sp\+24 +u +f + + + func idx \[1\]: pc = 0x1010, size = 64 bytes + STARTPC\[m\] +CFA +FP +RA + + 0+0000 +sp\+16 +u +f + + +#... diff --git a/ld/testsuite/ld-x86-64/sframe-pltgot-1.s b/ld/testsuite/ld-x86-64/sframe-pltgot-1.s new file mode 100644 index 0000000..e596e84 --- /dev/null +++ b/ld/testsuite/ld-x86-64/sframe-pltgot-1.s @@ -0,0 +1,15 @@ + .text + .globl foo + .type foo, @function +foo: + .cfi_startproc + call func1@plt + movq func1@GOTPCREL(%rip), %rax + call func2@plt + movq func2@GOTPCREL(%rip), %rax + call func3@plt + movq func3@GOTPCREL(%rip), %rax + call func4@plt + movq func4@GOTPCREL(%rip), %rax + .cfi_endproc + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-x86-64/sframe-pltgot-2.d b/ld/testsuite/ld-x86-64/sframe-pltgot-2.d new file mode 100644 index 0000000..7a99d12 --- /dev/null +++ b/ld/testsuite/ld-x86-64/sframe-pltgot-2.d @@ -0,0 +1,28 @@ +#as: --gsframe +#source: sframe-pltgot-1.s +#objdump: --sframe=.sframe +#ld: -shared --no-rosegment +#name: SFrame for .plt.got + +.*: +file format .* + +Contents of the SFrame section .sframe: + Header : + + Version: SFRAME_VERSION_2 + Flags: SFRAME_F_FDE_SORTED + CFA fixed RA offset: \-8 +#... + + Function Index : + + func idx \[0\]: pc = 0x1000, size = 16 bytes + STARTPC +CFA +FP +RA + + 0+1000 +sp\+16 +u +f + + 0+1006 +sp\+24 +u +f + + + func idx \[1\]: pc = 0x1010, size = 32 bytes + STARTPC\[m\] +CFA +FP +RA + + 0+0000 +sp\+16 +u +f + + +#... diff --git a/ld/testsuite/ld-x86-64/sframe-simple-1.d b/ld/testsuite/ld-x86-64/sframe-simple-1.d index adc4b74..7d88419 100644 --- a/ld/testsuite/ld-x86-64/sframe-simple-1.d +++ b/ld/testsuite/ld-x86-64/sframe-simple-1.d @@ -12,6 +12,7 @@ Contents of the SFrame section .sframe: Version: SFRAME_VERSION_2 Flags: SFRAME_F_FDE_SORTED + CFA fixed RA offset: \-8 #... Function Index : @@ -22,14 +23,14 @@ Contents of the SFrame section .sframe: func idx \[2\]: pc = 0x1020, size = 53 bytes STARTPC +CFA +FP +RA + - 0+1020 +sp\+8 +u +u + - 0+1021 +sp\+16 +c-16 +u + - 0+1024 +fp\+16 +c-16 +u + - 0+1054 +sp\+8 +c-16 +u + + 0+1020 +sp\+8 +u +f + + 0+1021 +sp\+16 +c-16 +f + + 0+1024 +fp\+16 +c-16 +f + + 0+1054 +sp\+8 +c-16 +f + func idx \[3\]: pc = 0x1055, size = 37 bytes STARTPC +CFA +FP +RA + - 0+1055 +sp\+8 +u +u + - 0+1056 +sp\+16 +c-16 +u + - 0+1059 +fp\+16 +c-16 +u + - 0+1079 +sp\+8 +c-16 +u + + 0+1055 +sp\+8 +u +f + + 0+1056 +sp\+16 +c-16 +f + + 0+1059 +fp\+16 +c-16 +f + + 0+1079 +sp\+8 +c-16 +f + diff --git a/ld/testsuite/ld-x86-64/tlsbindesc.dd b/ld/testsuite/ld-x86-64/tlsbindesc.dd index 7aa1b92..601dfc2 100644 --- a/ld/testsuite/ld-x86-64/tlsbindesc.dd +++ b/ld/testsuite/ld-x86-64/tlsbindesc.dd @@ -175,6 +175,9 @@ Disassembly of section .text: +[0-9a-f]+: 62 f4 fc 10 03 ([0-9a-f]{2} ){2}[ ]+add 0x[0-9a-f]+\(%rip\),%rax,%r16 +# [0-9a-f]+ <sG2> # -> R_X86_64_TPOFF64 sG2 +[0-9a-f]+: ([0-9a-f]{2} ){3} * + +[0-9a-f]+: 62 e4 fc 0c 03 ([0-9a-f]{2} ){2}[ ]+\{nf\} add 0x[0-9a-f]+\(%rip\),%r16 +# [0-9a-f]+ <sG2> +# -> R_X86_64_TPOFF64 sG2 + +[0-9a-f]+: ([0-9a-f]{2} ){3} * +[0-9a-f]+: 62 f4 fc 14 01 ([0-9a-f]{2} ){2}[ ]+\{nf\} add %rax,0x[0-9a-f]+\(%rip\),%r16 +# [0-9a-f]+ <sG2> # -> R_X86_64_TPOFF64 sG2 +[0-9a-f]+: ([0-9a-f]{2} ){3} * @@ -191,6 +194,9 @@ Disassembly of section .text: +[0-9a-f]+: 62 d4 f4 10 81 ([0-9a-f]{2} ){2}[ ]+add \$0x[0-9a-f]+,%r8,%r17 # sg1 +[0-9a-f]+: ff ff ff * + +[0-9a-f]+: 62 fc fc 0c 81 ([0-9a-f]{2} ){2}[ ]+\{nf\} add \$0x[0-9a-f]+,%r17 +# sg1 + +[0-9a-f]+: ff ff ff * +[0-9a-f]+: 62 d4 f4 14 81 ([0-9a-f]{2} ){2}[ ]+\{nf\} add \$0x[0-9a-f]+,%r8,%r17 # sg1 +[0-9a-f]+: ff ff ff * @@ -207,6 +213,9 @@ Disassembly of section .text: +[0-9a-f]+: 62 d4 fc 18 81 ([0-9a-f]{2} ){2}[ ]+add \$0x[0-9a-f]+,%r8,%rax # sl1 +[0-9a-f]+: ff ff ff * + +[0-9a-f]+: 62 fc fc 0c 81 ([0-9a-f]{2} ){2}[ ]+\{nf\} add \$0x[0-9a-f]+,%r18 +# sl1 + +[0-9a-f]+: ff ff ff * +[0-9a-f]+: 62 d4 fc 1c 81 ([0-9a-f]{2} ){2}[ ]+\{nf\} add \$0x[0-9a-f]+,%r8,%rax # sl1 +[0-9a-f]+: ff ff ff * @@ -223,6 +232,9 @@ Disassembly of section .text: +[0-9a-f]+: 62 fc bc 18 81 ([0-9a-f]{2} ){2}[ ]+add \$0x[0-9a-f]+,%r19,%r8 # sh1 +[0-9a-f]+: ff ff ff * + +[0-9a-f]+: 62 fc fc 0c 81 ([0-9a-f]{2} ){2}[ ]+\{nf\} add \$0x[0-9a-f]+,%r19 +# sh1 + +[0-9a-f]+: ff ff ff * +[0-9a-f]+: 62 fc bc 1c 81 ([0-9a-f]{2} ){2}[ ]+\{nf\} add \$0x[0-9a-f]+,%r19,%r8 # sh1 +[0-9a-f]+: ff ff ff * diff --git a/ld/testsuite/ld-x86-64/tlsbindesc.rd b/ld/testsuite/ld-x86-64/tlsbindesc.rd index 1e0348e..2fc965a 100644 --- a/ld/testsuite/ld-x86-64/tlsbindesc.rd +++ b/ld/testsuite/ld-x86-64/tlsbindesc.rd @@ -15,12 +15,12 @@ Section Headers: +\[[ 0-9]+\] .dynsym +.* +\[[ 0-9]+\] .dynstr +.* +\[[ 0-9]+\] .rela.dyn +.* - +\[[ 0-9]+\] .text +PROGBITS +0+401000 0+1000 0+2fd 00 +AX +0 +0 +4096 - +\[[ 0-9]+\] .tdata +PROGBITS +0+6012fd 0+12fd 0+60 00 WAT +0 +0 +1 - +\[[ 0-9]+\] .tbss +NOBITS +0+60135d 0+135d 0+40 00 WAT +0 +0 +1 - +\[[ 0-9]+\] .dynamic +DYNAMIC +0+601360 0+1360 0+100 10 +WA +4 +0 +8 - +\[[ 0-9]+\] .got +PROGBITS +0+601460 0+1460 0+20 08 +WA +0 +0 +8 - +\[[ 0-9]+\] .got.plt +PROGBITS +0+601480 0+1480 0+18 08 +WA +0 +0 +8 + +\[[ 0-9]+\] .text +PROGBITS +0+401000 0+1000 0+325 00 +AX +0 +0 +4096 + +\[[ 0-9]+\] .tdata +PROGBITS +0+601325 0+1325 0+60 00 WAT +0 +0 +1 + +\[[ 0-9]+\] .tbss +NOBITS +0+601385 0+1385 0+40 00 WAT +0 +0 +1 + +\[[ 0-9]+\] .dynamic +DYNAMIC +0+601388 0+1388 0+100 10 +WA +4 +0 +8 + +\[[ 0-9]+\] .got +PROGBITS +0+601488 0+1488 0+20 08 +WA +0 +0 +8 + +\[[ 0-9]+\] .got.plt +PROGBITS +0+6014a8 0+14a8 0+18 08 +WA +0 +0 +8 +\[[ 0-9]+\] .symtab +.* +\[[ 0-9]+\] .strtab +.* +\[[ 0-9]+\] .shstrtab +.* @@ -28,7 +28,7 @@ Key to Flags: #... Elf file type is EXEC \(Executable file\) -Entry point 0x401205 +Entry point 0x40122d There are [0-9]+ program headers, starting at offset [0-9]+ Program Headers: @@ -36,10 +36,10 @@ Program Headers: +PHDR.* +INTERP.* .*Requesting program interpreter.* - +LOAD +0x0+ 0x0+400000 0x0+400000 0x0+12fd 0x0+12fd R E 0x200000 - +LOAD +0x0+12fd 0x0+6012fd 0x0+6012fd 0x0+19b 0x0+19b RW +0x200000 - +DYNAMIC +0x0+1360 0x0+601360 0x0+601360 0x0+100 0x0+100 RW +0x8 - +TLS +0x0+12fd 0x0+6012fd 0x0+6012fd 0x0+60 0x0+a0 R +0x1 + +LOAD +0x0+ 0x0+400000 0x0+400000 0x0+1325 0x0+1325 R E 0x200000 + +LOAD +0x0+1325 0x0+601325 0x0+601325 0x0+19b 0x0+19b RW +0x200000 + +DYNAMIC +0x0+1388 0x0+601388 0x0+601388 0x0+100 0x0+100 RW +0x8 + +TLS +0x0+1325 0x0+601325 0x0+601325 0x0+60 0x0+a0 R +0x1 Section to Segment mapping: +Segment Sections... @@ -52,10 +52,10 @@ Program Headers: Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 4 entries: +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend -0+601460 +0+100000012 R_X86_64_TPOFF64 +0+ sG5 \+ 0 -0+601468 +0+200000012 R_X86_64_TPOFF64 +0+ sG2 \+ 0 -0+601470 +0+300000012 R_X86_64_TPOFF64 +0+ sG6 \+ 0 -0+601478 +0+400000012 R_X86_64_TPOFF64 +0+ sG1 \+ 0 +0+601488 +0+100000012 R_X86_64_TPOFF64 +0+ sG5 \+ 0 +0+601490 +0+200000012 R_X86_64_TPOFF64 +0+ sG2 \+ 0 +0+601498 +0+300000012 R_X86_64_TPOFF64 +0+ sG6 \+ 0 +0+6014a0 +0+400000012 R_X86_64_TPOFF64 +0+ sG1 \+ 0 Symbol table '\.dynsym' contains [0-9]+ entries: +Num: +Value +Size +Type +Bind +Vis +Ndx +Name @@ -88,8 +88,8 @@ Symbol table '\.symtab' contains [0-9]+ entries: +[0-9]+: 0+9c +0 +TLS +LOCAL +DEFAULT +8 bl8 .* FILE +LOCAL +DEFAULT +ABS +[0-9]+: 0+a0 +0 +TLS +LOCAL +DEFAULT +7 _TLS_MODULE_BASE_ - +[0-9]+: 0+601360 +0 +OBJECT +LOCAL +DEFAULT +9 _DYNAMIC - +[0-9]+: 0+601480 +0 +OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_ + +[0-9]+: 0+601388 +0 +OBJECT +LOCAL +DEFAULT +9 _DYNAMIC + +[0-9]+: 0+6014a8 +0 +OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_ +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8 +[0-9]+: 0+7c +0 +TLS +GLOBAL +DEFAULT +8 bg8 +[0-9]+: 0+74 +0 +TLS +GLOBAL +DEFAULT +8 bg6 @@ -104,7 +104,7 @@ Symbol table '\.symtab' contains [0-9]+ entries: +[0-9]+: 0+58 +0 +TLS +GLOBAL +HIDDEN +7 sh7 +[0-9]+: 0+5c +0 +TLS +GLOBAL +HIDDEN +7 sh8 +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1 - +[0-9]+: 0+401205 +0 +FUNC +GLOBAL +DEFAULT +6 _start + +[0-9]+: 0+40122d +0 +FUNC +GLOBAL +DEFAULT +6 _start +[0-9]+: 0+4c +0 +TLS +GLOBAL +HIDDEN +7 sh4 +[0-9]+: 0+78 +0 +TLS +GLOBAL +DEFAULT +8 bg7 +[0-9]+: 0+50 +0 +TLS +GLOBAL +HIDDEN +7 sh5 diff --git a/ld/testsuite/ld-x86-64/tlsbindesc.s b/ld/testsuite/ld-x86-64/tlsbindesc.s index 8aad102..39ba3bb 100644 --- a/ld/testsuite/ld-x86-64/tlsbindesc.s +++ b/ld/testsuite/ld-x86-64/tlsbindesc.s @@ -131,6 +131,7 @@ fn2: addq sG2@gottpoff(%rip), %r16 addq %rax, sG2@gottpoff(%rip), %r16 addq sG2@gottpoff(%rip), %rax, %r16 + {nf} addq sG2@gottpoff(%rip), %r16 {nf} addq %rax, sG2@gottpoff(%rip), %r16 {nf} addq sG2@gottpoff(%rip), %rax, %r16 @@ -138,6 +139,7 @@ fn2: addq sg1@gottpoff(%rip), %r17 addq %r8, sg1@gottpoff(%rip), %r17 addq sg1@gottpoff(%rip), %r8, %r17 + {nf} addq sg1@gottpoff(%rip), %r17 {nf} addq %r8, sg1@gottpoff(%rip), %r17 {nf} addq sg1@gottpoff(%rip), %r8, %r17 @@ -145,6 +147,7 @@ fn2: addq sl1@gottpoff(%rip), %r18 addq %r8, sl1@gottpoff(%rip), %rax addq sl1@gottpoff(%rip), %r8, %rax + {nf} addq sl1@gottpoff(%rip), %r18 {nf} addq %r8, sl1@gottpoff(%rip), %rax {nf} addq sl1@gottpoff(%rip), %r8, %rax @@ -152,6 +155,7 @@ fn2: addq sh1@gottpoff(%rip), %r19 addq %r19, sh1@gottpoff(%rip), %r8 addq sh1@gottpoff(%rip), %r19, %r8 + {nf} addq sh1@gottpoff(%rip), %r19 {nf} addq %r19, sh1@gottpoff(%rip), %r8 {nf} addq sh1@gottpoff(%rip), %r19, %r8 diff --git a/ld/testsuite/ld-x86-64/tlsdesc3.d b/ld/testsuite/ld-x86-64/tlsdesc3.d new file mode 100644 index 0000000..9558848 --- /dev/null +++ b/ld/testsuite/ld-x86-64/tlsdesc3.d @@ -0,0 +1,4 @@ +#name: TLS GDesc->LE transition check (LEA) +#as: --64 -mtls-check=no +#ld: -melf_x86_64 +#error: .*: relocation R_X86_64_GOTPC32_TLSDESC against `foo' must be used in LEA only diff --git a/ld/testsuite/ld-x86-64/tlsdesc3.s b/ld/testsuite/ld-x86-64/tlsdesc3.s new file mode 100644 index 0000000..4531065 --- /dev/null +++ b/ld/testsuite/ld-x86-64/tlsdesc3.s @@ -0,0 +1,13 @@ + .text + .globl _start + .type _start,@function +_start: + movq foo@tlsdesc(%rip), %rax + call *foo@tlscall(%rax) + .globl foo + .section .tdata,"awT",@progbits + .align 8 + .type foo, @object + .size foo, 8 +foo: + .quad 100 diff --git a/ld/testsuite/ld-x86-64/tlsdesc4.d b/ld/testsuite/ld-x86-64/tlsdesc4.d new file mode 100644 index 0000000..ccaa525 --- /dev/null +++ b/ld/testsuite/ld-x86-64/tlsdesc4.d @@ -0,0 +1,4 @@ +#name: TLS GDesc->LE transition check (indirect CALL) +#as: --64 -mtls-check=no +#ld: -melf_x86_64 +#error: .*: relocation R_X86_64_TLSDESC_CALL against `foo' must be used in indirect CALL with RAX register only diff --git a/ld/testsuite/ld-x86-64/tlsdesc4.s b/ld/testsuite/ld-x86-64/tlsdesc4.s new file mode 100644 index 0000000..1f3febc --- /dev/null +++ b/ld/testsuite/ld-x86-64/tlsdesc4.s @@ -0,0 +1,13 @@ + .text + .globl _start + .type _start,@function +_start: + leaq foo@tlsdesc(%rip), %rcx + call *foo@tlscall(%rcx) + .globl foo + .section .tdata,"awT",@progbits + .align 8 + .type foo, @object + .size foo, 8 +foo: + .quad 100 diff --git a/ld/testsuite/ld-x86-64/tlsdesc5.d b/ld/testsuite/ld-x86-64/tlsdesc5.d new file mode 100644 index 0000000..0876993 --- /dev/null +++ b/ld/testsuite/ld-x86-64/tlsdesc5.d @@ -0,0 +1,5 @@ +#source: tlsdesc4.s +#name: TLS GDesc call (indirect CALL) +#as: --64 -mtls-check=no +#ld: -shared -melf_x86_64 +#error: .*: relocation R_X86_64_TLSDESC_CALL against `foo' must be used in indirect CALL with RAX register only diff --git a/ld/testsuite/ld-x86-64/tlsie2.d b/ld/testsuite/ld-x86-64/tlsie2.d index 97dcc28..2e6d41c 100644 --- a/ld/testsuite/ld-x86-64/tlsie2.d +++ b/ld/testsuite/ld-x86-64/tlsie2.d @@ -1,4 +1,4 @@ #name: TLS IE->LE transition check -#as: --64 +#as: --64 -mtls-check=no #ld: -melf_x86_64 -#error: .*TLS transition from R_X86_64_GOTTPOFF to R_X86_64_TPOFF32 against `foo'.*failed.* +#error: .*: relocation R_X86_64_GOTTPOFF against `foo' must be used in ADD or MOV only diff --git a/ld/testsuite/ld-x86-64/tlsie3.d b/ld/testsuite/ld-x86-64/tlsie3.d index 8c982a6..b59cc64 100644 --- a/ld/testsuite/ld-x86-64/tlsie3.d +++ b/ld/testsuite/ld-x86-64/tlsie3.d @@ -1,4 +1,4 @@ #name: TLS IE->LE transition check (%r12) -#as: --64 +#as: --64 -mtls-check=no #ld: -melf_x86_64 -#error: .*TLS transition from R_X86_64_GOTTPOFF to R_X86_64_TPOFF32 against `foo'.*failed.* +#error: .*: relocation R_X86_64_GOTTPOFF against `foo' must be used in ADD or MOV only diff --git a/ld/testsuite/ld-x86-64/tlsie5.d b/ld/testsuite/ld-x86-64/tlsie5.d new file mode 100644 index 0000000..d7ab5ab --- /dev/null +++ b/ld/testsuite/ld-x86-64/tlsie5.d @@ -0,0 +1,4 @@ +#name: TLS IE->LE transition check (APX) +#as: --64 -mtls-check=no +#ld: -melf_x86_64 +#error: .*: relocation R_X86_64_CODE_6_GOTTPOFF against `foo' must be used in ADD only diff --git a/ld/testsuite/ld-x86-64/tlsie5.s b/ld/testsuite/ld-x86-64/tlsie5.s new file mode 100644 index 0000000..c39e46f --- /dev/null +++ b/ld/testsuite/ld-x86-64/tlsie5.s @@ -0,0 +1,12 @@ + .text + .globl _start +_start: + xorq %rax, foo@GOTTPOFF(%rip), %rax + movq (%rax), %rax + .globl foo + .section .tdata,"awT",@progbits + .align 4 + .type foo, @object + .size foo, 4 +foo: + .long 100 diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index dddac43..377d4a2 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -321,6 +321,7 @@ run_dump_test "hidden2" run_dump_test "hidden3" run_dump_test "hidden4" run_dump_test "hidden5" +run_dump_test "hidden6" run_dump_test "protected1" run_dump_test "protected2" run_dump_test "protected3" @@ -537,10 +538,19 @@ run_dump_test "pr31868b" run_dump_test "pr31868b-x32" run_dump_test "pr31868c" run_dump_test "pr31868c-x32" +run_dump_test "tlsie5" +run_dump_test "tlsdesc3" +run_dump_test "tlsdesc4" +run_dump_test "tlsdesc5" +run_dump_test "pr32191" +run_dump_test "pr32191-x32" if { ![skip_sframe_tests] } { run_dump_test "sframe-simple-1" run_dump_test "sframe-plt-1" + run_dump_test "sframe-ibt-plt-1" + run_dump_test "sframe-pltgot-1" + run_dump_test "sframe-pltgot-2" } if ![istarget "x86_64-*-linux*"] { @@ -774,9 +784,9 @@ proc undefined_weak {cflags ldflags} { if { [string match "*-fPIE*" $cflags] && ![string match "*nodynamic-undefined-weak*" $ldflags] } { - set weak_symbol "Weak defined" + set weak_symbol "Weak defined\n" } else { - set weak_symbol "Weak undefined" + set weak_symbol "Weak undefined\n" } run_cc_link_tests [list \ @@ -1215,7 +1225,7 @@ if { [isnative] && [check_compiler_available] } { ] \ [list \ "Build pr22393-3a.so" \ - "-shared -Wl,-z,separate-code,-z,max-page-size=0x1000" \ + "-shared -Wl,-z,separate-code,-z,max-page-size=0x1000,--no-rosegment" \ "-fPIC -Wa,-mx86-used-note=yes" \ {pr22393-3a.c} \ {{readelf -lW pr22393-3a.rd} \ @@ -1224,7 +1234,7 @@ if { [isnative] && [check_compiler_available] } { ] \ [list \ "Build pr22393-3a-now.so" \ - "-shared -Wl,-z,separate-code,-z,now,-z,max-page-size=0x1000" \ + "-shared -Wl,-z,separate-code,-z,now,-z,max-page-size=0x1000,--no-rosegment" \ "-fPIC -Wa,-mx86-used-note=yes" \ {pr22393-3a.c} \ {{readelf -lW pr22393-3a.rd} \ @@ -1233,7 +1243,7 @@ if { [isnative] && [check_compiler_available] } { ] \ [list \ "Build pr22393-3" \ - "$NOPIE_LDFLAGS -Wl,-z,separate-code,-z,max-page-size=0x1000,--no-as-needed tmpdir/pr22393-3a.so" \ + "$NOPIE_LDFLAGS -Wl,-z,separate-code,-z,max-page-size=0x1000,--no-rosegment,--no-as-needed tmpdir/pr22393-3a.so" \ "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \ {pr22393-3b.c} \ {{readelf -lW pr22393-3a.rd} \ @@ -1242,7 +1252,7 @@ if { [isnative] && [check_compiler_available] } { ] \ [list \ "Build pr22393-3 (PIE)" \ - "-pie -Wl,-z,separate-code,-z,max-page-size=0x1000,--no-as-needed tmpdir/pr22393-3a-now.so" \ + "-pie -Wl,-z,separate-code,-z,max-page-size=0x1000,--no-rosegment,--no-as-needed tmpdir/pr22393-3a-now.so" \ "-fPIE -Wa,-mx86-used-note=yes" \ {pr22393-3b.c} \ {{readelf -lW pr22393-3a.rd} \ @@ -1251,7 +1261,7 @@ if { [isnative] && [check_compiler_available] } { ] \ [list \ "Build pr22393-3 (static)" \ - "-static -Wl,-z,separate-code,-z,max-page-size=0x1000" \ + "-static -Wl,-z,separate-code,-z,max-page-size=0x1000,--no-rosegment" \ "-Wa,-mx86-used-note=yes" \ {pr22393-3a.c pr22393-3b.c} \ {{readelf -lW pr22393-3a.rd} \ @@ -1402,6 +1412,14 @@ if { [isnative] && [check_compiler_available] } { {{readelf -n indirect-extern-access.rd}} \ "libprotected-data-2b.so" \ ] \ + [list \ + "Build pr32067" \ + "-Wl,--oformat,binary -nostdlib -nostartfiles" \ + "" \ + { start.s pr32067.s } \ + {} \ + "pr32067" \ + ] \ ] if {[istarget "x86_64-*-linux*-gnux32"]} { @@ -1909,6 +1927,22 @@ if { [isnative] && [check_compiler_available] } { "pass.out" \ "-fPIE" \ ] \ + [list \ + "Run pr32189" \ + "$NOPIE_LDFLAGS -nostdlib -nostartfiles" \ + "" \ + { pr32189.s } \ + "pr32189" \ + "pass.out" \ + ] \ + [list \ + "Run plt3" \ + "$NOPIE_LDFLAGS -nostdlib -nostartfiles" \ + "" \ + { plt3.s } \ + "plt3" \ + "pass.out" \ + ] \ ] # Run-time tests which require working ifunc attribute support. @@ -2274,6 +2308,13 @@ run_dump_test "ibt-plt-3a-x32" run_dump_test "ibt-plt-3b-x32" run_dump_test "ibt-plt-3c-x32" run_dump_test "ibt-plt-3d-x32" + +# Skip -z mark-plt tests on MUSL. +if { [istarget "x86_64-*-musl*"]} { + set ASFLAGS "$saved_ASFLAGS" + return +} + run_dump_test "mark-plt-1a" run_dump_test "mark-plt-1b" run_dump_test "mark-plt-1c" diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index e6e643c..4c43425 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -33,27 +33,14 @@ proc at_least_gcc_version { major minor } { return 0 } # Filter out -Wl, options. - regsub -all -- "-Wl,\[^ ^\t\]+" $CC_FOR_TARGET "" cc_cmd - set state [remote_exec host $cc_cmd --version] + regsub -all -- {-Wl,[^ \t]+} $CC_FOR_TARGET {} cc_cmd + set prog "\"#if $major < __GNUC__ + ($minor <= __GNUC_MINOR__)\nyes\n#endif\"" + set cmd "echo $prog | $cc_cmd -E -" + set state [remote_exec host [concat sh -c [list "$cmd 2>/dev/null"]]] if { [lindex $state 0] != 0 } { return 0; } - set tmp "[lindex $state 1]\n" - # Look for (eg) 4.6.1 in the version output. - set ver_re "\[^\\.0-9\]+(\[1-9\]\[0-9\]*)\\.(\[0-9\]+)(?:\\.\[0-9\]+)?" - regexp $ver_re $tmp fred maj min - verbose "gcc version: $tmp" - if { ![info exists maj] || ![info exists min] } then { - perror "can't decipher gcc version number, fix the framework!" - return 0 - } - verbose "major gcc version is $maj, want at least $major" - if { $maj == $major } then { - verbose "minor gcc version is $min, want at least $minor" - return [expr $min >= $minor] - } else { - return [expr $maj > $major] - } + return [regexp {(?x)yes} [lindex $state 1]] } # Extract and print the version number of ld. @@ -109,12 +96,12 @@ proc run_host_cmd { prog command } { set gccflags "$gcc_B_opt $gccflags $ld_L_opt" if {![info exists gcc_ld_B_opt_tested]} { set gcc_ld_B_opt_tested 1 - set ld_version_message [run_host_cmd "$ld" "--version"] + set ld_version_message [string trim [run_host_cmd "$ld" "--version"]] set ver "-Wl,--version" if [check_lto_available] { set ver "-fno-lto $ver" } - set gcc_ld_version_message [run_host_cmd "$prog" "$gccflags $ver"] + set gcc_ld_version_message [string trim [run_host_cmd "$prog" "$gccflags $ver"]] if {[string first $ld_version_message $gcc_ld_version_message] < 0} { perror "************************************************************************" perror "Your compiler apparently ignores -B when choosing ld." @@ -123,7 +110,7 @@ proc run_host_cmd { prog command } { perror "Hint: don't configure gcc using --with-ld (or --with-as)" } perror "You will not be testing the new ld in many of the following tests." - set gcc_ld_version [run_host_cmd "$prog" "$gccflags --print-prog-name=ld"] + set gcc_ld_version [string trim [run_host_cmd "$prog" "$gccflags --print-prog-name=ld"]] if {![string match "" $gcc_ld_version] && ![string match "ld" $gcc_ld_version]} { perror "It seems you will be testing $gcc_ld_version instead." } @@ -136,9 +123,8 @@ proc run_host_cmd { prog command } { set status [remote_exec host [concat sh -c [list "$prog $gccflags $command 2>&1"]] "" "/dev/null" "ld.tmp"] remote_upload host "ld.tmp" set link_output [file_contents "ld.tmp"] - regsub "\n$" $link_output "" link_output if { [lindex $status 0] != 0 && [string match "" $link_output] } then { - append link_output "child process exited abnormally" + set link_output "child process exited abnormally" } remote_file build delete ld.tmp remote_file host delete ld.tmp @@ -502,6 +488,11 @@ proc run_ld_link_tests { ldtests args } { set maybe_failed 0 set ld_output "" + # Don't leave previous output around + if { $binfile ne "tmpdir/" } { + remote_file host delete $binfile + } + # Add -fno-lto. LTO should be tested explicitly by $cflags. if {[check_lto_available]} { set cflags "-fno-lto $cflags" @@ -720,6 +711,11 @@ proc run_ld_link_exec_tests { ldtests args } { set objfiles {} set failed 0 + # Don't leave previous output around + if { $binfile ne "tmpdir/" } { + remote_file host delete $binfile + } + if { ![check_compiler_available] } { unsupported $testname continue @@ -889,6 +885,11 @@ proc run_cc_link_tests { ldtests } { set check_ld(terminal) 0 set check_ld(source) "" + # Don't leave previous output around + if { $binfile ne "tmpdir/" } { + remote_file host delete $binfile + } + if { ![check_compiler_available] } { unsupported $testname continue @@ -1140,6 +1141,7 @@ proc uses_genelf { } { || [istarget "ft32-*-*"] || [istarget "iq2000-*-*"] || [istarget "mn10200-*-*"] + || [istarget "moxie-*-moxiebox*"] || [istarget "msp430-*-*"] || [istarget "mt-*-*"] || [istarget "pj*-*-*"] @@ -1150,6 +1152,14 @@ proc uses_genelf { } { return 0 } +# Return true if target uses elf.em. +proc uses_elf_em { } { + if { [is_elf_format] && ![uses_genelf] } { + return 1; + } + return 0; +} + proc is_underscore_target { } { global is_underscore_target_saved global target_triplet |