From 0209f552341ba16b515628ee5abc147fffc28885 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 28 Nov 2020 04:43:59 -0800 Subject: [PATCH] ld: Run PR ld/26936 test only if supported Linkonce sections and comdat groups can be mixed only if comdat groups have only a single member with matching symbol table entries. 1. Skip ld/26936 test if comdat groups always have more than one member. 2. Skip ld/26936 test if symbol table entries in linkonce and comdat group don't match. 3. Skip ld/26936 test if the assembly source file is renamed. PR ld/26936 * testsuite/ld-elf/pr26936.d: Run only if mixing linkonce and comdat sections is supported. * testsuite/lib/ld-lib.exp (check_mix_linkonce_comdat_support): New proc. --- ld/testsuite/ld-elf/pr26936.d | 8 ++++++- ld/testsuite/lib/ld-lib.exp | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/ld/testsuite/ld-elf/pr26936.d b/ld/testsuite/ld-elf/pr26936.d index 3c854fa0b5..887c44237f 100644 --- a/ld/testsuite/ld-elf/pr26936.d +++ b/ld/testsuite/ld-elf/pr26936.d @@ -4,7 +4,13 @@ #as: --gen-debug #ld: -z noseparate-code -Ttext-segment 0x10000 -z max-page-size=0x1000 #readelf: -wL -#target: [check_shared_lib_support] +#target: [check_mix_linkonce_comdat_support] +# Assembly source file for the HPPA assembler is renamed and modifed by +# sed. mn10300 and riscv put different numbers of local symbols in +# linkonce section and comdat sections. Some MIPS targets put section +# names in symbol table. +#notarget: am33_2.0-*-* hppa*-*-hpux* mips*-*-elf mips*-*-irix* +#notarget: mn10300-*-* tx39*-*-* riscv*-*-* #... CU: .*/pr26936c.s: diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index 1aa614fa36..708060d261 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -1660,3 +1660,47 @@ proc skip_ctf_tests { } { return 1 } + +# Returns true if mixing linkonce and comdat sections is supported on +# the target. + +proc check_mix_linkonce_comdat_support {} { + global mix_linkonce_comdat_support_saved + global AS + global ASFLAGS + global READELF + + if {[info exists mix_linkonce_comdat_support_saved]} { + return $mix_linkonce_comdat_support_saved + } + + if {![is_elf_format] || ![check_shared_lib_support]} { + set mix_linkonce_comdat_support_saved 0 + return $mix_linkonce_comdat_support_saved + } + + set test "test[pid]" + set f [open ${test}.s "w"] + puts $f " .section .text,\"axG\",%progbits,foo,comdat" + puts $f " .globl foo" + puts $f " .type foo, %function" + puts $f "foo:" + puts $f " .nop" + close $f + if {![ld_assemble_flags $AS "$ASFLAGS --gen-debug" ${test}.s ${test}.o]} { + set mix_linkonce_comdat_support_saved 0 + return $mix_linkonce_comdat_support_saved + } + set got [remote_exec host "$READELF -SWg ${test}.o"] + # Only single member comdat groups can be mixed with linkonce + # sections. + if {[lindex $got 0] != 0 \ + || ![regexp -- "COMDAT group section \\\[ +\[0-9\]+\\\] `.group' \\\[foo\\\] contains 1 sections:" [lindex $got 1]]} then { + set mix_linkonce_comdat_support_saved 0 + } else { + set mix_linkonce_comdat_support_saved 1 + } + file delete ${test}.s + file delete ${test}.o + return $mix_linkonce_comdat_support_saved +} -- 2.28.0