diff options
author | Andreas Arnez <arnez@linux.vnet.ibm.com> | 2014-12-02 16:35:47 +0100 |
---|---|---|
committer | Andreas Krebbel <krebbel@linux.vnet.ibm.com> | 2014-12-02 16:35:47 +0100 |
commit | fdb09caf2386b09272df3cac6ec65be724ace3b9 (patch) | |
tree | e98ceea7fd335ceb1fdaaeb93e740d9a874df150 | |
parent | 538baf8b7e6d17a490f126f8565638469da70204 (diff) | |
download | gdb-fdb09caf2386b09272df3cac6ec65be724ace3b9.zip gdb-fdb09caf2386b09272df3cac6ec65be724ace3b9.tar.gz gdb-fdb09caf2386b09272df3cac6ec65be724ace3b9.tar.bz2 |
execl-update-breakpoints.exp: Move whole segment instead of .text section
The test case builds two copies of the program, one with the compile
option "ldflags=-Wl,-Ttext=0x1000000" and the other with the address
changed to 0x2000000. However, when linking with ld.bfd, the
resulting executables crash early in ld.so on S390 and i386.
Analysis of the crash: The default linker script establishes a certain
order of loadable sections, and the option "-Ttext" effectively splits
these into an "unaffected" lot (everything before .text) and an
"affected" lot. The affected lot is placed at the given address,
whereas the unaffected lot stays at its default address. The
unaffected lot starts at an aligned address plus Elf header sizes,
which is good if it is the first LOAD segment (like on AMD64). But if
the affected lot comes first instead (like on S390 and i386), the PHDR
doesn't fit there and is placed *outside* any LOAD segments. Then the
PHDR is not mapped when the loader gets control, and the loader runs
into a segmentation fault while trying to access it.
Since we are lucky about the order of segments on AMD64, the test
succeeds there, but the resulting binaries are unusually large -- 2.1M
each, with lots of padding within.
When replacing '-Ttext' by '-Ttext-segment', the linker moves all
segments consistently, the binaries have normal sizes, and the test
case succeeds on all mentioned platforms.
Since old versions of the gold linker don't support '-Ttext-segment',
the patch also adds logic for falling back to '-Ttext'.
gdb/testsuite/ChangeLog:
* gdb.base/execl-update-breakpoints.exp: Specify the link address
with '-Ttext-segment' instead of '-Ttext'. Fall back to '-Ttext'
if the linker doesn't understand this.
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/execl-update-breakpoints.exp | 30 |
2 files changed, 28 insertions, 8 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 6d214ee..db5127c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-12-02 Andreas Arnez <arnez@linux.vnet.ibm.com> + + * gdb.base/execl-update-breakpoints.exp: Specify the link address + with '-Ttext-segment' instead of '-Ttext'. Fall back to '-Ttext' + if the linker doesn't understand this. + 2014-12-01 Simon Marchi <simon.marchi@ericsson.com> * gdb.python/python.exp: Change expected reply to help(). diff --git a/gdb/testsuite/gdb.base/execl-update-breakpoints.exp b/gdb/testsuite/gdb.base/execl-update-breakpoints.exp index eb1024b..2d9e550 100644 --- a/gdb/testsuite/gdb.base/execl-update-breakpoints.exp +++ b/gdb/testsuite/gdb.base/execl-update-breakpoints.exp @@ -28,17 +28,31 @@ standard_testfile # The address of "main" in the first binary should end up being an # unmapped address in the second binary. -set exec1 ${testfile}1 -set exec2 ${testfile}2 -set binfile1 ${binfile}1 -set binfile2 ${binfile}2 +set objfile ${binfile}.o +set exec1 ${binfile}1 +set exec2 ${binfile}2 -if { [prepare_for_testing "failed to prepare" ${exec1} "${srcfile}" \ - [list debug ldflags=-Wl,-Ttext=0x1000000]] } { +if { [gdb_compile [file join $srcdir $subdir $srcfile] $objfile \ + object [list debug]] != "" } { + untested "compile failed" return -1 } -if { [prepare_for_testing "failed to prepare" ${exec2} "${srcfile}" \ - [list debug ldflags=-Wl,-Ttext=0x2000000]] } { + +set opts1_ld [list debug ldflags=-Wl,-Ttext-segment=0x1000000] +set opts1_gold [list debug ldflags=-Wl,-Ttext=0x1000000] +set opts2_ld [list debug ldflags=-Wl,-Ttext-segment=0x2000000] +set opts2_gold [list debug ldflags=-Wl,-Ttext=0x2000000] + +if { [gdb_compile $objfile $exec1 executable $opts1_ld] != "" } { + # Old gold linker versions don't support -Ttext-segment. Fall + # back to -Ttext. + if { [gdb_compile $objfile $exec1 executable $opts1_gold] != "" + || [gdb_compile $objfile $exec2 executable $opts2_gold] != ""} { + untested "link failed" + return -1 + } +} elseif { [gdb_compile $objfile $exec2 executable $opts2_ld] != "" } { + untested "link failed" return -1 } |