Perl Inline::C default flags
Asked Answered
F

1

7

I made a module using Inline::C and I noticed some unexpected performance discrepancies between running it on the host MacOS vs a guest Linux VM. Looking into it, it was due to the default C compiler flags being different. On MacOS they appear to be:

-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -O3   -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\"

Vs on Centos 7:

 -fPIC -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -O2   -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\"

The main difference for my code is O3 vs O2, so I looked into the Inline docs and used:

use Inline (C => Config => ccflags => '-O3');

To explicitly specify -O3. Well, the result is that -O3 -O2 is applied that way, so specifying ccflags does not overwrite the default, it just adds before them, which in the end does not have any effect. Any idea where the default comes from and/or how to overwrite it to specify the optimization level that I want.

Flats answered 24/10, 2019 at 13:16 Comment(1)
Re "Any idea where the default comes from", It uses what was used to build the perl being used, as returned by perl -V:ccflags and use Config qw( %Config ); $Config{ccflags}Filomenafiloplume
T
6

It appears as though adding the optimize configuration option may do what you want. Here's a very short example with the output before adding optimize => '-O3' and after:

use warnings;
use strict;

use Inline 'C';

use Inline C => 'Config',
    build_noisy => 1,
    force_build => 1,
    optimize => '-O3',
;

print add(5, 6);

__END__
__C__

int add (int x, int y){
    return(x + y);
}

Here's the output (snipped for brevity):

Before:

cc -c -I"/home/steve/scratch/inline" -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2

After:

cc -c -I"/home/steve/scratch/inline" -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O3

...on Linux Mint 18.3.

The default comes from $Config{optimize}, which is stored as a read-only default at the time perl was compiled/built on the system.

Thermotherapy answered 24/10, 2019 at 14:30 Comment(3)
You are correct, thanks! Any idea where the default is pulled from and is different on each machine?Flats
The Inline::C docs refer to the MakeMaker ccflags and optimize settings. These are the same except they have different defaults and are positioned differently in the resulting argument list.Sheathbill
On my system, it appears this default comes from $Config{optimize}, which is stored as a read-only default at the time perl was compiled/built on the system.Thermotherapy

© 2022 - 2024 — McMap. All rights reserved.