mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-19 01:19:41 +08:00
include * bfdlink.h (struct bfd_link_info): Update descriptions of the 'execstack', 'noexecstack' and 'warn_execstack' fields. Add 'error_exectack' and 'warn_is_error_for_rwx_segments' fields. bfd * elf.c (assign_file_positions_except_relocs): Turn warnings about executable segments into errors if so requested. * elflink.c (bfd_elf_size_dynamic_sections): Turn warnings about executable stacks into errors if so requested. ld * ldlex.h (enum option_values): Add OPTION_ERROR_EXECSTACK, OPTION_NO_ERROR_EXECSTACK, OPTION_WARN_EXECSTACK_OBJECTS, OPTION_ERROR_RWX_SEGMENTS and OPTION_NO_ERROR_RWX_SEGMENTS. (struct ld_option): Add new long options. (parse_args): Parse new long options. (elf_static_list_options): Display the new options. * ld.texi: Document the new command line options. * configure.ac (error-execstack): New configuration option. (error-rwx-segments): New configuration option. * emultempl/elf.em (_before_parse): Initialse the new linkinfo fields. * NEWS: Mention the new features. * config.in: Regenerate. * configure: Regenerate. * testsuite/ld-elf/commonpage2.d: Disable errors for RWX segments and/or executable stacks. * testsuite/ld-elf/elf.exp: Likewise. * testsuite/ld-elf/header.d: Likewise. * testsuite/ld-elf/loadaddr1.d: Likewise. * testsuite/ld-elf/loadaddr2.d: Likewise. * testsuite/ld-elf/maxpage4.d: Likewise. * testsuite/ld-elf/nobits-1.d: Likewise. * testsuite/ld-elf/note-1.d: Likewise. * testsuite/ld-elf/orphan-10.d: Likewise. * testsuite/ld-elf/orphan-11.d: Likewise. * testsuite/ld-elf/orphan-12.d: Likewise. * testsuite/ld-elf/orphan-5.d: Likewise. * testsuite/ld-elf/orphan-7.d: Likewise. * testsuite/ld-elf/orphan-8.d: Likewise. * testsuite/ld-elf/orphan-9.d: Likewise. * testsuite/ld-elf/orphan-region.d: Likewise. * testsuite/ld-elf/orphan.d: Likewise. * testsuite/ld-elf/pr19539.d: Likewise. * testsuite/ld-elf/pr26256-1a.d: Likewise. * testsuite/ld-elf/pr26907.d: Likewise. * testsuite/ld-elf/pr28597.d: Likewise. * testsuite/ld-elf/retain2.d: Likewise. * testsuite/ld-elf/shared.exp: Likewise. * testsuite/ld-elf/size-1.d: Likewise. * testsuite/ld-elf/textaddr7.d: Likewise. * testsuite/ld-elf/warn1.d: Likewise. * testsuite/ld-elf/warn2.d: Likewise. * testsuite/ld-i386/discarded1.d: Likewise. * testsuite/ld-i386/pr19175.d: Likewise. * testsuite/ld-i386/pr19539.d: Likewise. * testsuite/ld-i386/pr23189.d: Likewise. * testsuite/ld-plugin/lto-3r.d: Likewise. * testsuite/ld-plugin/lto-5r.d: Likewise. * testsuite/ld-plugin/lto.exp: Likewise. * testsuite/ld-powerpc/ppc476-shared.d: Likewise. * testsuite/ld-powerpc/ppc476-shared2.d: Likewise. * testsuite/ld-powerpc/pr28827-2.d: Likewise. * testsuite/ld-s390/s390.exp: Likewise. * testsuite/ld-scripts/align2a.d: Likewise. * testsuite/ld-scripts/align2b.d: Likewise. * testsuite/ld-scripts/align5.d: Likewise. * testsuite/ld-scripts/alignof.exp: Likewise. * testsuite/ld-scripts/crossref.exp: Likewise. * testsuite/ld-scripts/defined2.d: Likewise. * testsuite/ld-scripts/defined3.d: Likewise. * testsuite/ld-scripts/defined5.d: Likewise. * testsuite/ld-scripts/pr14962.d: Likewise. * testsuite/ld-scripts/pr18963.d: Likewise. * testsuite/ld-scripts/pr20302.d: Likewise. * testsuite/ld-scripts/print-memory-usage.exp: Likewise. * testsuite/ld-scripts/rgn-at1.d: Likewise. * testsuite/ld-scripts/rgn-at10.d: Likewise. * testsuite/ld-scripts/rgn-at4.d: Likewise. * testsuite/ld-scripts/rgn-at6.d: Likewise. * testsuite/ld-scripts/rgn-at8.d: Likewise. * testsuite/ld-scripts/rgn-at9.d: Likewise. * testsuite/ld-scripts/rgn-over1.d: Likewise. * testsuite/ld-scripts/rgn-over2.d: Likewise. * testsuite/ld-scripts/rgn-over4.d: Likewise. * testsuite/ld-scripts/rgn-over5.d: Likewise. * testsuite/ld-scripts/rgn-over6.d: Likewise. * testsuite/ld-scripts/script.exp: Likewise. * testsuite/ld-scripts/sizeof.exp: Likewise. * testsuite/ld-scripts/sort-file.d: Likewise. * testsuite/ld-x86-64/discarded1.d: Likewise. * testsuite/ld-x86-64/pr19175.d: Likewise. * testsuite/ld-x86-64/pr19539a.d: Likewise. * testsuite/ld-x86-64/pr19539b.d: Likewise. * testsuite/ld-x86-64/pr23189.d: Likewise.
208 lines
6.5 KiB
Plaintext
208 lines
6.5 KiB
Plaintext
# Test NOCROSSREFS in a linker script.
|
|
# By Ian Lance Taylor, Cygnus Support.
|
|
# Copyright (C) 2000-2023 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.
|
|
|
|
set test1 "NOCROSSREFS 1"
|
|
set test2 "NOCROSSREFS 2"
|
|
set test3 "NOCROSSREFS 3"
|
|
set test4 "NOCROSSREFS_TO 1"
|
|
set test5 "NOCROSSREFS_TO 2"
|
|
set test6 "NOCROSSREFS_TO 3"
|
|
set test7 "NOCROSSREFS_TO 4"
|
|
|
|
if { ![check_compiler_available] } {
|
|
untested $test1
|
|
untested $test2
|
|
untested $test3
|
|
untested $test4
|
|
untested $test5
|
|
untested $test6
|
|
untested $test7
|
|
return
|
|
}
|
|
|
|
# Pass -fplt to CC since -fno-plt doesn't work with NOCROSSREFS tests.
|
|
# Also add $NOPIE_CFLAGS since PIE doesn't work NOCROSSREFS tests.
|
|
set old_CFLAGS "$CFLAGS_FOR_TARGET"
|
|
append CFLAGS_FOR_TARGET " $PLT_CFLAGS $NOPIE_CFLAGS"
|
|
|
|
# Xtensa targets currently default to putting literal values in a separate
|
|
# section and that requires linker script support, so put literals in text.
|
|
if [istarget xtensa*-*-*] {
|
|
append CFLAGS_FOR_TARGET " -mtext-section-literals"
|
|
}
|
|
|
|
# Prevent the use of the MeP's small data area which references a symbol
|
|
# called __sdabase which will not be defined by our test linker scripts.
|
|
if [istarget mep*-*-elf] {
|
|
append CFLAGS_FOR_TARGET " -mtiny=0"
|
|
}
|
|
|
|
# The .dsbt section and __c6xabi_DSBT_BASE are not defined in our test
|
|
# linker scripts.
|
|
if [istarget tic6x*-*-*] {
|
|
append CFLAGS_FOR_TARGET " -mno-dsbt -msdata=none"
|
|
}
|
|
|
|
if { ![ld_compile "$CC_FOR_TARGET $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \
|
|
|| ![ld_compile "$CC_FOR_TARGET $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } {
|
|
unsupported $test1
|
|
unsupported $test2
|
|
set CFLAGS_FOR_TARGET "$old_CFLAGS"
|
|
return
|
|
}
|
|
|
|
set flags [big_or_little_endian]
|
|
|
|
# arc-elf32 requires the symbol __SDATA_BEGIN__ to always be present.
|
|
if [istarget arc*-*-elf32] {
|
|
append flags " --defsym __SDATA_BEGIN__=0"
|
|
}
|
|
|
|
if [is_pecoff_format] {
|
|
append flags " --image-base 0"
|
|
}
|
|
|
|
set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o --no-error-rwx-segments"]
|
|
|
|
set exec_output [prune_warnings $exec_output]
|
|
|
|
regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
|
|
|
if [string match "" $exec_output] then {
|
|
fail $test1
|
|
} else {
|
|
verbose -log "$exec_output"
|
|
if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
|
|
pass $test1
|
|
} else {
|
|
fail $test1
|
|
}
|
|
}
|
|
|
|
# Check cross references within a single object.
|
|
|
|
if { ![ld_compile "$CC_FOR_TARGET $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
|
|
unsupported $test2
|
|
set CFLAGS_FOR_TARGET "$old_CFLAGS"
|
|
return
|
|
}
|
|
|
|
set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o --no-error-rwx-segments"]
|
|
set exec_output [prune_warnings $exec_output]
|
|
|
|
regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
|
|
|
if [string match "" $exec_output] then {
|
|
fail $test2
|
|
} else {
|
|
verbose -log "$exec_output"
|
|
if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
|
|
pass $test2
|
|
} else {
|
|
fail $test2
|
|
}
|
|
}
|
|
|
|
# Check cross references for ld -r
|
|
|
|
if { ![ld_compile "$CC_FOR_TARGET $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
|
|
unsupported $test3
|
|
set CFLAGS_FOR_TARGET "$old_CFLAGS"
|
|
return
|
|
}
|
|
|
|
if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
|
|
fail $test3
|
|
set CFLAGS_FOR_TARGET "$old_CFLAGS"
|
|
return
|
|
}
|
|
|
|
set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o --no-error-rwx-segments"]
|
|
|
|
set exec_output [prune_warnings $exec_output]
|
|
|
|
regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
|
|
|
if [string match "" $exec_output] then {
|
|
pass $test3
|
|
} else {
|
|
verbose -log "$exec_output"
|
|
fail $test3
|
|
}
|
|
|
|
set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross4 -T $srcdir/$subdir/cross4.t tmpdir/cross4.o --no-error-rwx-segments"]
|
|
set exec_output [prune_warnings $exec_output]
|
|
|
|
regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
|
|
|
if [string match "" $exec_output] then {
|
|
pass $test4
|
|
} else {
|
|
verbose -log "$exec_output"
|
|
fail $test4
|
|
}
|
|
|
|
set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross5 -T $srcdir/$subdir/cross5.t tmpdir/cross4.o --no-error-rwx-segments"]
|
|
set exec_output [prune_warnings $exec_output]
|
|
|
|
regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
|
|
|
if [string match "" $exec_output] then {
|
|
fail $test5
|
|
} else {
|
|
verbose -log "$exec_output"
|
|
if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
|
|
pass $test5
|
|
} else {
|
|
fail $test5
|
|
}
|
|
}
|
|
|
|
set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross6 -T $srcdir/$subdir/cross6.t tmpdir/cross3.o --no-error-rwx-segments"]
|
|
set exec_output [prune_warnings $exec_output]
|
|
|
|
regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
|
|
|
if [string match "" $exec_output] then {
|
|
pass $test6
|
|
} else {
|
|
verbose -log "$exec_output"
|
|
fail $test6
|
|
}
|
|
|
|
set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross7 -T $srcdir/$subdir/cross7.t tmpdir/cross3.o --no-error-rwx-segments"]
|
|
set exec_output [prune_warnings $exec_output]
|
|
|
|
regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
|
|
|
if [string match "" $exec_output] then {
|
|
fail $test7
|
|
} else {
|
|
verbose -log "$exec_output"
|
|
if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
|
|
pass $test7
|
|
} else {
|
|
fail $test7
|
|
}
|
|
}
|
|
|
|
set CFLAGS_FOR_TARGET "$old_CFLAGS"
|