From patchwork Fri Nov 21 18:09:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 3839 Received: (qmail 25356 invoked by alias); 21 Nov 2014 18:09:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 25345 invoked by uid 89); 21 Nov 2014 18:09:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: e06smtp17.uk.ibm.com Received: from e06smtp17.uk.ibm.com (HELO e06smtp17.uk.ibm.com) (195.75.94.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 21 Nov 2014 18:09:30 +0000 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 21 Nov 2014 18:09:26 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 21 Nov 2014 18:09:23 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id DC5D417D8043 for ; Fri, 21 Nov 2014 18:09:36 +0000 (GMT) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sALI9Ni214483730 for ; Fri, 21 Nov 2014 18:09:23 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sALI9M2e003590 for ; Fri, 21 Nov 2014 11:09:22 -0700 Received: from br87z6lw.de.ibm.com (dyn-9-152-212-196.boeblingen.de.ibm.com [9.152.212.196]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id sALI9M1A003570 for ; Fri, 21 Nov 2014 11:09:22 -0700 From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH] execl-update-breakpoints.exp: Move whole segment instead of .text section Date: Fri, 21 Nov 2014 19:09:22 +0100 Message-ID: <87lhn4qvcd.fsf@br87z6lw.de.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14112118-0029-0000-0000-000001C8A286 X-IsSubscribed: yes 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. --- .../gdb.base/execl-update-breakpoints.exp | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) 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 }