From patchwork Thu Aug 16 18:37:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Terekhov, Mikhail via Gdb-patches" X-Patchwork-Id: 28941 Received: (qmail 99681 invoked by alias); 16 Aug 2018 18:37:52 -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 99671 invoked by uid 89); 16 Aug 2018 18:37:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HX-HELO:sk:mail-yb X-HELO: mail-yb0-f201.google.com Received: from mail-yb0-f201.google.com (HELO mail-yb0-f201.google.com) (209.85.213.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Aug 2018 18:37:49 +0000 Received: by mail-yb0-f201.google.com with SMTP id s12-v6so1301009ybm.19 for ; Thu, 16 Aug 2018 11:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=zV0IhklLxY+Wuzej835I49qs9sigDFCw7peUjuYQu2M=; b=AyNFoBagF0ibrZuvlthLQP7ot3qXG4xj0aJF3NEJJV52rkslV388LWZSmzz2gy/1p9 xV8NwEn8ARjIiyKy32VXNeN5CLe91zTbQuP87F0CIftk2tw5t/Q9q6ugi+aZjt43PfuI SNAL7USV0PuOU10nQXeKOkgBGeVVe3IIZcKodyexFcfjUBt57XY4/G9lF3JY+TdBd7dV hVycM+4LSqOjuuR/h7X3hVhAKbyUV9XY6YOPQvqvAo8BDnwo7f4COa0+/z0zJCg/aNF3 qfF66kn9fEtHgCkmmnM1fwHWk30av0qnhqOcm7wil499PmxrKmIg9rBCeAKQFrvnKmN1 5WYw== Date: Thu, 16 Aug 2018 14:37:38 -0400 Message-Id: <20180816183737.73409-1-spang@google.com> Mime-Version: 1.0 Subject: [PATCH] Fix debugging of stripped PIE executables with padded PT_TLS X-Patchwork-Original-From: "spang.google.com via gdb-patches" From: "Terekhov, Mikhail via Gdb-patches" Reply-To: spang@google.com To: gdb-patches@sourceware.org Cc: Michael Spang From: Michael Spang Certain PIE executables produced by gold cannot be debugged by gdb after being stripped. GDB requires program headers of PIE executables to match, and those checks may fail due to adjustments made during stripping. One case of this occurs because strip recomputes the memsz of PT_TLS and does not add alignment, while gold does. This is another variant of PR 11786, so apply the same fix of relaxing the program header matching. gdb/ChangeLog: PR gdb/11786 * solib-svr4.c (svr4_exec_displacement): Ignore memsz fields for PT_TLS segments. testsuite/ * gdb.base/gcore-tls-pie.c: New file. * gdb.base/gcore-tls-pie.exp: New file. --- gdb/ChangeLog | 10 ++++++++++ gdb/solib-svr4.c | 8 ++++++-- .../gdb.base/{gcore-relro-pie.c => gcore-tls-pie.c} | 4 ++++ .../{gcore-relro-pie.exp => gcore-tls-pie.exp} | 4 ++-- 4 files changed, 22 insertions(+), 4 deletions(-) copy gdb/testsuite/gdb.base/{gcore-relro-pie.c => gcore-tls-pie.c} (96%) copy gdb/testsuite/gdb.base/{gcore-relro-pie.exp => gcore-tls-pie.exp} (93%) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9fac8ccf5f..b441619ca7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2018-08-16 Michael Spang + + PR gdb/11786 + * solib-svr4.c (svr4_exec_displacement): Ignore memsz fields + for PT_TLS segments. + + testsuite/ + * gdb.base/gcore-tls-pie.c: New file. + * gdb.base/gcore-tls-pie.exp: New file. + 2018-08-15 Tom Tromey * aarch64-linux-tdep.c (aarch64_linux_core_read_vq): Use pulongest. diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 6f48c68632..84589509ef 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -2709,8 +2709,10 @@ svr4_exec_displacement (CORE_ADDR *displacementp) /* Strip modifies the flags and alignment of PT_GNU_RELRO. CentOS-5 has problems with filesz, memsz as well. + Strip also modifies memsz of PT_TLS. See PR 11786. */ - if (phdr2[i].p_type == PT_GNU_RELRO) + if (phdr2[i].p_type == PT_GNU_RELRO || + phdr2[i].p_type == PT_TLS) { Elf32_External_Phdr tmp_phdr = *phdrp; Elf32_External_Phdr tmp_phdr2 = *phdr2p; @@ -2840,8 +2842,10 @@ svr4_exec_displacement (CORE_ADDR *displacementp) /* Strip modifies the flags and alignment of PT_GNU_RELRO. CentOS-5 has problems with filesz, memsz as well. + Strip also modifies memsz of PT_TLS. See PR 11786. */ - if (phdr2[i].p_type == PT_GNU_RELRO) + if (phdr2[i].p_type == PT_GNU_RELRO || + phdr2[i].p_type == PT_TLS) { Elf64_External_Phdr tmp_phdr = *phdrp; Elf64_External_Phdr tmp_phdr2 = *phdr2p; diff --git a/gdb/testsuite/gdb.base/gcore-relro-pie.c b/gdb/testsuite/gdb.base/gcore-tls-pie.c similarity index 96% copy from gdb/testsuite/gdb.base/gcore-relro-pie.c copy to gdb/testsuite/gdb.base/gcore-tls-pie.c index 2b5c0f3d2f..9deb4cd1d8 100644 --- a/gdb/testsuite/gdb.base/gcore-relro-pie.c +++ b/gdb/testsuite/gdb.base/gcore-tls-pie.c @@ -15,6 +15,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ + +__thread long j; +__thread char i; + void break_here (void) { diff --git a/gdb/testsuite/gdb.base/gcore-relro-pie.exp b/gdb/testsuite/gdb.base/gcore-tls-pie.exp similarity index 93% copy from gdb/testsuite/gdb.base/gcore-relro-pie.exp copy to gdb/testsuite/gdb.base/gcore-tls-pie.exp index fd03e4a98d..1f7381e1b3 100644 --- a/gdb/testsuite/gdb.base/gcore-relro-pie.exp +++ b/gdb/testsuite/gdb.base/gcore-tls-pie.exp @@ -13,13 +13,13 @@ # 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). +# PR 11786 (Gold and strip differ on memsz field of PT_TLS). # 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 "failed to prepare" $testfile $srcfile {debug additional_flags=-fpie "ldflags=-pie -Wl,-z,relro"}]} { +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug additional_flags=-fpie "ldflags=-pie -fuse-ld=gold"}]} { return -1 }