From patchwork Tue May 16 11:10:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 762890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wRvqx5h0Pz9s2P for ; Tue, 16 May 2017 21:10:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NuiVH1c8"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=BoTeafuef/5kX+P/t36soELUhZXPpk7CBD1YHhlyAxR83LIpxgq9Y YQv/PG5itVgXLJ7nflcXJNzC/lt5rG2lH9VJKlzf4PCd3NVbuhIpxLntZ7XUqyrW mz0/QFD9F1SNaFTKKa+jKIB/b0dI6nZY7FYsPECEmpkedm/h6/5xww= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=n/McSZv+6Xp0UpGNXI3Y3Ct3IWY=; b=NuiVH1c8xOPEtF28C3HH y/vlIaqkSwR2sKc/rFByJfrf5kQ5LqWTxkv1GN2u6z1OQEJD3VB+ylEMHEn9llNl xHhXBjvGeOKdFn08lwisbixAfbLsZWckxC4+GB2n00t4vP0hxsNhFLyAa8HIeUoV NqObs43tNnGLn6apLRjYEdM= Received: (qmail 88856 invoked by alias); 16 May 2017 11:10:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 88829 invoked by uid 89); 16 May 2017 11:10:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=incremental, printers X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 May 2017 11:10:06 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 06DF8ABBD for ; Tue, 16 May 2017 11:10:07 +0000 (UTC) Date: Tue, 16 May 2017 13:10:06 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] LTO early-debug incremental changes Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following patch ontop of early LTO debug patches get us back to LTO bootstrap (see also the DW_OP_GNU_variable_value fixes / tweaks mail). With early LTO debug we have to resolve DW_OP_GNU_variable_value early as we are going to output the DIEs early. The following patch always does that conservatively when we generate LTO IL (and does not undo that for the eventual fat part of the object). The patch also adjusts asan patterns for PR78063 (libbacktrace doesn't handle location attributes being in an abstract origin imported from a different CU). We then print an address rather than file + line info. The patch also adds a -flto run for the libstdc++ pretty printers (the original motivation of early LTO debug -- make those work). I had to work around ld/20882 here. Richard. Index: early-lto-debug/gcc/dwarf2out.c =================================================================== --- early-lto-debug.orig/gcc/dwarf2out.c 2017-05-16 13:03:51.583346409 +0200 +++ early-lto-debug/gcc/dwarf2out.c 2017-05-16 12:58:20.509820311 +0200 @@ -30643,6 +30642,20 @@ note_variable_value_in_expr (dw_die_ref { tree decl = loc->dw_loc_oprnd1.v.val_decl_ref; dw_die_ref ref = lookup_decl_die (decl); + if (! ref && flag_generate_lto) + { + /* ??? This is somewhat a hack because we do not create DIEs + for variables not in BLOCK trees early but when generating + early LTO output we need the dw_val_class_decl_ref to be + fully resolved. For fat LTO objects we'd also like to + undo this after LTO dwarf output. */ + gcc_assert (DECL_CONTEXT (decl)); + dw_die_ref ctx = lookup_decl_die (DECL_CONTEXT (decl)); + gcc_assert (ctx != NULL); + gen_decl_die (decl, NULL_TREE, NULL, ctx); + ref = lookup_decl_die (decl); + gcc_assert (ref != NULL); + } if (ref) { loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref; Index: early-lto-debug/gcc/testsuite/c-c++-common/asan/global-overflow-1.c =================================================================== --- early-lto-debug.orig/gcc/testsuite/c-c++-common/asan/global-overflow-1.c 2017-05-16 10:07:02.111097130 +0200 +++ early-lto-debug/gcc/testsuite/c-c++-common/asan/global-overflow-1.c 2017-05-16 10:07:09.427211120 +0200 @@ -23,6 +23,6 @@ int main() { } /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */ -/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*global-overflow-1.c:20|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r).*" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*global-overflow-1.c:20|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r).*" } */ /* { dg-output "0x\[0-9a-f\]+ is located 0 bytes to the right of global variable" } */ /* { dg-output ".*YYY\[^\n\r]* of size 10\[^\n\r]*(\n|\r\n|\r)" } */ Index: early-lto-debug/gcc/testsuite/c-c++-common/asan/heap-overflow-1.c =================================================================== --- early-lto-debug.orig/gcc/testsuite/c-c++-common/asan/heap-overflow-1.c 2017-05-16 10:08:38.876604540 +0200 +++ early-lto-debug/gcc/testsuite/c-c++-common/asan/heap-overflow-1.c 2017-05-16 10:08:45.796712320 +0200 @@ -24,8 +24,8 @@ int main(int argc, char **argv) { } /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */ -/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:21|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:21|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 0 bytes to the right of 10-byte region\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output " #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:19|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:19|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ Index: early-lto-debug/gcc/testsuite/c-c++-common/asan/misalign-1.c =================================================================== --- early-lto-debug.orig/gcc/testsuite/c-c++-common/asan/misalign-1.c 2017-04-26 16:15:21.708936635 +0200 +++ early-lto-debug/gcc/testsuite/c-c++-common/asan/misalign-1.c 2017-05-16 10:09:59.333857466 +0200 @@ -39,5 +39,5 @@ main () /* { dg-output "ERROR: AddressSanitizer:\[^\n\r]*on address\[^\n\r]*" } */ /* { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*READ of size 4 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*foo(\[^\n\r]*misalign-1.c:1\[01]|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*misalign-1.c:3\[45]|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*foo(\[^\n\r]*misalign-1.c:1\[01]|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*misalign-1.c:3\[45]|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } */ Index: early-lto-debug/gcc/testsuite/c-c++-common/asan/misalign-2.c =================================================================== --- early-lto-debug.orig/gcc/testsuite/c-c++-common/asan/misalign-2.c 2017-04-26 16:15:21.708936635 +0200 +++ early-lto-debug/gcc/testsuite/c-c++-common/asan/misalign-2.c 2017-05-16 10:10:23.174228648 +0200 @@ -39,5 +39,5 @@ main () /* { dg-output "ERROR: AddressSanitizer:\[^\n\r]*on address\[^\n\r]*" } */ /* { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*READ of size 4 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*baz(\[^\n\r]*misalign-2.c:2\[23]|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*misalign-2.c:3\[45]|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*baz(\[^\n\r]*misalign-2.c:2\[23]|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*misalign-2.c:3\[45]|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } */ Index: early-lto-debug/gcc/testsuite/c-c++-common/asan/null-deref-1.c =================================================================== --- early-lto-debug.orig/gcc/testsuite/c-c++-common/asan/null-deref-1.c 2016-11-10 12:35:11.015453219 +0100 +++ early-lto-debug/gcc/testsuite/c-c++-common/asan/null-deref-1.c 2017-05-16 10:12:02.315771866 +0200 @@ -18,5 +18,5 @@ int main() /* { dg-output "ERROR: AddressSanitizer:? SEGV on unknown address\[^\n\r]*" } */ /* { dg-output "0x\[0-9a-f\]+ \[^\n\r]*pc 0x\[0-9a-f\]+.*(\n|\r\n|\r)" } */ -/* { dg-output " #0 0x\[0-9a-f\]+ +(in \[^\n\r]*NullDeref\[^\n\r]* (\[^\n\r]*null-deref-1.c:10|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*null-deref-1.c:15|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ +(in \[^\n\r]*NullDeref\[^\n\r]* (\[^\n\r]*null-deref-1.c:10|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*null-deref-1.c:15|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ Index: early-lto-debug/gcc/testsuite/c-c++-common/asan/stack-overflow-1.c =================================================================== --- early-lto-debug.orig/gcc/testsuite/c-c++-common/asan/stack-overflow-1.c 2015-01-12 16:25:19.992887357 +0100 +++ early-lto-debug/gcc/testsuite/c-c++-common/asan/stack-overflow-1.c 2017-05-16 10:12:20.452054110 +0200 @@ -18,6 +18,6 @@ int main() { } /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*stack-overflow-1.c:16|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*stack-overflow-1.c:16|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ /* { dg-output "\[^\n\r]*in main.*stack-overflow-1.c.*(\n|\r\n|\r)" */ Index: early-lto-debug/gcc/testsuite/c-c++-common/asan/strncpy-overflow-1.c =================================================================== --- early-lto-debug.orig/gcc/testsuite/c-c++-common/asan/strncpy-overflow-1.c 2015-01-12 16:25:19.985887357 +0100 +++ early-lto-debug/gcc/testsuite/c-c++-common/asan/strncpy-overflow-1.c 2017-05-16 10:13:03.432722916 +0200 @@ -14,8 +14,8 @@ int main(int argc, char **argv) { /* { dg-output "WRITE of size \[0-9\]* at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output " #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)strncpy|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:11|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:11|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 0 bytes to the right of 9-byte region\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output " #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:10|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:10|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ Index: early-lto-debug/gcc/testsuite/c-c++-common/asan/use-after-free-1.c =================================================================== --- early-lto-debug.orig/gcc/testsuite/c-c++-common/asan/use-after-free-1.c 2015-01-12 16:25:19.995887357 +0100 +++ early-lto-debug/gcc/testsuite/c-c++-common/asan/use-after-free-1.c 2017-05-16 10:13:44.657368497 +0200 @@ -12,11 +12,11 @@ int main() { /* { dg-output "ERROR: AddressSanitizer:? heap-use-after-free on address\[^\n\r]*" } */ /* { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:9|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:9|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 5 bytes inside of 10-byte region .0x\[0-9a-f\]+,0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*freed by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output " #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)free|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:8|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:8|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } */ /* { dg-output "\[^\n\r]*previously allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output " #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ -/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:7|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:7|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ Index: early-lto-debug/gcc/testsuite/g++.dg/asan/large-func-test-1.C =================================================================== --- early-lto-debug.orig/gcc/testsuite/g++.dg/asan/large-func-test-1.C 2015-01-12 16:25:17.505887443 +0100 +++ early-lto-debug/gcc/testsuite/g++.dg/asan/large-func-test-1.C 2017-05-16 10:14:30.238082709 +0200 @@ -38,7 +38,7 @@ int main() { // { dg-output "ERROR: AddressSanitizer:? heap-buffer-overflow on address\[^\n\r]*" } // { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } // { dg-output "\[^\n\r]*READ of size 4 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } -// { dg-output " #0 0x\[0-9a-f\]+ +(in \[^\n\r]*LargeFunction\[^\n\r]*(large-func-test-1.C:18|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } +// { dg-output " #0 0x\[0-9a-f\]+ +(in \[^\n\r]*LargeFunction\[^\n\r]*(large-func-test-1.C:18|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } // { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 44 bytes to the right of 400-byte region.*(\n|\r\n|\r)" } // { dg-output "\[^\n\r]*allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } // { dg-output " #0( 0x\[0-9a-f\]+ +(in _*(interceptor_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } Index: early-lto-debug/libstdc++-v3/testsuite/libstdc++-prettyprinters/prettyprinters.exp =================================================================== --- early-lto-debug.orig/libstdc++-v3/testsuite/libstdc++-prettyprinters/prettyprinters.exp 2017-05-16 10:48:04.281774905 +0200 +++ early-lto-debug/libstdc++-v3/testsuite/libstdc++-prettyprinters/prettyprinters.exp 2017-05-16 12:32:28.607998187 +0200 @@ -15,6 +15,7 @@ # . load_lib gdb-test.exp +load_lib target-supports.exp dg-init v3-build_support @@ -46,6 +47,14 @@ global PCH_CXXFLAGS gdb-dg-runtest [lsort [glob $srcdir/$subdir/*.cc]] \ "" "$DEFAULT_CXXFLAGS $PCH_CXXFLAGS" +if { [check_effective_target_lto] } { + append cxxflags " -flto" + # work around sourceware.org 20882 + regsub {^(.*)-Wl,--gc-sections(.*)$} $cxxldflags {\1\2} cxxldflags + gdb-dg-runtest [lsort [glob $srcdir/$subdir/*.cc]] \ + "" "$DEFAULT_CXXFLAGS -flto $PCH_CXXFLAGS" +} + if [info exists guality_gdb_name] { unsetenv GUALITY_GDB_NAME }