unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Alex Vong <alexvong1995@gmail.com>
To: 30111@debbugs.gnu.org
Subject: [bug#30111] [PATCH] gnu: gcc@7: Use retpoline options when building itself.
Date: Sat, 27 Jan 2018 11:19:55 +0800	[thread overview]
Message-ID: <87lggkt2ck.fsf@gmail.com> (raw)
In-Reply-To: <877esksi62.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 338 bytes --]

Hello,

This patch makes gcc use retpoline options when building itself. My last
attempt to build it was successful. But after that I have changed
something, I hope it wouldn't make it fail to build. (It shouldn't,
since the options passed aren't changed.)

Are we going to add these options to other natively compiled programs as
well?


[-- Attachment #2: 0001-gnu-gcc-7-Use-retpoline-options-when-building-itself.patch --]
[-- Type: text/x-diff, Size: 3619 bytes --]

From f6b9caae6e13936be65550c871208a3425fe4ce4 Mon Sep 17 00:00:00 2001
From: Alex Vong <alexvong1995@gmail.com>
Date: Thu, 25 Jan 2018 23:24:24 +0800
Subject: [PATCH] gnu: gcc@7: Use retpoline options when building itself.

* gnu/packages/gcc.scm (gcc@7)[arguments]: Add retpoline options
to #:make-flags.
---
 gnu/packages/gcc.scm | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/gnu/packages/gcc.scm b/gnu/packages/gcc.scm
index 48e7b8ee3..6344ce734 100644
--- a/gnu/packages/gcc.scm
+++ b/gnu/packages/gcc.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
 ;;; Copyright © 2015, 2016, 2017 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2016 Carlos Sánchez de La Lama <csanchezdll@gmail.com>
+;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -428,6 +429,45 @@ Go.  It also includes runtime support libraries for these languages.")
                 "0p71bij6bfhzyrs8676a8jmpjsfz392s2rg862sdnsk30jpacb43"))
               (patches (search-patches "gcc-strmov-store-file-names.patch"
                                        "gcc-5.0-libvtv-runpath.patch"))))
+    (arguments
+     (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
+                                                (guix build utils)
+                                                (ice-9 regex)
+                                                (srfi srfi-1)
+                                                (srfi srfi-26))
+                                     ,@(package-arguments gcc-6))
+       ;; Use retpoline options when building itself.
+       ((#:make-flags flags)
+        `(let* ((cross-compiling? ,(%current-target-system))
+                (system (if cross-compiling?
+                            ,(%current-target-system)
+                            ,(%current-system)))
+                (retpoline-opts '("-mindirect-branch=thunk"
+                                  "-mfunction-return=thunk"
+                                  "-mindirect-branch-register"))
+                (append-flag
+                 (lambda (flag)
+                   (if (string-match "^((BOOT_)?CFLAGS|C(XX)?FLAGS_FOR_TARGET)="
+                                     flag)
+                       (string-join (cons flag retpoline-opts))
+                       flag)))
+                (add-flag
+                 (lambda (prefix flags)
+                   (if (any (cut string-prefix? prefix <>) flags)
+                       flags
+                       (cons (string-append prefix
+                                            (string-join retpoline-opts))
+                             flags))))
+                (add-gcc-flag (cut add-flag
+                                (if cross-compiling? "CFLAGS=" "BOOT_CFLAGS=")
+                                <>))
+                (add-c-lib-flag (cut add-flag "CFLAGS_FOR_TARGET=" <>))
+                (add-c++-lib-flag (cut add-flag "CXXFLAGS_FOR_TARGET=" <>)))
+           ;; Right now, the retpoline options are x86-specific.
+           (if (any (cut string-prefix? <> system) '("x86_64" "i686"))
+               (add-gcc-flag (add-c-lib-flag (add-c++-lib-flag (map append-flag
+                                                                    ,flags))))
+               ,flags)))))
     (description
      "GCC is the GNU Compiler Collection.  It provides compiler front-ends
 for several languages, including C, C++, Objective-C, Fortran, Ada, and Go.
-- 
2.15.1


[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


Cheers,
Alex

  parent reply	other threads:[~2018-01-27  3:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-14 13:07 [bug#30111] gnu: gcc@7: Apply the 'retpoline' mitigation technique Alex Vong
2018-01-15 14:29 ` Alex Vong
2018-01-16 13:14   ` Alex Vong
2018-01-16 14:33     ` Ludovic Courtès
2018-01-16 15:24       ` Alex Vong
2018-01-17 13:11         ` Ludovic Courtès
2018-01-17 23:31           ` Leo Famulari
2018-01-27  3:19 ` Alex Vong [this message]
2018-02-27  9:37   ` [bug#30111] [PATCH] gnu: gcc@7: Use retpoline options when building itself Ludovic Courtès
2018-06-22 20:07 ` [bug#30111] gnu: gcc@7: Use retpoline options when building itself. Previous Next Gábor Boskovits
2020-12-18 23:22 ` [bug#30111] gnu: gcc@7: Apply the 'retpoline' mitigation technique zimoun
2021-01-11 15:43   ` zimoun
2021-01-11 20:03     ` Efraim Flashner
2021-02-09  1:07       ` bug#30111: " zimoun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lggkt2ck.fsf@gmail.com \
    --to=alexvong1995@gmail.com \
    --cc=30111@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).