Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CROSSTOOL opt mode flags #99

Closed
ulfjack opened this issue Apr 7, 2015 · 6 comments
Closed

Update CROSSTOOL opt mode flags #99

ulfjack opened this issue Apr 7, 2015 · 6 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request

Comments

@ulfjack
Copy link
Contributor

ulfjack commented Apr 7, 2015

Update CROSSTOOL opt mode, at least set -O2, maybe -DNDEBUG as well?

@mzhaom
Copy link
Contributor

mzhaom commented Apr 7, 2015

What about "-fno-omit-frame-pointer"?

@ulfjack
Copy link
Contributor Author

ulfjack commented Apr 7, 2015

What about it? :-) I don't have any first-hand experience with it, but I
think it can be made to work.

On Tuesday, April 7, 2015, Ming Zhao notifications@github.com wrote:

What about "-fno-omit-frame-pointer"?


Reply to this email directly or view it on GitHub
#99 (comment).

@damienmg damienmg added type: feature request P3 We're not considering working on this, but happy to review a PR. (No assignee) labels Apr 8, 2015
@mzhaom
Copy link
Contributor

mzhaom commented May 7, 2015

Does a change like this make sense?

--- a/tools/cpp/CROSSTOOL                                                                                                                                                                     
+++ b/tools/cpp/CROSSTOOL                                                                                                                                                                     
@@ -35,6 +35,22 @@ toolchain {
   tool_path { name: "dwp" path: "/usr/bin/dwp" }                                                                                                                                             
   tool_path { name: "gcc" path: "/usr/bin/gcc" }                                                                                                                                             
   cxx_flag: "-std=c++0x"                                                                                                                                                                     
+  compilation_mode_flags {                                                                                                                                                                   
+    mode: FASTBUILD                                                                                                                                                                          
+  }                                                                                                                                                                                          
+  compilation_mode_flags {                                                                                                                                                                   
+    mode: DBG                                                                                                                                                                                
+    cxx_flag: "-g3"                                                                                                                                                                          
+  }                                                                                                                                                                                          
+  compilation_mode_flags {                                                                                                                                                                   
+    mode: COVERAGE                                                                                                                                                                           
+  }                                                                                                                                                                                          
+  compilation_mode_flags {                                                                                                                                                                   
+    mode: OPT                                                                                                                                                                                
+    compiler_flag: "-DNDEBUG"                                                                                                                                                                
+    compiler_flag: "-fno-omit-frame-pointer"                                                                                                                                                 
+    compiler_flag: "-O3"                                                                                                                                                                     
+  }                                                                                                                                                                                          
   linker_flag: "-lstdc++"                                                                                                                                                                    
   linker_flag: "-B/usr/bin/"                               

@ulfjack
Copy link
Contributor Author

ulfjack commented May 7, 2015

Here's my proposal.

for DBG:
It's unclear that the benefits of -g3 warrant the size increase of the resulting binaries.
-g
for OPT:
# No debug symbols
# Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or even generally?
# However, that can't happen here, as it requires special handling in Bazel.
compiler_flag: "-g0"
# Conservative choice for -O
# -O3 can increase binary size and even slow down the resulting binaries.
# Profile first and / or use FDO if you need better performance than this.
compiler_flag: "-O2"
compiler_flag: "-DNDEBUG"
# Removal of unused code and data at link time (can this increase binary size in some cases?).
compiler_flag: "-ffunction-sections"
compiler_flag: "-fdata-sections"
linker_flag: "-Wl,--gc-sections"
This doesn't really belong here, but if we're changing the crosstool file, we might also want to update the default flags. Personally, I'd add security hardening options by default, as well as enable a number of warnings. I haven't tried to build anything with these options yet.
# Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases.
compiler_flag: "-D_FORTIFY_SOURCE=1"
compiler_flag: "-fstack-protector"
compiler_flag: "-fPIE"
linker_flag: "-pie"
linker_flag: "-Wl,-z,relro,-z,now"
# Enable coloring even if there's no attached terminal.
compiler_flag: "-fcolor-diagnostics"
# All warnings are enabled (this is probably too aggressive).
# Maybe enable -Werror as well?
compiler_flag: "-Wall"
compiler_flag: "-Wformat-security"
compiler_flag: "-Wthread-safety-analysis"
compiler_flag: "-Wunused-but-set-parameter"
compiler_flag: "-Wself-assign"
compiler_flag: "-Wno-free-nonheap-object" # has false positives
compiler_flag: "-fno-omit-frame-pointer"
compiler_flag: "-gmlt"
linker_flag: "-Wl,--build-id=md5"
linker_flag: "-Wl,--hash-style=gnu"
linker_flag: "-pass-exit-codes"
# Gold linker only?
linker_flag: "-Wl,--warn-execstack"
linker_flag: "-Wl,--detect-odr-violations"

@mzhaom
Copy link
Contributor

mzhaom commented May 9, 2015

looks good to me, 👍

@tfarina
Copy link
Contributor

tfarina commented May 13, 2015

I can try building with some of these flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request
Projects
None yet
Development

No branches or pull requests

4 participants