[GHC] #14452: `-optc-O3` getting shadowed by automatically injected -O flags
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Consider the following example: {{{#!hs {-# LANGUAGE CApiFFI #-} {-# OPTIONS_GHC -optc-O3 #-} module M where foreign import capi unsafe "stdlib.h exit" c_exit :: Int -> IO () }}} However, the `-optc-O3` flag has no effect, unless `ghc` is called without any `-O` flags, or with `-O0`. Here's the resulting C compiler invocations for different `-O` flags: {{{ $ ghc -fforce-recomp -v -c m.hs |& grep O3 gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE -O3 -x c /tmp/ghc14023_0/ghc_2.c -o /tmp/ghc14023_0/ghc_3.s -Wimplicit -S -include /opt/ghc/8.2.1/lib/ghc-8.2.1/include/ghcversion.h -I. -I/opt/ghc/8.2.1/lib/ghc-8.2.1/base-4.10.0.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/integer-gmp-1.0.1.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/include }}} {{{ $ ghc -fforce-recomp -O0 -v -c m.hs |& grep O3 gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE -O3 -x c /tmp/ghc14045_0/ghc_2.c -o /tmp/ghc14045_0/ghc_3.s -Wimplicit -S -include /opt/ghc/8.2.1/lib/ghc-8.2.1/include/ghcversion.h -I. -I/opt/ghc/8.2.1/lib/ghc-8.2.1/base-4.10.0.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/integer-gmp-1.0.1.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/include }}} {{{ $ ghc -fforce-recomp -O1 -v -c m.hs |& grep O3 gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE -O3 -x c /tmp/ghc14073_0/ghc_2.c -o /tmp/ghc14073_0/ghc_3.s -Wimplicit -S -O -include /opt/ghc/8.2.1/lib/ghc-8.2.1/include/ghcversion.h -I. -I/opt/ghc/8.2.1/lib/ghc-8.2.1/base-4.10.0.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/integer-gmp-1.0.1.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/include }}} {{{ $ ghc -fforce-recomp -O2 -v -c m.hs |& grep O3 gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE -O3 -x c /tmp/ghc14093_0/ghc_2.c -o /tmp/ghc14093_0/ghc_3.s -Wimplicit -S -O2 -include /opt/ghc/8.2.1/lib/ghc-8.2.1/include/ghcversion.h -I. -I/opt/ghc/8.2.1/lib/ghc-8.2.1/base-4.10.0.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/integer-gmp-1.0.1.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/include }}} {{{ $ ghc -fforce-recomp -O3 -v -c m.hs |& grep O3 gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE -O3 -x c /tmp/ghc14119_0/ghc_2.c -o /tmp/ghc14119_0/ghc_3.s -Wimplicit -S -O2 -include /opt/ghc/8.2.1/lib/ghc-8.2.1/include/ghcversion.h -I. -I/opt/ghc/8.2.1/lib/ghc-8.2.1/base-4.10.0.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/integer-gmp-1.0.1.0/include -I/opt/ghc/8.2.1/lib/ghc-8.2.1/include }}} To summarise, here's the resulting effective `-O`-level passed to `gcc`: ||= GHC invocation =||= GCC invocation =||= Effective C `-O`-level =|| || `ghc` || `gcc -O3` || `-O3` || || `ghc -O0` || `gcc -O3` || `-O3` || || `ghc -O1` || `gcc -O3 -O1` || `-O1` || || `ghc -O2` || `gcc -O3 -O2` || `-O2` || || `ghc -O3` || `gcc -O3 -O2` || `-O2` || Consequently, the only way to have C code compiled with `-O3` is to force GHC into `-O0` mode; this is obviously not ideal, as it easily kills any benefit you'd gain from passing `-O3` to the C compiler... ;-) I see a few alternatives on how to resolve this: 1. Have GHC recognise `-optc-O[0-9]` and suppress automatically injecting any `-O<n>` of its own 2. Have GHC inject its automatic `-O`-flags before user-provided `-optc` flags 3. Have GHC inject `-optc` flags as late as possible on the C compiler command-line 4. Implement a new variant of the `-optc` flag which injects its flags as late as possible on the C compiler command-line -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: RolandSenn Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * owner: (none) => RolandSenn * milestone: => 8.8.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: RolandSenn Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TEST=T14452 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5318 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * testcase: => make test TEST=T14452 * status: new => patch * differential: => Phab:D5318 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: RolandSenn Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TEST=T14452 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5318 Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): Phab:D5318 implements (2) by passing user-provided flags last, which I think is a good way to fix this. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: RolandSenn Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TEST=T14452 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5318 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"f2d9fb0c288788abeb796a13d600295a526290cd/ghc" f2d9fb0c/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="f2d9fb0c288788abeb796a13d600295a526290cd" Calling gcc: Pass optc flags as last options (#14452) Test Plan: make test TEST=T14452 Reviewers: hvr, bgamari, monoidal, thomie, osa1 Reviewed By: osa1 Subscribers: rwbarton, carter GHC Trac Issues: #14452 Differential Revision: https://phabricator.haskell.org/D5318 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: RolandSenn Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TEST=T14452 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5318 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TEST=T14452 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5318 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * owner: RolandSenn => (none) * status: closed => new * resolution: fixed => Comment: The test T14452 is broken under Windows. Under Windows all the parameters of ''gcc'' including the last (''-O3'') are quoted: {{{ "C:\msys64\home\Roli\ghc\inplace\lib\../mingw/bin/gcc.exe" "-fno-stack- protector" "-DTABLES_NEXT_TO_CODE" "-x" "c" "C:\Users\Roli\AppData\Local\Temp\ghc7308_0\ghc_2.c" "-o" "C:\Users\Roli\AppData\Local\Temp\ghc7308_0\ghc_3.s" "-no-pie" "-Wimplicit" "-S" "-O2" "-include" "C:/msys64/home/Roli/ghc/includes\ghcversion.h" "-iquote." "-IC:\msys64\home\Roli\ghc\libraries\base\include" "-IC:\msys64\home\Roli\ghc\libraries\base\dist-install\build\include" "-IC:\msys64\home\Roli\ghc\libraries\integer-gmp\include" "-IC:\msys64\home\Roli\ghc\libraries\integer-gmp\dist- install\build\include" "-IC:/msys64/home/Roli/ghc/rts/dist/build" "-IC:/msys64/home/Roli/ghc/includes" "-IC:/msys64/home/Roli/ghc/includes /dist-derivedconstants/header" "-O3" }}} I'll create a better test. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: RolandSenn Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TEST=T14452 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5318 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * owner: (none) => RolandSenn -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: RolandSenn Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TEST=T14452 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5318 Wiki Page: | Phab:D5398 -------------------------------------+------------------------------------- Changes (by RolandSenn): * status: new => patch * differential: Phab:D5318 => Phab:D5318 Phab:D5398 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: RolandSenn Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TEST=T14452 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5318 Wiki Page: | Phab:D5398 -------------------------------------+------------------------------------- Comment (by Tamar Christina <tamar@…>): In [changeset:"6090002e19d5c888c2eda0ce06dd84e3c46aa0c9/ghc" 6090002e/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="6090002e19d5c888c2eda0ce06dd84e3c46aa0c9" Improve test T14452 for Windows Summary: Under Windows all parameters to gcc are enclosed in quotes, opposite to Linux, where the quotes are missing. Therefore in the test, we remove all quotes in the stdout file with sed. Test Plan: make test TEST=T14452 Reviewers: osa1, hvr, bgamari, monoidal, Phyx, simonpj Reviewed By: Phyx Subscribers: rwbarton, carter GHC Trac Issues: #14452 Differential Revision: https://phabricator.haskell.org/D5398 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14452: `-optc-O3` getting shadowed by automatically injected -O flags -------------------------------------+------------------------------------- Reporter: hvr | Owner: RolandSenn Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TEST=T14452 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5318 Wiki Page: | Phab:D5398 -------------------------------------+------------------------------------- Changes (by Phyx-): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14452#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC