From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 69A7138387F9 for ; Fri, 27 May 2022 21:20:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 69A7138387F9 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pg1-x535.google.com with SMTP id r71so4985079pgr.0 for ; Fri, 27 May 2022 14:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m7np164oTC9yIFrezKK7ELWpbB2GEDldlu/fwuhYL3I=; b=MOtmgt+I+Orv+rJ+kyY1pzywpDkOJVbUfqIxAIMvaJJ6XNiYn9joRNOgtcHyO1ll/y rExjtT/rbDv7SYK/rEjyANa48UvpHZ8caRIwmXC+D4jTKFSek+ZWTEzXTKF4rX4kkGFH jJLRgBGWFX9OAP84/KpJTNO/rl04mwu6RYyE7Meb8rQXH4XafgQ/UUhMO9uxyAiUxXuX h6aEeyQgRmldpOhjhbV/vEfhR84zBxCB3VZFn2yXFHB1IGpeW7a7nIYyh/ILfNt3Lpmw zNfOPaZShp1iuHk04g4Xgau9ZIK3hIchOmCbIZvo7MXHFeg5Kv8AygambQTUKMshrrI3 VwHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m7np164oTC9yIFrezKK7ELWpbB2GEDldlu/fwuhYL3I=; b=Ke2S2xCEHpKsg3jyTaimdWQpW49GSsNK10PgtvUh+IkKP0ApPgPSY3z/FpbqNuXWAb khytBO/GYhnMHLGy4Y2ou3U0oyEzUm/5GJGLlul8iVNmnlziIeMm5bLp4dKb7tbJuRqL lpsrQ0jBnKzfy57ay1EEte0PgqI8Vb5E96KNu+c3p1EvTRQlpxz7kNOh/moDpsQNhsC1 x2OxK210cYjM/hEiTB3w5lrj25YitdugrXLXxW1fFps0+sPEWj77rEHayu8tEG9lweAp Uh+tZj9gv6ld5FM5kiPOwDbpJhey+l7ZW6+CxcvCSS9L+omHPO61VqX59bzUtAi1qw1f N9/A== X-Gm-Message-State: AOAM5338enOxqhx5rBc93QMV3YFVBW5MSkAsaWpFehRwn6/iK+NU8i0B gbsWkccrSpJ2AT1sfEhIzY5kTQ/bAgcYUg== X-Google-Smtp-Source: ABdhPJx6+x3d+LPsreZcebEfOKb6zK474/9DmMyby2Ae7H8loHK4m+/WLCr6uXF84a7wYqMAot7wfw== X-Received: by 2002:a05:6a00:140f:b0:4e0:6995:9c48 with SMTP id l15-20020a056a00140f00b004e069959c48mr45253373pfu.59.1653686444096; Fri, 27 May 2022 14:20:44 -0700 (PDT) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hq.rivosinc.com ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id o20-20020a63fb14000000b003ed6b3dc52esm3901320pgh.55.2022.05.27.14.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 May 2022 14:20:43 -0700 (PDT) From: Patrick O'Neill To: binutils@sourceware.org, nelson.chu@sifive.com Cc: gnu-toolchain@rivosinc.com, jim.wilson.gcc@gmail.com, palmer@rivosinc.com, andrew@sifive.com, kito.cheng@gmail.com, Patrick O'Neill Subject: [PATCH v3 3/3] RISCV: Add --defer-deletion flag Date: Fri, 27 May 2022 14:20:05 -0700 Message-Id: <20220527212005.30709-4-patrick@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220527212005.30709-1-patrick@rivosinc.com> References: <20220502135048.1392596-1-patrick@rivosinc.com> <20220527212005.30709-1-patrick@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 May 2022 21:20:47 -0000 Previously the linker failed to relax only the backwards case (where a relaxation enables another relaxation that has already been checked). With patches 1-4, the behavior has been changed to fail in both the forward and backwards case. It's possible that this will lead to worse performance, so the --no-defer-deletion flag allows you to use the non-linear immediate deletion method. By default, the linear deletion method is enabled as this is expected to be more performant. 2022-05-27 Patrick O'Neill * elfnn-riscv.c: Pass flag to deletion function to immediately delete bytes (or not). * bfdlink.h: Add delete_immediately flag. * ld/ld.texi: Document the new --defer-deletion flag. * ld/ldlex.h: Add DEFER_DELETION and NO_DEFER_DELETION options. * ld/lexsup.c: Parse --defer-deletion and --no-defer-deletion flags. Signed-off-by: Patrick O'Neill --- I think that there may be a better way to phrase the --defer-deletion flag. I'm also unsure if this is the correct way of expressing a target-specific linker flag. --- v2 Changelog: - This is a new patch. --- v3 Changelog: - Rebase with changes to elfnn-riscv.c from patch 2/3. --- bfd/elfnn-riscv.c | 12 ++++++++---- include/bfdlink.h | 4 ++++ ld/ld.texi | 10 ++++++++++ ld/ldlex.h | 2 ++ ld/lexsup.c | 10 ++++++++++ 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 4b6ea179442..0a750773d47 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -4324,7 +4324,8 @@ _bfd_riscv_relax_call (bfd *abfd, asection *sec, asection *sym_sec, /* Delete unnecessary JALR. */ *again = true; return riscv_relax_delete_bytes (abfd, sec, rel->r_offset + len, 8 - len, - rel + 1, link_info, pcgp_relocs, true); + rel + 1, link_info, pcgp_relocs, + !link_info->immediate_deletion); } /* Traverse all output sections and return the max alignment. */ @@ -4417,7 +4418,8 @@ _bfd_riscv_relax_lui (bfd *abfd, /* We can delete the unnecessary LUI and reuse the reloc. */ *again = true; return riscv_relax_delete_bytes (abfd, sec, rel->r_offset, 4, rel, - link_info, pcgp_relocs, true); + link_info, pcgp_relocs, + !link_info->immediate_deletion); default: abort (); @@ -4450,7 +4452,8 @@ _bfd_riscv_relax_lui (bfd *abfd, *again = true; return riscv_relax_delete_bytes (abfd, sec, rel->r_offset + 2, 2, rel + 1, - link_info, pcgp_relocs, true); + link_info, pcgp_relocs, + !link_info->immediate_deletion); } return true; @@ -4492,7 +4495,8 @@ _bfd_riscv_relax_tls_le (bfd *abfd, rel->r_info = ELFNN_R_INFO (0, R_RISCV_NONE); *again = true; return riscv_relax_delete_bytes (abfd, sec, rel->r_offset, 4, rel, - link_info, pcgp_relocs, true); + link_info, pcgp_relocs, + !link_info->immediate_deletion); default: abort (); diff --git a/include/bfdlink.h b/include/bfdlink.h index 09a3ec01685..f6c87fbe911 100644 --- a/include/bfdlink.h +++ b/include/bfdlink.h @@ -587,6 +587,10 @@ struct bfd_link_info args_type structure in ldmain.c:main. */ signed int disable_target_specific_optimizations; + /* Enable or disable deferred deletion of linker relaxations. + This option is enabled my default. */ + unsigned int immediate_deletion: 1; + /* Function callbacks. */ const struct bfd_link_callbacks *callbacks; diff --git a/ld/ld.texi b/ld/ld.texi index eabbec8faa9..c536eed4162 100644 --- a/ld/ld.texi +++ b/ld/ld.texi @@ -2186,6 +2186,16 @@ This option is ignored for Linux compatibility. @item -Qy This option is ignored for SVR4 compatibility. +@cindex defer relaxation deletion +@kindex --defer-relaxation-deletions +@kindex --no-defer-relaxation-deletions +@item --defer-relaxation-deletions +@itemx --no-defer-relaxation-deletions +Enable (or don't enable) linear time linker relaxations by deferring byte +deletion. This assumes the pathologial case is rare. If the pathological case +is common, disabling linear linking will improve performance. +Default to linear time linker relaxation. + @kindex --relax @cindex synthesizing linker @cindex relaxing addressing modes diff --git a/ld/ldlex.h b/ld/ldlex.h index 57ade1f754b..ce9f5d5aafe 100644 --- a/ld/ldlex.h +++ b/ld/ldlex.h @@ -54,6 +54,8 @@ enum option_values OPTION_OFORMAT, OPTION_RELAX, OPTION_NO_RELAX, + OPTION_DEFER_DELETION, + OPTION_NO_DEFER_DELETION, OPTION_NO_SYMBOLIC, OPTION_RETAIN_SYMBOLS_FILE, OPTION_RPATH, diff --git a/ld/lexsup.c b/ld/lexsup.c index 9225f71b3ce..1a0d9a31fef 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -442,6 +442,10 @@ static const struct ld_option ld_options[] = '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES }, { {"no-relax", no_argument, NULL, OPTION_NO_RELAX}, '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES }, + { {"defer-deletion", no_argument, NULL, OPTION_DEFER_DELETION}, + '\0', NULL, N_("Defer deletions caused by linker relaxation"), TWO_DASHES }, + { {"no-defer-deletion", no_argument, NULL, OPTION_NO_DEFER_DELETION}, + '\0', NULL, N_("Do not defer deletions caused by linker relaxation"), TWO_DASHES }, { {"retain-symbols-file", required_argument, NULL, OPTION_RETAIN_SYMBOLS_FILE}, '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES }, @@ -935,6 +939,12 @@ parse_args (unsigned argc, char **argv) case OPTION_NO_WARN_RWX_SEGMENTS: link_info.no_warn_rwx_segments = 1; break; + case OPTION_DEFER_DELETION: + link_info.immediate_deletion = false; + break; + case OPTION_NO_DEFER_DELETION: + link_info.immediate_deletion = true; + break; case 'e': lang_add_entry (optarg, true); break; -- 2.25.1