Author Topic: GCC configuration - runtime options...  (Read 4708 times)

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1135
  • Karma: +24/-0
    • View Profile
GCC configuration - runtime options...
« on: February 21, 2018, 03:22:04 am »
I have the RPM package of GCC 4.9.2 installed here.

As I experimented with the optimal settings for the NBench benchmark I tried quite a few different opimization flags. Well, I am not back to much simpler stuff...literally "Hello World!"...except that I am using the simple stuff to learn a lot more about the whole GNU toolset configuration on our platform.

So here is the question, given a simple compilation with the -v (verbose) option I get a dump of the built-in flags:

Code: [Select]
[G:\code\source\GCC]gcc -v hello.c -o hello.exe
Using built-in specs.
COLLECT_GCC=gcc
Target: i386-pc-os2-emx
Configured with: ../configure --prefix=/@unixroot/usr --with-sysroot=/@unixroot --enable-shared --enable-languages=c,c++ --enable-frame-pointer --with-gnu-as --disable-bootstrap --disable-multilib --disable-libstdcxx-pch --enable-threads
Thread model: os2
gcc version 4.9.2 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 'hello.exe' '-mtune=i386' '-march=i386'
G:/usr/bin/../libexec/gcc/i386-pc-os2-emx/4.9.2/cc1 -quiet -v -iprefix G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/ hello.c -quiet -dumpbase hello.c -mtune=i386 -march=i386 -auxbase hello -version -o G:\var\tmp/cceQCIJv.s
GNU C (GCC) version 4.9.2 (i386-pc-os2-emx)
        compiled by GNU C version 4.7.3, GMP version 5.0.2, MPFR version 3.1.0,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/../../../../i386-pc-os2-emx/include"
ignoring nonexistent directory "/@unixroot/usr/local/include"
ignoring nonexistent directory "G:/usr/lib/gcc/../../lib/gcc/i386-pc-os2-emx/4.9.2/../../../../i386-pc-os2-emx/include"
#include "..." search starts here:
#include <...> search starts here:
 G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/include
 G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/include-fixed
 G:/usr/lib/gcc/../../lib/gcc/i386-pc-os2-emx/4.9.2/include
 G:/usr/lib/gcc/../../lib/gcc/i386-pc-os2-emx/4.9.2/include-fixed
 /@unixroot/usr/include
End of search list.
GNU C (GCC) version 4.9.2 (i386-pc-os2-emx)
        compiled by GNU C version 4.7.3, GMP version 5.0.2, MPFR version 3.1.0,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 40cb22df062740f747e010b72b1ced6d
COLLECT_GCC_OPTIONS='-v' '-o' 'hello.exe' '-mtune=i386' '-march=i386'
 as -v --traditional-format -o G:\var\tmp/ccokR79z.o G:\var\tmp/cceQCIJv.s
GNU assembler version 2.27 (i386-pc-os2-emx) using BFD version (GNU Binutils) 2.27
COMPILER_PATH=G:/usr/bin/../libexec/gcc/i386-pc-os2-emx/4.9.2/;G:/usr/bin/../libexec/gcc/;G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/../../../../i386-pc-os2-emx/bin/
LIBRARY_PATH=G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/;G:/usr/bin/../lib/gcc/;G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/../../../;/@unixroot/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'hello.exe' '-mtune=i386' '-march=i386'
 ld.exe -o hello.exe G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/../../../crt0.o -LG:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2 -LG:/usr/bin/../lib/gcc -LG:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/../../.. -L/@unixroot/usr/lib G:\var\tmp/ccokR79z.o -lgcc_so_d -lc_alias -lc_dll -los2 -lgcc_so_d -lc_alias -lc_dll -los2 -
lgcc_so_d -lc_alias -lc_dll -los2 -lgcc_so_d -lc_alias -lc_dll -los2

Now what I am trying to figure out is where the heck the seeded COLLECT_GCC_OPTIONS comes from? Heck, compiling for a i386 architecture, even in a very simple program is...well, appaling...LOL, c'mon...no setup today should be defaulting to this...!!!

Dave Yeo

  • Hero Member
  • *****
  • Posts: 3664
  • Karma: +77/-0
    • View Profile
Re: GCC configuration - runtime options...
« Reply #1 on: February 21, 2018, 03:57:40 am »
They're just the defaults, probably mostly hard coded at build time. Which part are you wondering about?
For extra fun, try
Code: [Select]
gcc -v -E hello.c -o hello.exeand look at hello.exe in a text editor. Then do the same by replacing the -E with -S.
« Last Edit: February 21, 2018, 04:33:19 am by Dave Yeo »

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1135
  • Karma: +24/-0
    • View Profile
Re: GCC configuration - runtime options...
« Reply #2 on: February 21, 2018, 05:01:31 am »
Hey Dave!

...Which part are you wondering about?...

Ahh...the dreaded '-mtune=i386' '-march=i386' options. Even when I set the CFLAGS at CLI (SET CFLAGS='-march=i686 -O2 -pipe') the gcc execution in that same session does not appear to pick these up...so is it that gcc on it's own does not actually use the env variable and that it's sole use is for the make utility?

...For extra fun, try
Code: [Select]
gcc -v -E hello.c -o hello.exeand look at hello.exe in a text editor. Then do the same by replacing the -E with -S.

Good stuff...I got there in a slightly different way, be executing the cpp pre-processor and then the as assembler. Still...good stuff, especially the pre-processor output, it does give you the final look at the complete source tree, or at least the fully resolved path to all your includes.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 3664
  • Karma: +77/-0
    • View Profile
