]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - ld/testsuite/ld-elf/shared.exp
elf: Add GNU_PROPERTY_UINT32_AND_XXX/GNU_PROPERTY_UINT32_OR_XXX
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / shared.exp
index 742fe974c75d66d34a4bc59c1a51fe25692286a7..d00358e47ef595b9cdf6f87b2613f29fedbf3b99 100644 (file)
@@ -1,5 +1,5 @@
 # Expect script for various ELF tests.
-#   Copyright (C) 2006-2019 Free Software Foundation, Inc.
+#   Copyright (C) 2006-2021 Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
@@ -31,9 +31,6 @@ if ![check_shared_lib_support] {
     return
 }
 
-# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
-global NOPIE_CFLAGS NOPIE_LDFLAGS
-
 set old_ASFLAGS $ASFLAGS
 
 # This target requires extra GAS options when building code for shared
@@ -46,7 +43,7 @@ if [istarget "tic6x-*-*"] {
     append AFLAGS_PIC " -mpic -mpid=near"
 }
 if [istarget "sparc*-*-*"] {
-    append AFLAGS_PIC " -K PIC"
+    append AFLAGS_PIC " -K PIC -Av9"
 }
 
 # GAS options to disable program property note.
@@ -74,7 +71,7 @@ if { [istarget "mips*vr4100*-*-elf*"] \
 }
 
 if [is_underscore_target] {
-    set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
+    append ASFLAGS " --defsym UNDERSCORE=1"
 }
 
 run_ld_link_tests [list \
@@ -96,15 +93,6 @@ run_ld_link_tests [list \
        {} \
        "pr22471b.so" \
     ] \
-    [list \
-       "Build pr22471" \
-       "$LFLAGS -rpath-link ." \
-       "tmpdir/pr22471b.so" \
-       "" \
-       {pr22471b.s} \
-       {} \
-       "pr22471" \
-    ] \
     [list \
        "Build pr22649-1.so" \
        "$LFLAGS -shared" \
@@ -116,6 +104,18 @@ run_ld_link_tests [list \
     ] \
 ]
 
+run_ld_link_tests [list \
+    [list \
+       "Build pr22471" \
+       "$LFLAGS -rpath-link . -rpath-link tmpdir" \
+       "tmpdir/pr22471b.so" \
+       "" \
+       {pr22471b.s} \
+       {} \
+       "pr22471" \
+    ] \
+] bfin-*-* frv-*-* lm32-*-*
+
 if { [check_gc_sections_available] } {
     if [istarget mips*-*-*] {
        set actions {{ld pr22649-2ab-mips.msg}}
@@ -180,7 +180,7 @@ run_ld_link_tests [list \
          {readelf {-d --wide} textrel.rd}} \
        "textrel.so" \
     ] \
-] "xtensa-*-*"
+] bfin-*-* frv-*-* lm32-*-* xtensa-*-*
 
 # The MIPS backend sets SHF_WRITE, in `mips_elf_create_dynamic_relocation',
 # for any section that has a dynamic relocation attached and consequently
@@ -197,7 +197,7 @@ run_ld_link_tests [list \
         {{ld textrel.map}} \
        "textrel.so" \
     ] \
-] "cris*-*-*" "mips*-*-*"
+] bfin-*-* cris*-*-* frv-*-* lm32-*-* mips*-*-*
 
 # PR ld/20828 check for correct dynamic symbol table entries where:
 # - symbols have been defined with a linker script,
@@ -337,6 +337,38 @@ if { [check_gc_sections_available] } {
            "pr22150" \
        ] \
     ]
+
+    switch -glob $target_triplet {
+       # exclude targets that don't support copy relocs
+       bfin-*-* { }
+       frv-*-* { }
+       lm32-*-* { }
+       mips*-*-* { }
+       tic6x-*-* { }
+       xtensa-*-* { }
+       default {
+           run_ld_link_tests [list \
+               [list \
+                    "Build pr25458.so" \
+                    "$LFLAGS -shared --version-script=pr25458.map" \
+                    "" \
+                    "$AFLAGS_PIC" \
+                    {pr25458b.s} \
+                    {} \
+                    "pr25458.so" \
+               ] \
+               [list \
+                    "Build pr25458" \
+                    "$LFLAGS -e _start --gc-sections" \
+                    "tmpdir/pr25458.so" \
+                    "$AFLAGS_PIC" \
+                    {pr25458a.s} \
+                    {{readelf {--dyn-sym --wide} pr25458.rd}} \
+                    "pr25458" \
+               ] \
+           ]
+       }
+    }
 }
 
 set ASFLAGS $old_ASFLAGS
