]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - ld/testsuite/ld-elf/elf.exp
For test for PR 29072 when the linker is configured with --enable-default-execstack=no.
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
index 10c635e95932af82cc00464b0301db77c3475d62..ca345e865c220f209f0e45a37da9862a41220157 100644 (file)
@@ -1,5 +1,5 @@
 # Expect script for various ELF tests.
-#   Copyright (C) 2002-2022 Free Software Foundation, Inc.
+#   Copyright (C) 2002-2023 Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
@@ -180,12 +180,29 @@ if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
 }
 
 proc target_defaults_to_execstack {} {
+    global base_dir
+
+    # If the linker has been configured with --enable-default-execstack=no then
+    # this proc should always return 0.
+    if { [file exists $base_dir/config.status] } {
+       set status [remote_exec host grep "enable-default-execstack=no" $base_dir/config.status]
+       if { [lindex $status 0] == 0 } {
+           return 0
+       } else {
+           verbose -log "$base_dir/config.status does not contain enable-default-execstack=no"
+       }
+    } else {
+       verbose -log "there is no file $base_dir/config.status"
+    }
+    
     if {   [istarget "aarch64*-*-*"]
        || [istarget "arc*-*-*"]
        || [istarget "cris*-*-*"]
        || [istarget "ia64*-*-*"]
+       || [istarget "loongarch*-*-*"]
        || [istarget "nios2*-*-*"]
        || [istarget "powerpc64*-*-*"]
+       || [istarget "pru*-*-*"]
        || [istarget "riscv*-*-*"]
        || [istarget "tilegx*-*-*"]
        || [istarget "tilepro*-*-*"] } {
@@ -236,18 +253,17 @@ if {   [istarget *-*-*linux*]
        return $text
     }
 
-    # The HPPA target disables the warnings by default since it needs an
-    # executable stack to support older kernels and an RWX segment to
-    # support its PLT.  MIPS also turns off exec stack warnings.
-    if { [istarget "hppa*-*-*"] || [istarget mips*-*-*] } {
-        set extra_link_opts "--warn-execstack --warn-rwx-segments"
-    } else {
-        set extra_link_opts ""
+    set curr_ldflags $LDFLAGS
+    if { [istarget powerpc*-*-*] && ![istarget powerpc64*-*-*] } {
+       # Don't generate an executable .plt section
+       set LDFLAGS "$LDFLAGS --secure-plt"
     }
 
+    # Since the warnings can be disabled by configure, ensure consistency
+    # of the first test by forcing the flags.
     run_ld_link_tests [list \
        [list "PR ld/29072 (warn about an executable .note.GNU-stack)" \
-           "-e 0 $extra_link_opts" \
+           "-e 0 --warn-execstack --warn-rwx-segments" \
            "" \
            "" \
            {pr29072-a.s} \
@@ -290,6 +306,8 @@ if {   [istarget *-*-*linux*]
            "rwx-segments-3.exe"] \
          ]
 
+    set LDFLAGS $curr_ldflags
+
     if { [target_defaults_to_execstack] } {
        run_ld_link_tests [list \
           [list "PR ld/29072 (warn about absent .note.GNU-stack)" \
@@ -521,31 +539,24 @@ run_cc_link_tests [list \
        {{nm "" pr26391.nd}} \
        "pr26391-4" \
     ] \
-]
-
-run_ld_link_tests [list \
     [list \
        "Build pr26391-5.o" \
-       "-z unique-symbol -r" \
-       "" \
-       "" \
+       "-Wl,-z,unique-symbol -r -nostdlib -nostartfiles" \
+       "-fno-function-sections" \
        {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
        [list \
            [list "nm" "$dep_plug_opt" "pr26391.nd"] \
            [list "nm" "$dep_plug_opt" "pr26391.fd"] \
        ] \
        "pr26391-5.o" \
-       "-fno-function-sections" \
     ] \
     [list \
        "Build pr26391-6.o" \
-       "-z unique-symbol -r" \
-       "" \
-       "" \
+       "-Wl,-z,unique-symbol -r -nostdlib -nostartfiles" \
+       "-ffunction-sections" \
        {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
        {{nm "" pr26391.nd}} \
        "pr26391-6.o" \
-       "-ffunction-sections" \
     ] \
 ]
 
@@ -612,4 +623,10 @@ run_ld_link_exec_tests [list \
     ] \
 ]
 
+set merge_exec_tests {
+    {"merge4" "" ""
+       {merge4a.c merge4b.s} "merge4" "merge4.out"}
+}
+run_ld_link_exec_tests $merge_exec_tests
+
 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status