Skip to content

Commit 968aa7a

Browse files
committed
Testsuite: Ensure pie is disabled on some tests
Recent versions of Ubuntu and Debian default GCC to enable pie. In dump.exp, pie will causes addresses to be out of range for IHEX. In break-interp.exp, pie is explicitly set for some tests and assumed to be disabled for the remainder. Ensure pie is disabled for these tests when required. In addition, add a pie option to gdb_compile to match the nopie option and simplify use. gdb/testsuite/ChangeLog: * README: Add pie options. * gdb.base/break-interp.exp: Ensure pie is disabled. * gdb.base/dump.exp: Likewise. * lib/gdb.exp (gdb_compile): Add pie option.
1 parent d8a95af commit 968aa7a

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

gdb/testsuite/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2019-03-22 Alan Hayward <alan.hayward@arm.com>
2+
3+
* README: Add pie options.
4+
* gdb.base/break-interp.exp: Ensure pie is disabled.
5+
* gdb.base/dump.exp: Likewise.
6+
* lib/gdb.exp (gdb_compile): Add pie option.
7+
18
2019-03-19 Tom Tromey <tromey@adacore.com>
29

310
* gdb.mi/mi2-cli-display.c: New file.

gdb/testsuite/README

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,16 @@ gdb,no_thread_names
482482

483483
The target doesn't support thread names.
484484

485+
gdb,pie_flag
486+
487+
The flag required to force the compiler to produce position-independent
488+
executables.
489+
490+
gdb,pie_ldflag
491+
492+
The flag required to force the linker to produce position-independent
493+
executables.
494+
485495
gdb,nopie_flag
486496

487497
The flag required to force the compiler to produce non-position-independent

gdb/testsuite/gdb.base/break-interp.exp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,10 @@ foreach ldprelink {NO YES} {
625625
lappend opts {debug}
626626
}
627627
if {$binpie != "NO"} {
628-
lappend opts {additional_flags=-fPIE}
629-
lappend opts {ldflags=-pie}
628+
lappend opts {pie}
629+
} else {
630+
# Debian9/Ubuntu16.10 onwards default to PIE enabled. Ensure it is disabled.
631+
lappend opts {nopie}
630632
}
631633

632634
set dir ${exec}.d

gdb/testsuite/gdb.base/dump.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ if {[istarget "spu*-*-*"]} then {
3636
set is64bitonly "yes"
3737
}
3838

39+
# Debian9/Ubuntu16.10 onwards default to PIE enabled. Ensure it is disabled as
40+
# this causes addresses to be out of range for IHEX.
41+
lappend options {nopie}
42+
3943
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
4044
untested "failed to compile"
4145
return -1

gdb/testsuite/lib/gdb.exp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3461,6 +3461,7 @@ set gdb_saved_set_unbuffered_mode_obj ""
34613461
# dynamically load libraries at runtime. For example, on Linux, this adds
34623462
# -ldl so that the test can use dlopen.
34633463
# - nowarnings: Inhibit all compiler warnings.
3464+
# - pie: Force creation of PIE executables.
34643465
# - nopie: Prevent creation of PIE executables.
34653466
#
34663467
# And here are some of the not too obscure options understood by DejaGnu that
@@ -3599,8 +3600,33 @@ proc gdb_compile {source dest type options} {
35993600
set options [lreplace $options $nowarnings $nowarnings $flag]
36003601
}
36013602

3602-
# Replace the "nopie" option with the appropriate additional_flags
3603-
# to disable PIE executables.
3603+
# Replace the "pie" option with the appropriate compiler and linker flags
3604+
# to enable PIE executables.
3605+
set pie [lsearch -exact $options pie]
3606+
if {$pie != -1} {
3607+
if [target_info exists gdb,pie_flag] {
3608+
set flag "additional_flags=[target_info gdb,pie_flag]"
3609+
} else {
3610+
# For safety, use fPIE rather than fpie. On AArch64, m68k, PowerPC
3611+
# and SPARC, fpie can cause compile errors due to the GOT exceeding
3612+
# a maximum size. On other architectures the two flags are
3613+
# identical (see the GCC manual). Note Debian9 and Ubuntu16.10
3614+
# onwards default GCC to using fPIE. If you do require fpie, then
3615+
# it can be set using the pie_flag.
3616+
set flag "additional_flags=-fPIE"
3617+
}
3618+
set options [lreplace $options $pie $pie $flag]
3619+
3620+
if [target_info exists gdb,pie_ldflag] {
3621+
set flag "ldflags=[target_info gdb,pie_ldflag]"
3622+
} else {
3623+
set flag "ldflags=-pie"
3624+
}
3625+
lappend options "$flag"
3626+
}
3627+
3628+
# Replace the "nopie" option with the appropriate linker flag to disable
3629+
# PIE executables. There are no compiler flags for this option.
36043630
set nopie [lsearch -exact $options nopie]
36053631
if {$nopie != -1} {
36063632
if [target_info exists gdb,nopie_flag] {

0 commit comments

Comments
 (0)