@@ -350,22 +382,24 @@ run_ld_link_tests [list \
 ]
 
 # bfin does not currently support copy relocs.
+setup_xfail bfin-*-*
+clear_xfail bfin-*-linux*
 run_ld_link_tests [list \
     [list "PR ld/14170" \
        "$LFLAGS --no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" \
        $hpux \
         {pr14170c.s} { } "pr14170" ] \
-] "bfin-*-*"
+]
 
 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
-# Not will hppa64 with dot-symbols.
+# Nor will hppa64 with dot-symbols.
 run_ld_link_tests [list \
     [list "PR ld/21703 shared" \
-       "-shared --allow-multiple-definition --version-script pr21703.ver\
+       "$LFLAGS -shared --allow-multiple-definition --version-script pr21703.ver\
         tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "$AFLAGS_PIC" \
        {pr21703-3.s pr21703-4.s} {{readelf {--dyn-syms} pr21703-shared.sd}} \
        "pr21703.so" ] \
-] "d30v-*-*" "dlx-*-*" "pj-*-*" "hppa64-*-*" "xgate-*-*"
+] \[is_generic\] hppa64-*-*
 
 # This target requires extra GAS options when building non-PIC code
 # for linking with shared libraries.
@@ -402,22 +436,26 @@ run_ld_link_tests [list \
 ]
 
 # bfin does not currently support copy relocs.
+setup_xfail bfin-*-*
+clear_xfail bfin-*-linux*
 run_ld_link_tests {
     {"pr17068 link --as-needed lib in group"
        "$LFLAGS --as-needed --no-dynamic-linker"
        "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a\
         --end-group" ""
        {start.s pr17068.s} {} "pr17068"}
-} "bfin-*-*"
+}
 
 # Fails on MIPS because ABI trickery means that a NULL reloc is emitted.
 # Fails on bfin because relocations are not created.
+setup_xfail mips*-*-* bfin-*-*
+clear_xfail bfin-*-linux*
 run_ld_link_tests [list \
     [list "-Bsymbolic-functions" \
        "-shared -Bsymbolic-functions" "" "$AFLAGS_PIC" \
        {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}} \
        "symbolic-func.so"] \
