diff options
author | Nick Clifton <nickc@redhat.com> | 2022-05-03 11:42:24 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2022-05-03 11:42:24 +0100 |
commit | ba951afb99912da01a6e8434126b8fac7aa75107 (patch) | |
tree | e94ddfba29d29a82ab36d28592d6c8e7edd04350 /ld/testsuite/ld-elf | |
parent | 46465574a925062ba7dfa72f49ba5199d7a39fc3 (diff) | |
download | fsf-binutils-gdb-ba951afb99912da01a6e8434126b8fac7aa75107.zip fsf-binutils-gdb-ba951afb99912da01a6e8434126b8fac7aa75107.tar.gz fsf-binutils-gdb-ba951afb99912da01a6e8434126b8fac7aa75107.tar.bz2 |
Add a linker warning when creating potentially dangerous executable segments. Add tests, options to disabke and configure switches to choose defaults.
Diffstat (limited to 'ld/testsuite/ld-elf')
-rw-r--r-- | ld/testsuite/ld-elf/changelma.d | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/elf.exp | 50 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/flags1.d | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/maxpage5.d | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/note-2.d | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/rwx-segments-1.l | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/rwx-segments-2.l | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/rwx-segments-2.t | 20 |
8 files changed, 67 insertions, 13 deletions
diff --git a/ld/testsuite/ld-elf/changelma.d b/ld/testsuite/ld-elf/changelma.d index 858a8db..567e72d 100644 --- a/ld/testsuite/ld-elf/changelma.d +++ b/ld/testsuite/ld-elf/changelma.d @@ -1,5 +1,5 @@ #name: changelma (pr20659) -#ld: -T changelma.lnk +#ld: -T changelma.lnk --no-warn-rwx-segments #objcopy_linked_file: --change-section-lma .dynamic+0x80000000 #readelf: -l --wide #xfail: rx-*-* diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp index d561540..1b30011 100644 --- a/ld/testsuite/ld-elf/elf.exp +++ b/ld/testsuite/ld-elf/elf.exp @@ -182,6 +182,7 @@ if { [check_gc_sections_available] && ![istarget "v850-*-*"] } { proc target_defaults_to_execstack {} { if { [istarget "aarch64*-*-*"] + || [istarget "*-*-nacl"] || [istarget "arc*-*-*"] || [istarget "ia64*-*-*"] || [istarget "loongarch*-*-*"] @@ -226,7 +227,18 @@ if { [istarget *-*-*linux*] "" \ {pr23900-1.s} \ [list [list "readelf" {-Wl} $pr23900_1_exp]] \ - "pr23900-1.exe"] \ + "pr23900-1.exe"] \ + ] + + # Test the linker's generation of execstack and executable segment warnings. + # Since these are normally pruned from the linker's output we temporarily + # disable tha action here. + rename prune_warnings_extra old_prune_warnings_extra + proc prune_warnings_extra { text } { + return $text + } + + run_ld_link_tests [list \ [list "PR ld/29072 (warn about an executable .note.GNU-stack)" \ "-e 0" \ "" \ @@ -248,23 +260,39 @@ if { [istarget *-*-*linux*] {pr29072-a.s} \ {} \ "pr29072-d.exe"] \ - ] + [list "Ensure that a warning issued when creating a segment with RWX permissions" \ + "-e 0 -Tnobits-1.t --warn-rwx-segments" \ + "" \ + "" \ + {nobits-1.s} \ + {{ld rwx-segments-1.l}} \ + "rwx-segments-1.exe"] \ + [list "Ensure that a warning issued when creating a TLS segment with execute permission" \ + "-e 0 -T rwx-segments-2.t --warn-rwx-segments" \ + "" \ + "" \ + {size-2.s} \ + {{ld rwx-segments-2.l}} \ + "rwx-segments-2.exe"] \ + [list "Ensure that the warning can be suppressed" \ + "-e 0 -Tnobits-1.t --no-warn-rwx-segments" \ + "" \ + "" \ + {nobits-1.s} \ + {} \ + "rwx-segments-3.exe"] \ + ] + if { [target_defaults_to_execstack] } { - rename prune_warnings_extra old_prune_warnings_extra - proc prune_warnings_extra { text } { - return $text - } run_ld_link_tests [list \ [list "PR ld/29072 (warn about absent .note.GNU-stack)" \ - "-e 0 -z stack-size=0x123400" \ + "-e 0 -z stack-size=0x123400 --warn-execstack" \ "" \ "" \ {pr29072-b.s} \ {{ld pr29072.b.warn}} \ "pr29072-b.exe"] \ ] - rename prune_warnings_extra "" - rename old_prune_warnings_extra prune_warnings_extra } else { run_ld_link_tests [list \ [list "PR ld/29072 (ignore absent .note.GNU-stack)" \ @@ -276,6 +304,10 @@ if { [istarget *-*-*linux*] "pr29072-b.exe"] \ ] } + + # Restore the normal pruning behaviour. + rename prune_warnings_extra "" + rename old_prune_warnings_extra prune_warnings_extra } if [check_gc_sections_available] { diff --git a/ld/testsuite/ld-elf/flags1.d b/ld/testsuite/ld-elf/flags1.d index 6cd8b3f..d9034e2 100644 --- a/ld/testsuite/ld-elf/flags1.d +++ b/ld/testsuite/ld-elf/flags1.d @@ -1,5 +1,5 @@ #name: --set-section-flags test 1 (sections) -#ld: -Tflags1.ld +#ld: -Tflags1.ld --no-warn-rwx-segments #objcopy_linked_file: --set-section-flags .post_text_reserve=contents,alloc,load,readonly,code #readelf: -S --wide diff --git a/ld/testsuite/ld-elf/maxpage5.d b/ld/testsuite/ld-elf/maxpage5.d index 9d9b57a..843a976 100644 --- a/ld/testsuite/ld-elf/maxpage5.d +++ b/ld/testsuite/ld-elf/maxpage5.d @@ -1,6 +1,6 @@ #source: maxpage5.s #as: --32 -#ld: -z max-page-size=0x200000 -T maxpage5.t +#ld: -z max-page-size=0x200000 -T maxpage5.t --no-warn-rwx-segments #objcopy_linked_file: -R .foo #readelf: -l --wide #target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu* diff --git a/ld/testsuite/ld-elf/note-2.d b/ld/testsuite/ld-elf/note-2.d index aff3240..ed81703 100644 --- a/ld/testsuite/ld-elf/note-2.d +++ b/ld/testsuite/ld-elf/note-2.d @@ -1,4 +1,4 @@ -#ld: -Tnote-2.t +#ld: -Tnote-2.t --no-warn-rwx-segments #objcopy_linked_file: -R .foo #readelf: -l --wide diff --git a/ld/testsuite/ld-elf/rwx-segments-1.l b/ld/testsuite/ld-elf/rwx-segments-1.l new file mode 100644 index 0000000..432fceb --- /dev/null +++ b/ld/testsuite/ld-elf/rwx-segments-1.l @@ -0,0 +1 @@ +.*warning: .* has a LOAD segment with RWX permissions diff --git a/ld/testsuite/ld-elf/rwx-segments-2.l b/ld/testsuite/ld-elf/rwx-segments-2.l new file mode 100644 index 0000000..b830de6 --- /dev/null +++ b/ld/testsuite/ld-elf/rwx-segments-2.l @@ -0,0 +1 @@ +.*: warning: .* has a TLS segment with execute permission diff --git a/ld/testsuite/ld-elf/rwx-segments-2.t b/ld/testsuite/ld-elf/rwx-segments-2.t new file mode 100644 index 0000000..f3aef1d --- /dev/null +++ b/ld/testsuite/ld-elf/rwx-segments-2.t @@ -0,0 +1,20 @@ +PHDRS +{ + header PT_PHDR PHDRS ; + + image PT_LOAD FLAGS (5) PHDRS; + tls PT_TLS FLAGS (7); + +} +SECTIONS +{ + .text 0x100 : { *(.text) } :image + .tdata : { *(.tdata) } :image :tls + .tbss : { *(.tbss) } :image : tls + .map : { + LONG (SIZEOF (.text)) + LONG (SIZEOF (.tdata)) + LONG (SIZEOF (.tbss)) + } :image + /DISCARD/ : { *(*) } +} |