From patchwork Tue May 8 15:05:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 910251 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-477363-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="a8zyKIhI"; dkim-atps=neutral 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 40gN8p1gGhz9s0W for ; Wed, 9 May 2018 01:05:45 +1000 (AEST) 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:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=IombvKf0MpOW1v3zKPnMfyibYbCm6qWegH70urOImQJK2Uk+un RM+vtJzka7t5Xp0vV1gHYNAZZkXAjhDiS5QtxkDV7gCQn8rPrFpeNufChd3Mykg3 gDeBW1MFdhOsYMlxrZAHSX13EYBhXtkIsAheECdP0pjXlRDCY8qBjGCQU= 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:cc:subject:message-id:mime-version:content-type; s= default; bh=L9EAbnYh8uh9OGNhgV/H1q206As=; b=a8zyKIhI2x8YotB3g0Og nk61W7SLlYUwo60Pg50MZK99KLQxy8/2ySpiZT9bjTitWTa8lS747Nu3SBAyQ6zj vP9z8Hyfie8rET3xvKrTfRm/jTbA7lh4+yONYBMdW2Kk6Lue47h4stiapHHjNnl1 Efcj0TZRaNX5yucUWL3tIkY= Received: (qmail 32450 invoked by alias); 8 May 2018 15:05:38 -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 32436 invoked by uid 89); 8 May 2018 15:05:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=H*F:D*cz, IRC, irc X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 08 May 2018 15:05:34 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id CBC95541685; Tue, 8 May 2018 17:05:31 +0200 (CEST) Date: Tue, 8 May 2018 17:05:31 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Cc: dj@redhat.com, ian@airs.com, rguenther@suse.de Subject: [RFA] Incremental LTO linking part 1: simple-object bits Message-ID: <20180508150531.GA16916@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Hi, for incremental linking of LTO objects we need to copy debug sections from source object files into destination without renaming them from .gnu.debuglto into the standard debug section (because they will again be LTO debug section in the resulting object file). I have discussed this with Richard on IRC and I hope it is fine to change the API here becuase lto-wrapper is the only user of this function. I will send lto-wrapper support in separate patch. I have lto-bootstrapped/regtested the whole incremental linking patchet on x86-64-linux with libbackend being incrementaly linked and also experimented with extra testcases and tested that debugging works on resulting cc1 binary. OK? Honza * simple-object.h (simple_object_copy_lto_debug_sections): Add rename parameter. * simple-object.c (handle_lto_debug_sections): Add rename parameter. (handle_lto_debug_sections_rename): New function. (handle_lto_debug_sections_norename): New function. (simple_object_copy_lto_debug_sections): Add rename parameter. Index: include/simple-object.h =================================================================== --- include/simple-object.h (revision 260042) +++ include/simple-object.h (working copy) @@ -198,12 +198,15 @@ simple_object_release_write (simple_object_write *); /* Copy LTO debug sections from SRC_OBJECT to DEST. + If RENAME is true, rename LTO debug section into debug section (i.e. + when producing final binary) and if it is false, keep the sections with + original names (when incrementally linking). If an error occurs, return the errno value in ERR and an error string. */ extern const char * simple_object_copy_lto_debug_sections (simple_object_read *src_object, const char *dest, - int *err); + int *err, int rename); #ifdef __cplusplus } Index: libiberty/simple-object.c =================================================================== --- libiberty/simple-object.c (revision 260042) +++ libiberty/simple-object.c (working copy) @@ -251,12 +251,15 @@ } /* Callback to identify and rename LTO debug sections by name. - Returns 1 if NAME is a LTO debug section, 0 if not. */ + Returns non-NULL if NAME is a LTO debug section, NULL if not. + If RENAME is true it will rename LTO debug sections to non-LTO + ones. */ static char * -handle_lto_debug_sections (const char *name) +handle_lto_debug_sections (const char *name, int rename) { - char *newname = XCNEWVEC (char, strlen (name) + 1); + char *newname = rename ? XCNEWVEC (char, strlen (name) + 1) + : xstrdup (name); /* ??? So we can't use .gnu.lto_ prefixed sections as the assembler complains about bogus section flags. Which means we need to arrange @@ -265,12 +268,14 @@ /* Also include corresponding reloc sections. */ if (strncmp (name, ".rela", sizeof (".rela") - 1) == 0) { - strncpy (newname, name, sizeof (".rela") - 1); + if (rename) + strncpy (newname, name, sizeof (".rela") - 1); name += sizeof (".rela") - 1; } else if (strncmp (name, ".rel", sizeof (".rel") - 1) == 0) { - strncpy (newname, name, sizeof (".rel") - 1); + if (rename) + strncpy (newname, name, sizeof (".rel") - 1); name += sizeof (".rel") - 1; } /* ??? For now this handles both .gnu.lto_ and .gnu.debuglto_ prefixed @@ -277,10 +282,10 @@ sections. */ /* Copy LTO debug sections and rename them to their non-LTO name. */ if (strncmp (name, ".gnu.debuglto_", sizeof (".gnu.debuglto_") - 1) == 0) - return strcat (newname, name + sizeof (".gnu.debuglto_") - 1); + return rename ? strcat (newname, name + sizeof (".gnu.debuglto_") - 1) : newname; else if (strncmp (name, ".gnu.lto_.debug_", sizeof (".gnu.lto_.debug_") -1) == 0) - return strcat (newname, name + sizeof (".gnu.lto_") - 1); + return rename ? strcat (newname, name + sizeof (".gnu.lto_") - 1) : newname; /* Copy over .note.GNU-stack section under the same name if present. */ else if (strcmp (name, ".note.GNU-stack") == 0) return strcpy (newname, name); @@ -289,14 +294,31 @@ COMDAT sections in objects produced by GCC. */ else if (strcmp (name, ".comment") == 0) return strcpy (newname, name); + free (newname); return NULL; } +/* Wrapper for handle_lto_debug_sections. */ + +static char * +handle_lto_debug_sections_rename (const char *name) +{ + return handle_lto_debug_sections (name, 1); +} + +/* Wrapper for handle_lto_debug_sections. */ + +static char * +handle_lto_debug_sections_norename (const char *name) +{ + return handle_lto_debug_sections (name, 0); +} + /* Copy LTO debug sections. */ const char * simple_object_copy_lto_debug_sections (simple_object_read *sobj, - const char *dest, int *err) + const char *dest, int *err, int rename) { const char *errmsg; simple_object_write *dest_sobj; @@ -317,9 +339,10 @@ if (! dest_sobj) return errmsg; - errmsg = sobj->functions->copy_lto_debug_sections (sobj, dest_sobj, - handle_lto_debug_sections, - err); + errmsg = sobj->functions->copy_lto_debug_sections + (sobj, dest_sobj, + rename ? handle_lto_debug_sections_rename + : handle_lto_debug_sections_norename, err); if (errmsg) { simple_object_release_write (dest_sobj);