From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9229 invoked by alias); 25 Oct 2013 23:26:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 9219 invoked by uid 89); 25 Oct 2013 23:26:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-vb0-f73.google.com Received: from mail-vb0-f73.google.com (HELO mail-vb0-f73.google.com) (209.85.212.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 25 Oct 2013 23:26:26 +0000 Received: by mail-vb0-f73.google.com with SMTP id w5so228295vbf.2 for ; Fri, 25 Oct 2013 16:26:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:cc:date:message-id:mime-version :content-type; bh=Tz4B5NkEClkrRjBE/djSoVyIqredJo6dgBK6RsjPBPk=; b=UsaSVrit0p0emUwnOVWs2sOOsBJ2GtalWNGjrHHMoYn97kHwBaIcr4z6A6FixGEveX T+xeQuXt/KdloHUwYFSLUrb2Bz3ScQSjYdBZejo3OhLPbJ7NznY+nN7ukUPu6ssyhqRt IRWnQ9VUiSwELV2dWoaKHrmpJ+cf8AavI9U7nN4KMT12HoudSm1A3/2KECowoVCCTPNp xJ4PhdjB2L3KOtakEL1PChq4Gx4koKfJ3olUlRijXYOejOSOB5iWHMY4fEizNh1E8uP+ 2algVy6XhrEB1BnQkK/Cplc4Gt1LAIOECoTjbcQyyr0uLbYACut5dGtXw/I/lwicJfNo Tt3w== X-Gm-Message-State: ALoCoQmEyj4m2pxnxMzhIxHqXkpDsWrWWOvLuW1V76aVxPc3QS34LwVKz/88MOUWvrokn2IraQOnH1NggFoixscM7b6XIAFRv97PjLPWJxim9SvfXQ9sr5IVAEciUq+vKOvaJw5pO6YHgboskeulagbtSjVLOI4XAyNc+YrLODb0HdFQFucApA/+4gtCoXMas7BU5uCUxJzCBOD2jd23qf/ew3ZXg85eZw== X-Received: by 10.58.128.67 with SMTP id nm3mr3890700veb.38.1382743584180; Fri, 25 Oct 2013 16:26:24 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id a24si518959yhl.1.2013.10.25.16.26.24 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Oct 2013 16:26:24 -0700 (PDT) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.44]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 7921931C15D; Fri, 25 Oct 2013 16:26:23 -0700 (PDT) From: Doug Evans To: gdb-patches@sourceware.org, jan.kratochvil@redhat.com Subject: [PATCH] Fix Gold/strip discrepancies for PR 11786 cc: ccoutant@google.com Date: Fri, 25 Oct 2013 23:26:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00834.txt.bz2 Hi. This patch addresses the discrepancy in the flags and align fields of PT_GNU_RELRO between Gold and strip. Ref: https://sourceware.org/bugzilla/show_bug.cgi?id=11786 Ok to check in? 2013-10-25 Doug Evans PR 11786 * solib-svr4.c (svr4_exec_displacement): Ignore flags and align fields for PT_GNU_RELRO segments. testsuite/ * gdb.base/gcore-relro-pie.c: New file. * gdb.base/gcore-relro-pie.exp: New file. diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index ddbbd94..d3b55e5 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -2608,6 +2608,22 @@ svr4_exec_displacement (CORE_ADDR *displacementp) if (memcmp (phdrp, phdr2p, sizeof (*phdrp)) == 0) continue; + /* Gold and strip differ on the flags and alignment of + PT_GNU_RELRO. See PR 11786. */ + if (phdr2[i].p_type == PT_GNU_RELRO) + { + Elf32_External_Phdr tmp_phdr = *phdrp; + Elf32_External_Phdr tmp_phdr2 = *phdr2p; + + memset (tmp_phdr.p_flags, 0, 4); + memset (tmp_phdr.p_align, 0, 4); + memset (tmp_phdr2.p_flags, 0, 4); + memset (tmp_phdr2.p_align, 0, 4); + + if (memcmp (&tmp_phdr, &tmp_phdr2, sizeof (tmp_phdr)) == 0) + continue; + } + /* prelink can convert .plt SHT_NOBITS to SHT_PROGBITS. */ plt2_asect = bfd_get_section_by_name (exec_bfd, ".plt"); if (plt2_asect) @@ -2717,6 +2733,22 @@ svr4_exec_displacement (CORE_ADDR *displacementp) if (memcmp (phdrp, phdr2p, sizeof (*phdrp)) == 0) continue; + /* Gold and strip differ on the flags and alignment of + PT_GNU_RELRO. See PR 11786. */ + if (phdr2[i].p_type == PT_GNU_RELRO) + { + Elf64_External_Phdr tmp_phdr = *phdrp; + Elf64_External_Phdr tmp_phdr2 = *phdr2p; + + memset (tmp_phdr.p_flags, 0, 4); + memset (tmp_phdr.p_align, 0, 8); + memset (tmp_phdr2.p_flags, 0, 4); + memset (tmp_phdr2.p_align, 0, 8); + + if (memcmp (&tmp_phdr, &tmp_phdr2, sizeof (tmp_phdr)) == 0) + continue; + } + /* prelink can convert .plt SHT_NOBITS to SHT_PROGBITS. */ plt2_asect = bfd_get_section_by_name (exec_bfd, ".plt"); if (plt2_asect) diff --git a/gdb/testsuite/gdb.base/gcore-relro-pie.c b/gdb/testsuite/gdb.base/gcore-relro-pie.c new file mode 100644 index 0000000..1594385 --- /dev/null +++ b/gdb/testsuite/gdb.base/gcore-relro-pie.c @@ -0,0 +1,41 @@ +/* Copyright 2013 Free Software Foundation, Inc. + + This file is part of GDB. + + 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, see . */ + +void +break_here () +{ + *(int *) 0 = 0; +} + +void +foo () +{ + break_here (); +} + +void +bar () +{ + foo (); +} + +int +main (void) +{ + bar (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/gcore-relro-pie.exp b/gdb/testsuite/gdb.base/gcore-relro-pie.exp new file mode 100644 index 0000000..1fcfd8c --- /dev/null +++ b/gdb/testsuite/gdb.base/gcore-relro-pie.exp @@ -0,0 +1,70 @@ +# Copyright 2013 Free Software Foundation, Inc. + +# 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, see . + +# PR 11786 (Gold and strip differ on flags,align fields of PT_GNU_RELRO). +# Generate a core file from the stripped version of the program, +# and then try to debug the core with the unstripped version. + +standard_testfile + +if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug additional_flags=-fpie additional_flags=-pie additional_flags=-Wl,-z,relro}]} { + return -1 +} + +set stripped_binfile ${binfile}.stripped +set gcorefile ${binfile}.gcore + +set strip_program [transform strip] +remote_file host delete ${stripped_binfile} +if [run_on_host "strip" "$strip_program" "-g -o ${stripped_binfile} $binfile"] { + return -1 +} + +clean_restart ${stripped_binfile} + +# Does this gdb support gcore? +set test "help gcore" +gdb_test_multiple $test $test { + -re "Undefined command: .gcore.*\r\n$gdb_prompt $" { + # gcore command not supported -- nothing to test here. + unsupported "gdb does not support gcore on this target" + return -1 + } + -re "Save a core file .*\r\n$gdb_prompt $" { + pass $test + } +} + +# The binary is stripped of debug info, but not minsyms. +if ![runto break_here] { + fail "Can't run to break_here" + return -1 +} + +if {![gdb_gcore_cmd $gcorefile "save a corefile"]} { + return -1 +} + +# Now restart gdb with the unstripped binary and load the corefile. + +clean_restart ${binfile} + +gdb_test "core ${gcorefile}" \ + "Core was generated by .*" "re-load generated corefile" + +# Put $pc in gdb.log for debug purposes for comparison with stripped case. +gdb_test "x/i \$pc" "break_here.*" + +gdb_test "frame" "#0 \[^\r\n\]* break_here .*" "unstripped + core ok"