Re: GCC configuration - runtime options...
« Reply #3 on: February 21, 2018, 07:32:09 am »
Hey Dave!

...Which part are you wondering about?...

Ahh...the dreaded '-mtune=i386' '-march=i386' options. Even when I set the CFLAGS at CLI (SET CFLAGS='-march=i686 -O2 -pipe') the gcc execution in that same session does not appear to pick these up...so is it that gcc on it's own does not actually use the env variable and that it's sole use is for the make utility?

Yes that's only for make (and configure sometimes). Try SET GCCOPT='march=i686 -O2 -pipe' (might need double quotes).


Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1135
  • Karma: +24/-0
    • View Profile
Re: GCC configuration - runtime options...
« Reply #4 on: February 22, 2018, 12:02:23 am »
...Try SET GCCOPT='march=i686 -O2 -pipe' (might need double quotes)...

It worked...sort of...seems that multiple flags actually cause a problem, here is what happens:

1) issue : SET GCCOPT="-march=i686 -O2 -pipe"
2) compile : gcc -v hello.c -o hello.exe
3) what comes back is :

Code: [Select]
Using built-in specs.
COLLECT_GCC=gcc
Target: i386-pc-os2-emx
Configured with: ../configure --prefix=/@unixroot/usr --with-sysroot=/@unixroot --enable-shared --enable-languages=c,c++ --enable-frame-pointer --with-gnu-as --disable-bootstrap --disable-multilib --disable-libstdcxx-pch --enable-threads
Thread model: os2
gcc version 4.9.2 (GCC)
COLLECT_GCC_OPTIONS='-march=i686 -O2 -pipe' '-v' '-o' 'hello.exe'
 G:/usr/bin/../libexec/gcc/i386-pc-os2-emx/4.9.2/cc1 -quiet -v -iprefix G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/ hello.c -quiet -dumpbase hello.c -march=i686 -O2 -pipe -auxbase hello -version -o G:\var\tmp/ccxiDPJ7.s
GNU C (GCC) version 4.9.2 (i386-pc-os2-emx)
        compiled by GNU C version 4.7.3, GMP version 5.0.2, MPFR version 3.1.0,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/../../../../i386-pc-os2-emx/include"
ignoring nonexistent directory "/@unixroot/usr/local/include"
ignoring nonexistent directory "G:/usr/lib/gcc/../../lib/gcc/i386-pc-os2-emx/4.9.2/../../../../i386-pc-os2-emx/include"
#include "..." search starts here:
#include <...> search starts here:
 G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/include
 G:/usr/bin/../lib/gcc/i386-pc-os2-emx/4.9.2/include-fixed
 G:/usr/lib/gcc/../../lib/gcc/i386-pc-os2-emx/4.9.2/include
 G:/usr/lib/gcc/../../lib/gcc/i386-pc-os2-emx/4.9.2/include-fixed
 /@unixroot/usr/include
End of search list.
hello.c:1:0: error: bad value (i686 -O2 -pipe) for -march= switch
 // 'Hello World' example
 ^
GNU C (GCC) version 4.9.2 (i386-pc-os2-emx)
        compiled by GNU C version 4.7.3, GMP version 5.0.2, MPFR version 3.1.0,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096

So the error "hello.c:1:0: error: bad value (i686 -O2 -pipe) for -march= switch" implies that the whole GCCOPT is perceived to be a single value, you can confirm that since "COLLECT_GCC_OPTIONS='-march=i686 -O2 -pipe' '-v' '-o' 'hello.exe'" shows it as such as well.

I'll investigate passing multiple values next...in the bigger scheme of things this is probably not all that important given that the more complex stuff would be done through a makefile anyways. Still, this type of stuff teaching you a bunch about the innner-workings, so some value there anywayss.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 3664
  • Karma: +77/-0
    • View Profile
Re: GCC configuration - runtime options...
« Reply #5 on: February 22, 2018, 12:26:28 am »
Seems to be a shell issue. Using sh, I did
Code: [Select]
export GCCOPT='-O2 -pipe -march=i686'
gcc -v hello.c -o hello.exe
and got
Code: [Select]
COLLECT_GCC_OPTIONS='-O2' '-pipe' '-march=i686' '-v' '-o' 'hello.exe'and a working hello.exe.
Not sure how to set up the environment variable under cmd.exe with multiple arguments.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 3664
  • Karma: +77/-0
    • View Profile
Re: GCC configuration - runtime options...
« Reply #6 on: February 22, 2018, 12:41:20 am »
Under 4os2, doing
Code: [Select]
set GCCOPT=-march=i686 -pipe -O2also works.
Hmm, under cmd.exe, this seems to be fine
Code: [Select]
set GCCOPT="-march=i686" "-pipe" "O2"giving
Code: [Select]
COLLECT_GCC_OPTIONS='-march=i686' '-pipe' '-O2' '-v' '-o' 'hello.exe'

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1135
  • Karma: +24/-0
    • View Profile
Re: GCC configuration - runtime options...
« Reply #7 on: February 22, 2018, 03:52:44 am »
...Hmm, under cmd.exe, this seems to be fine
Code: [Select]
set GCCOPT="-march=i686" "-pipe" "O2"giving
Code: [Select]
COLLECT_GCC_OPTIONS='-march=i686' '-pipe' '-O2' '-v' '-o' 'hello.exe'

Yup, that did the trick...I did not think that just listing the individual flags with double-quotes around each one and no concatenation character of any sorts in-between would work...but heck, that is our answer! Thank you.