-] "mips*-*-*" "bfin-*-*"
+]
 
 run_ld_link_tests [list \
     [list "Build pr20995.so" \
@@ -425,55 +463,45 @@ run_ld_link_tests [list \
        {pr20995b.s} {} "pr20995.so"] \
 ]
 
-# xfail on arm*-*-eabi*.  The list can be enlarged to those targets that
-# don't support GNU_RELRO.  For more details, please see discussions at:
-#   https://sourceware.org/ml/binutils/2017-01/msg00441.html
-run_ld_link_tests [list \
-    [list "Build pr20995-2.so" \
-       "-shared -z relro" "" "$AFLAGS_PIC" \
-       {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \
-] "tic6x-*-*" "arm*-*-eabi*" "hppa*64*-*-hpux*" "aarch64*-*-elf*" \
-  "*-*-lynxos*" "*-*-nto*"
-
 # These targets don't copy dynamic variables into .bss.
 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
 # or don't have .data.rel.ro
-setup_xfail "hppa*64*-*-hpux*"
+setup_xfail "hppa*64*-*-hpux*" "tic6x-*-*"
+# or complain about relocs in read-only sections
+setup_xfail frv-*-* lm32-*-*
 run_ld_link_tests [list \
     [list \
        "pr20995" \
        "$LFLAGS" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
        {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
 
-# xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO.
-# Please see the link above for details.
-setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*"
-setup_xfail "hppa*64*-*-hpux*" "aarch64*-*-elf*"
+# xfail on targets that don't support GNU_RELRO.
+#   For more details, please see discussions at:
+#   https://sourceware.org/ml/binutils/2017-01/msg00441.html
+run_ld_link_tests [list \
+    [list "Build pr20995-2.so" \
+       "-shared -z relro" "" "$AFLAGS_PIC" \
+       {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \
+] {![check_relro_support]}
+
+setup_xfail alpha-*-* xtensa-*-*
 run_ld_link_tests [list \
     [list \
        "pr20995-2" \
        "$LFLAGS" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
        {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]
-] "*-*-lynxos*" "*-*-nto*"
+] {![check_relro_support]}
 
 run_ld_link_tests [list \
     [list "Build pr22374 shared library" \
        "-shared" "" "$AFLAGS_PIC" "pr22374b.s" {} "pr22374.so" ] \
 ]
-if { ![istarget "alpha-*-*"]
-     && ![istarget "csky-*-*"]
-     && ![istarget "frv-*-*"]
-     && ![istarget "hppa*-*-*"]
-     && ![istarget "i?86-*-*"]
-     && ![istarget "ia64-*-*"]
-     && ![istarget "microblaze-*-*"]
-     && ![istarget "powerpc*-*-*"]
-     && ![istarget "x86_64-*-*"]
-     && ![istarget "xtensa-*-*"] } {
-    # The next test checks that copy relocs are not used unnecessarily,
-    # but that is just an optimization so don't complain loudly.
-    setup_xfail "*-*-*"
-}
+
+# The next test checks that copy relocs are not used unnecessarily,
+# but that is just an optimization so don't complain loudly.
+setup_xfail *-*-*
+clear_xfail alpha-*-* bfin-*-linux* csky-*-* frv-*-* hppa*-*-* i?86-*-*
+clear_xfail ia64-*-* microblaze-*-* powerpc*-*-* x86_64-*-* xtensa-*-*
 run_ld_link_tests {
     {"pr22374 function pointer initialization"
        "" "tmpdir/pr22374.so" "" "pr22374a.s"
@@ -498,7 +526,7 @@ if { [istarget *-*-linux*]
 }
 
 # Check to see if the C compiler works
-if { [which $CC] == 0 } {
+if { ![check_compiler_available] } {
     return
 }
 
@@ -566,6 +594,34 @@ set build_tests {
   {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
    "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
    {dl2.c dl2xxx.c} {} "libdl2c.so"}
+  {"Build libdl2d.so with --dynamic-list-data -Bsymbolic"
+   "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2d.so"}
+  {"Build libdl2e.so with --export-dynamic-symbol=foo"
+   "-shared -Wl,--export-dynamic-symbol=foo" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2e.so"}
+  {"Build libdl2f.so with --dynamic-list=dlempty.list and --export-dynamic-symbol=foo"
+   "-shared -Wl,--dynamic-list=dlempty.list,--export-dynamic-symbol=foo" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2f.so"}
+  {"Build libdl2g.so with --export-dynamic-symbol-list=dl2.list"
+   "-shared -Wl,--export-dynamic-symbol-list=dl2.list" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2g.so"}
+  {"Build libdl2h.so with --dynamic-list=dlempty.list and --export-dynamic-symbol-list=dl2.list"
+   "-shared -Wl,--dynamic-list=dlempty.list,--export-dynamic-symbol-list=dl2.list" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2h.so"}
+  {"Build libdl2i.so with -Bsymbolic and --export-dynamic-symbol=foo"
+   "-shared -Wl,-Bsymbolic,--export-dynamic-symbol=foo" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2i.so"}
+  {"Build libdl2j.so with -Bsymbolic and --export-dynamic-symbol-list=dl2.list"
+   "-shared -Wl,-Bsymbolic,--export-dynamic-symbol-list=dl2.list" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2j.so"}
+  {"Build libdl2k.so with --export-dynamic-symbol-list=dl2.list and -Bsymbolic"
+   "-shared -Wl,--export-dynamic-symbol-list=dl2.list,-Bsymbolic" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2k.so"}
+  # Check that -Bno-symbolic cancels -Bsymbolic.
+  {"Build libdl2l.so with -Bsymbolic -Bno-symbolic and --export-dynamic-symbol=foo"
+   "-shared -Wl,-Bsymbolic,-Bno-symbolic,--export-dynamic-symbol=foo" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2l.so"}
   {"Build libdl4a.so with --dynamic-list=dl4.list"
    "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
    {dl4.c dl4xxx.c} {} "libdl4a.so"}
@@ -603,7 +659,7 @@ set build_tests {
    "-shared" "-fPIC"
    {data2.c} {} "libdata2.so"}
   {"Build libcomm1.o"
-   "-r -nostdlib" ""
+   "-r -nostdlib" "-fcommon"
    {comm1.c} {} "libcomm1.o"}
   {"Build libfunc1.so"
    "-shared" "-fPIC"
@@ -634,16 +690,16 @@ set build_tests {
    "-r -nostdlib" ""
    {pr11138-2.c} {} "libpr11138-2.o"}
   {"Build pr13250-1.so"
-   "-shared" "-fPIC"
+   "-shared" "-fPIC -fcommon"
    {pr13250-1.c} {} "libpr13250-1.so"}
   {"Build pr13250-2.so with libpr13250-1.so"
-   "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC"
+   "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC -fcommon"
    {pr13250-2.c} {} "libpr13250-2.so"}
   {"Build libpr13250-3.o"
-   "-r -nostdlib" ""
+   "-r -nostdlib" "-fcommon"
    {pr13250-3.c} {} "libpr13250-3.o"}
   {"Build libpr14323-2.so"
-   "-shared" "-fPIC"
+   "-shared" "-fPIC -fcommon"
    {pr14323-2.c} {} "libpr14323-2.so"}
   {"Build pr14862-1.o"
    "-r -nostdlib" ""
@@ -702,15 +758,6 @@ set build_tests {
   {"Build needed3"
    "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
    {dummy.c} {} "needed3"}
-  {"Build libpr2404a.so"
-   "-shared" "-fPIC"
-   {pr2404a.c} {} "libpr2404a.so"}
-  {"Build libpr2404n.so"
-   "-shared -Wl,-z,now" "-fPIC"
-   {pr2404a.c} {} "libpr2404n.so"}
-  {"Build libpr2404b.a"
-   "" ""
-   {pr2404b.c} {} "libpr2404b.a"}
   {"Build rdynamic-1"
    "-Wl,--no-dynamic-linker,-export-dynamic,--gc-sections" "-ffunction-sections"
    {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
@@ -745,6 +792,84 @@ set build_tests {
    "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC"
    {pr18458b.c} {} "libpr18458b.so"}
 }
+
+run_cc_link_tests [list \
+    [list \
+       "Build libpr2404a.so" \
+       "-shared $NOSANITIZE_CFLAGS" \
+       "-fPIC $NOSANITIZE_CFLAGS" \
+       {pr2404a.c} \
+       {} \
+       "libpr2404a.so" \
+    ] \
+    [list \
+       "Build libpr2404n.so" \
+       "-shared -Wl,-z,now $NOSANITIZE_CFLAGS" \
+       "-fPIC $NOSANITIZE_CFLAGS" \
+       {pr2404a.c} \
+       {} \
+       "libpr2404n.so" \
+    ] \
+    [list \
+       "Build libpr2404b.a" \
+       "" \
+       "$NOSANITIZE_CFLAGS" \
+       {pr2404b.c} \
+       {} \
+       "libpr2404b.a" \
+    ] \
+    [list \
+       "Build libpr26590a.so" \
+       "-shared" \
+       "-fPIC" \
+       {pr26590a.c} \
+       {} \
+       "libpr26590a.so" \
+    ] \
+    [list \
+       "Build libpr26590b.so (1)" \
+       "-shared" \
+       "-fPIC" \
+       {pr26590b.c} \
+       {} \
+       "libpr26590b.so" \
+    ] \
+    [list \
+       "Build pr26590c.o and pr26590d.o" \
+       "" \
+       "" \
+       {pr26590c.c pr26590d.c} \
+       {} \
+    ] \
+    [list \
+       "Build pr26590 (1)" \
+       "tmpdir/pr26590c.o tmpdir/pr26590d.o \
+        -Wl,--as-needed tmpdir/libpr26590a.so tmpdir/libpr26590b.so" \
+       "" \
+       {dummy.c} \
+       {{error_output pr26590.err}} \
+       "pr26590" \
+    ] \
+    [list \
+       "Build libpr26590b.so (2)" \
+       "-shared -Wl,--no-as-needed \
+        tmpdir/libpr26590a.so" \
+       "-fPIC" \
+       {pr26590b.c} \
+       {} \
+       "libpr26590b.so" \
+    ] \
+    [list \
+       "Build pr26590 (2)" \
+       "tmpdir/pr26590c.o tmpdir/pr26590d.o \
+        -Wl,--as-needed tmpdir/libpr26590a.so tmpdir/libpr26590b.so" \
+       "" \
+       {dummy.c} \
+       {} \
+       "pr26590" \
+    ] \
+]
+
 # pr19073.s uses .set, which has a different meaning on alpha.
 if { ![istarget alpha-*-*] } {
     append build_tests {
@@ -775,20 +900,61 @@ append build_tests {
   {"Dump pr21978.so"
    "-shared" "-fPIC -g -O2"
    {pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"}
+  {"libpr26580-2.so"
+   "-shared" "-fPIC -fcommon"
+   {pr26580-b.c} {} "libpr26580-2.so"}
 }
 
 run_cc_link_tests $build_tests
 
+run_cc_link_tests [list \
+    [list \
+       "Build pr26094-1.so" \
+       "-shared -Wl,--version-script=pr26094-1.ver" \
+       "-fPIC" \
+       {pr26094-1a.c} \
+       {{readelf {--dyn-syms --wide} pr26094-1a.rd}} \
+       "pr26094-1.so" \
+    ] \
+    [list \
+       "Build pr26094-1" \
+       "-Wl,--no-as-needed tmpdir/pr26094-1.so" \
+       "-fcommon" \
+       {pr26094-1b.c pr26094-1c.c} \
+       {{readelf {--dyn-syms --wide} pr26094-1b.rd}} \
+       "pr26094-1" \
+    ] \
+    [list \
+       "Build pr26302a.so" \
+       "-shared -Wl,--version-script=pr26302.ver" \
+       "-fPIC" \
+       {pr26302a.c} \
+       {} \
+       "pr26302a.so"
+    ] \
+    [list \
+       "Build pr26302b.so" \
+       "-shared -Wl,--no-as-needed tmpdir/pr26302a.so" \
+       "-fPIC" \
+       {pr26302b.c} \
+       {{readelf {-sW} pr26302.rd} \
+        {nm {-u} pr26302.nd} \
+        {nm {-u -D} pr26302.nd} \
+        {nm {-u -D --with-symbol-versions} pr26302.nd}} \
+       "pr26302b.so" \
+    ] \
+]
+
 run_ld_link_tests [list \
     [list \
-       "Build pr22269-1" \
-       "-pie -e _start --no-dynamic-linker -z text" \
+       "pr22269-1 (static pie undefined weak)" \
+       "-pie -e _start --no-dynamic-linker -z text -z nocombreloc " \
        "" \
        "$AFLAGS_PIC" \
        { pr22269-1.c } \
        {{readelf -rW pr22269-1.rd}} \
        "pr22269-1" \
-       "-fPIE -O2" \
+       "-fPIE -O2 $NOSANITIZE_CFLAGS" \
     ] \
 ]
 
@@ -842,24 +1008,51 @@ set run_tests [list \
     [list "Run with libdl2c.so" \
      "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
      {dl2main.c} "dl2c" "dl2b.out" ] \
+    [list "Run with libdl2d.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2d.so" "" \
+     {dl2main.c} "dl2d" "dl2a.out" ] \
+    [list "Run with libdl2e.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2e.so" "" \
+     {dl2main.c} "dl2e" "dl2b.out" ] \
+    [list "Run with libdl2f.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2f.so" "" \
+     {dl2main.c} "dl2f" "dl2a.out" ] \
+    [list "Run with libdl2g.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2g.so" "" \
+     {dl2main.c} "dl2g" "dl2b.out" ] \
+    [list "Run with libdl2h.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2h.so" "" \
+     {dl2main.c} "dl2h" "dl2a.out" ] \
+    [list "Run with libdl2i.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2i.so" "" \
+     {dl2main.c} "dl2i" "dl2a.out" ] \
+    [list "Run with libdl2j.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2j.so" "" \
+     {dl2main.c} "dl2j" "dl2a.out" ] \
+    [list "Run with libdl2k.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2k.so" "" \
+     {dl2main.c} "dl2k" "dl2a.out" ] \
+    [list "Run with libdl2l.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2l.so" "" \
+     {dl2main.c} "dl2l" "dl2b.out" ] \
     [list "Run with libdl4a.so" \
      "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
-     {dl4main.c} "dl4a" "dl4a.out" ] \
+     {dl4main.c} "dl4a" "dl4a.out" "-fPIC"] \
     [list "Run with libdl4b.so" \
      "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \
-     {dl4main.c} "dl4b" "dl4a.out" ] \
+     {dl4main.c} "dl4b" "dl4a.out" "-fPIC"] \
     [list "Run with libdl4c.so" \
      "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \
-     {dl4main.c} "dl4c" "dl4b.out" ] \
+     {dl4main.c} "dl4c" "dl4b.out" "-fPIC"] \
     [list "Run with libdl4d.so" \
      "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \
-     {dl4main.c} "dl4d" "dl4b.out" ] \
+     {dl4main.c} "dl4d" "dl4b.out" "-fPIC"] \
     [list "Run with libdl4e.so" \
      "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
-     {dl4main.c} "dl4e" "dl4a.out" ] \
+     {dl4main.c} "dl4e" "dl4a.out" "-fPIC"] \
     [list "Run with libdl4f.so" \
      "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
-     {dl4main.c} "dl4f" "dl4a.out" ] \
+     {dl4main.c} "dl4f" "dl4a.out" "-fPIC"] \
     [list "Run with libdata1.so" \
      "-Wl,--no-as-needed tmpdir/libdata1.so" "" \
      {dynbss1.c} "dynbss1" "pass.out" ] \
@@ -879,7 +1072,7 @@ set run_tests [list \
      "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \
      {dummy.c} "pr11138b" "pr11138.out" ] \
     [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \
-     "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "" \
+     "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "-fcommon" \
      {dummy.c} "pr13250" "pass.out" ] \
     [list "Run with pr14323-1.c pr14323-2.so" \
      "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \
@@ -897,11 +1090,16 @@ set run_tests [list \
      "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
      {relmain.c} "relmain" "relmain.out" ] \
     [list "Run pr2404" \
-     "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \
-     {dummy.c} "pr2404" "pr2404.out" ] \
+     "$NOSANITIZE_CFLAGS -Wl,--no-as-needed \
+      tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
+     "" \
+     {dummy.c} "pr2404" "pr2404.out" \
+     "$NOSANITIZE_CFLAGS" ] \
     [list "Run pr2404n" \
-     "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \
-     {dummy.c} "pr2404n" "pr2404.out" ] \
+     "$NOSANITIZE_CFLAGS -Wl,-z,now \
+      -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \
+     {dummy.c} "pr2404n" "pr2404.out" \
+     "$NOSANITIZE_CFLAGS" ] \
     [list "Run pr18458" \
      "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
      {pr18458c.c} "pr18458" "pass.out" ] \
@@ -911,6 +1109,18 @@ set run_tests [list \
     [list "Run pr21964-3" \
      "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so tmpdir/pr21964-3a.so" "" \
      {pr21964-3c.c} "pr21964-3" "pass.out" ] \
+    [list "pr26580-3" \
+     "" "" \
+     {pr26580-a.c} "pr26580-3" "pr26580-3.out" "-fcommon" "c" "" \
+     "-Wl,--as-needed tmpdir/libpr26580-2.so" ] \
+    [list "pr26580-4" \
+     "" "" \
+     {pr26580-a.c} "pr26580-4" "pr26580-4.out" "-fcommon" "c" "" \
+     "-Wl,--no-as-needed tmpdir/libpr26580-2.so" ] \
+    [list "Run pr26590 (2)" \
+     "" "" \
+     {pr26590c.c pr26590d.c} "pr26590" "pass.out" "" "c" "" \
+     "-Wl,--as-needed tmpdir/libpr26590a.so tmpdir/libpr26590b.so" ] \
 ]
 
 # NetBSD ELF systems do not currently support the .*_array sections.
@@ -956,7 +1166,7 @@ set dlopen_run_tests [list \
      {dl6cmain.c} "dl6c1" "dl6b.out" ] \
     [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
      "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
-     {dl6dmain.c} "dl6d1" "dl6b.out" ] \
+     {dl6dmain.c} "dl6d1" "dl6a.out" ] \
     [list "Run pr21964-2" \
      "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \
      {pr21964-2c.c} "pr21964-2" "pass.out" ] \
@@ -969,7 +1179,11 @@ set dlopen_run_tests [list \
 if [check_libdl_available] {
   # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
   # sections.
+  # Disable all sanitizers.
+  set old_CFLAGS "$CFLAGS"
+  append CFLAGS " $NOSANITIZE_CFLAGS"
   run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsdelf*"
+  set CFLAGS "$old_CFLAGS"
 }
 
 # Check --no-add-needed and --no-copy-dt-needed-entries
@@ -1017,14 +1231,29 @@ set build_cxx_tests {
   {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
    "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
    {dl3.cc} {} "libdl3c.so" "c++"}
-  {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
-   "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC -ansi"
-   {del.cc new.cc} {} "libnew1a.so" "c++"}
-  {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
-   "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC -ansi"
-   {del.cc new.cc} {} "libnew1b.so" "c++"}
 }
 
+run_cc_link_tests [list \
+    [list \
+       "Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new" \
+       "-shared $NOSANITIZE_CFLAGS -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" \
+       "-fPIC -ansi $NOSANITIZE_CFLAGS" \
+       {del.cc new.cc} \
+       {} \
+       "libnew1a.so" \
+       "c++" \
+    ] \
+    [list \
+       "Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new" \
+       "-shared $NOSANITIZE_CFLAGS -Wl,--dynamic-list-data,--dynamic-list-cpp-new" \
+       "-fPIC -ansi $NOSANITIZE_CFLAGS" \
+       {del.cc new.cc} \
+       {} \
+       "libnew1b.so" \
+       "c++" \
+    ] \
+]
+
 # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
 #    {"Run with libdl3b.so"
 #     "tmpdir/libdl3b.so" ""
@@ -1036,14 +1265,31 @@ set run_cxx_tests {
     {"Run with libdl3c.so"
      "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
      {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
-    {"Run with libnew1a.so"
-     "-Wl,--no-as-needed tmpdir/libnew1a.so" ""
-     {dl5.cc} "dl5a" "dl5.out" "-ansi" "c++"}
-    {"Run with libnew1b.so"
-     "-Wl,--no-as-needed tmpdir/libnew1b.so" ""
-     {dl5.cc} "dl5b" "dl5.out" "-ansi" "c++"}
 }
 
+run_ld_link_exec_tests [list \
+    [list \
+       "Run with libnew1a.so" \
+       "-Wl,--no-as-needed tmpdir/libnew1a.so $NOSANITIZE_CFLAGS" \
+       "" \
+       {dl5.cc} \
+       "dl5a" \
+       "dl5.out" \
+       "-ansi $NOSANITIZE_CFLAGS" \
+       "c++" \
+    ] \
+    [list \
+       "Run with libnew1b.so" \
+       "-Wl,--no-as-needed tmpdir/libnew1b.so $NOSANITIZE_CFLAGS" \
+       "" \
+       {dl5.cc} \
+       "dl5b" \
+       "dl5.out" \
+       "-ansi $NOSANITIZE_CFLAGS" \
+       "c++" \
+    ] \
+]
+
 run_cc_link_tests $build_cxx_tests
 run_ld_link_exec_tests $run_cxx_tests
 
@@ -1054,14 +1300,14 @@ if { [istarget *-*-linux*]
        [list \
            "Build libpr2404b.a with PIE" \
            "" \
-           "-fPIE" \
+           "-fPIE $NOSANITIZE_CFLAGS" \
            { pr2404b.c } \
            {} \
            "libpr2404b.a" \
        ] \
        [list \
            "Build pr19579a.o" \
-           "" "-fPIE" \
+           "" "-fPIE -fcommon" \
            {pr19579a.c} \
            {} \
            "libpr19579a.a" \
@@ -1069,7 +1315,7 @@ if { [istarget *-*-linux*]
        [list \
            "Build libpr19579.so" \
            "-shared" \
-           "-fPIC" \
+           "-fPIC -fcommon" \
            {pr19579b.c} \
            {} \
            "libpr19579.so" \
@@ -1077,7 +1323,7 @@ if { [istarget *-*-linux*]
        [list \
            "Build libpr19579now.so" \
            "-shared -Wl,-z,now" \
-           "-fPIC" \
+           "-fPIC -fcommon" \
            {pr19579b.c} \
            {} \
            "libpr19579.so" \
@@ -1140,21 +1386,21 @@ if { [istarget *-*-linux*]
        ] \
        [list \
            "Run pr2404 with PIE" \
-           "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
+           "-pie $NOSANITIZE_CFLAGS -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
            "" \
            { dummy.c } \
            "pr2404pie" \
            "pr2404.out" \
-           "-fPIE" \
+           "-fPIE $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Run pr2404 with PIE (-z now)" \
-           "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \
+           "-pie $NOSANITIZE_CFLAGS -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \
            "" \
            { dummy.c } \
            "pr2404pien" \
            "pr2404.out" \
-           "-fPIE" \
+           "-fPIE $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Run pr18718" \
@@ -1376,6 +1622,9 @@ if { [istarget "i?86-*-*"]
      || [istarget "x86_64-*-*"] } {
     set AFLAGS_PIE "-mrelax-relocations=yes"
 }
+if [istarget "sparc*-*-*"] {
+    set AFLAGS_PIE "-Av9"
+}
 
 if { ([istarget "*-*-linux*"]
       || [istarget "*-*-nacl*"]
@@ -1390,7 +1639,7 @@ if { ([istarget "*-*-linux*"]
            { pr23162a.c } \
            "" \
            "libpr23162a.so" \
-           "-fPIC -O2" \
+           "-fPIC -O2 $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Build pr23162a" \
@@ -1400,7 +1649,7 @@ if { ([istarget "*-*-linux*"]
            { pr23162b.c } \
            {{readelf {-rW} pr23162.rd}} \
            "pr23162a" \
-           "-fPIC -O0" \
+           "-fPIC -O0 $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Build libpr23162b.so" \
@@ -1410,7 +1659,7 @@ if { ([istarget "*-*-linux*"]
            { pr23162a.c } \
            "" \
            "libpr23162b.so" \
-           "-fPIC -O2" \
+           "-fPIC -O2 $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Build pr23162b" \
@@ -1420,7 +1669,7 @@ if { ([istarget "*-*-linux*"]
            { pr23162b.c } \
            {{readelf {-rW} pr23162.rd}} \
            "pr23162b" \
-           "-fPIC -O0" \
+           "-fPIC -O0 $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Build libpr23161a.so" \
@@ -1430,7 +1679,7 @@ if { ([istarget "*-*-linux*"]
            { pr23161a.c } \
            {{readelf {--dyn-syms -rW} pr23161a.rd}} \
            "libpr23161a.so" \
-           "-fPIC -O2" \
+           "-fPIC -O2 $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Build pr23161a" \
@@ -1440,7 +1689,7 @@ if { ([istarget "*-*-linux*"]
            { pr23161b.c } \
            {{readelf {--dyn-syms -rW} pr23161b.rd}} \
            "pr23161a" \
-           "-fPIC -O0" \
+           "-fPIC -O0 $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Build libpr23161b.so" \
@@ -1450,7 +1699,7 @@ if { ([istarget "*-*-linux*"]
            { pr23161a.c } \
            {{readelf {--dyn-syms -rW} pr23161a.rd}} \
            "libpr23161b.so" \
-           "-fPIC -O2" \
+           "-fPIC -O2 $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Build pr23161b" \
@@ -1460,7 +1709,7 @@ if { ([istarget "*-*-linux*"]
            { pr23161b.c } \
            {{readelf {--dyn-syms -rW} pr23161b.rd}} \
            "pr23161b" \
-           "-fPIC -O0" \
+           "-fPIC -O0 $NOSANITIZE_CFLAGS" \
        ] \
     ]
 }
@@ -1476,7 +1725,7 @@ if { [istarget "i?86-*-*"]
            { pr23161c.c } \
            {{readelf {--dyn-syms -rW} pr23161c.rd}} \
            "libpr23161c.so" \
-           "-fPIC -O2" \
+           "-fPIC -O2 $NOSANITIZE_CFLAGS" \
        ] \
        [list \
            "Build pr23161c" \
@@ -1486,7 +1735,7 @@ if { [istarget "i?86-*-*"]
            { pr23161b.c } \
            {{readelf {--dyn-syms -rW} pr23161d.rd}} \
            "pr23161c" \
-           "-fPIC -O0" \
+           "-fPIC -O0 $NOSANITIZE_CFLAGS" \
        ] \
     ]
 }