WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Compiler flags  (Read 2593 times)

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Compiler flags
« on: March 05, 2016, 11:36:09 AM »
Is there a reason to prefer setting CC/CCX as I commonly see in the x86_64 example:

CC="gcc -flto -fuse-linker-plugin -mtune=generic -Os -pipe"                                                                               
CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

over setting CFLAGS/CXXFLAGS as I commonly see in the x86 example:

CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe"

It seems like if we could be consistent, then we could get closer to common build scripts using something like this (based on what I could mine from the forums):
Code: [Select]
case $(uname -m) in
  i686|x86)
    CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
    CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe"
    ;;
  x86_64)
    CFLAGS="-flto -fuse-linker-plugin -mtune=generic -Os -pipe"                                                                               
    CXXFLAGS="-flto -fuse-linker-plugin -mtune=generic -Os -pipe -fno-exceptions -fno-rtti"
    ;;
  armv6*)
    CFLAGS="-march=armv6 -mcpu=arm1176jzf-s -mfpu=vfp"
    CXXFLAGS="-march=armv6 -mcpu=arm1176jzf-s -mfpu=vfp"
    ;;
  armv7*)
    CFLAGS="-march=armv7-a -mtune=cortex-a7 -mfpu=neon"
    CXXFLAGS="-march=armv7-a -mtune=cortex-a7 -mfpu=neon"
    ;;
esac

And why would we need to specifiy the compiler directly versus letting the configure script find it? Is this an issue on some platforms?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11036
Re: Compiler flags
« Reply #1 on: March 05, 2016, 11:49:07 AM »
The setting of CC/CXX is to guarantee the LTO flags get passed to all invocations. In some packages, C(XX)FLAGS do not appear in the link command, which would produce bad results when LTO is in use.
The only barriers that can stop you are the ones you create yourself.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Compiler flags
« Reply #2 on: March 05, 2016, 11:56:46 AM »
Is there a reason not to use CC/CXX on all platforms? If there is an issue in some source packages build scripts not passing flags correctly wouldn't the issue be the same on all platforms given we're using the same source for all of them?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11036
Re: Compiler flags
« Reply #3 on: March 05, 2016, 01:30:23 PM »
The issue would affect all platforms, but LTO is only advised on x86_64 right now (it's the most used platform for it, I guess). Without LTO, the normal flags should be used.
The only barriers that can stop you are the ones you create yourself.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Compiler flags
« Reply #4 on: March 05, 2016, 03:40:05 PM »
OK, but that doesn't really answer the broader question. Why not do something like this if we want to be sure that the flags we want for each platform are getting applied consistently for each package?
Code: [Select]
case $(uname -m) in
  i686|x86)
    CC="gcc -march=i486 -mtune=i686 -Os -pipe"
    CXX="g++ -march=i486 -mtune=i686 -Os -pipe"
    ;;
  x86_64)
    CC="gcc -flto -fuse-linker-plugin -mtune=generic -Os -pipe"                                                                               
    CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe -fno-exceptions -fno-rtti"
    ;;
  armv6*)
    CC="gcc -march=armv6 -mcpu=arm1176jzf-s -mfpu=vfp"
    CXX="g++ -march=armv6 -mcpu=arm1176jzf-s -mfpu=vfp"
    ;;
  armv7*)
    CC="gcc -march=armv7-a -mtune=cortex-a7 -mfpu=neon"
    CXX="g++ -march=armv7-a -mtune=cortex-a7 -mfpu=neon"
    ;;
esac