[Gdal-dev] Building with profile directed optimization

Seth Price seth at pricepages.org
Sat Jul 7 16:25:07 EDT 2007


I'm trying to build GDAL with GCC 4's profile directed optimization  
and I'm hitting some problems. It would be awesome if this sort of  
optimization could be incorperated into the build process. :) I'll  
outline the steps I'm going through and hopefully someone can point  
out what I'm doing wrong.

I start by adding '-fprofile-generate' to all flags. I'm not using  
any optimization here because it mangles the output code a bit and is  
not recommended.

export CXXFLAGS="-fprofile-generate"
export CPPFLAGS="-fprofile-generate"
export CFLAGS="-fprofile-generate"
export LDFLAGS="-fprofile-generate -lgcov"
./configure && make

Here is where the first problem occurs, this command needs to be  
altered to add the "-lgcov", then everything goes smooth.
/bin/sh /usr/local/gdal/gdal-1.4.2/libtool --mode=link  g++ -O1 - 
fprofile-generate -ljpeg -ltiff -lpng -lz  -ldl -lgcov   -L/usr/lib - 
lcurl -lssl -lcrypto -lz   -o libgdal.la /usr/local/gdal/gdal-1.4.2/ 
frmts/o/*.lo /usr/local/gdal/gdal-1.4.2/gcore/*.lo /usr/local/gdal/ 
gdal-1.4.2/port/*.lo /usr/local/gdal/gdal-1.4.2/alg/*.lo /usr/local/ 
gdal/gdal-1.4.2/ogr/ogrsf_frmts/o/*.lo ./ogr/ogrgeometryfactory.lo ./ 
ogr/ogrpoint.lo ./ogr/ogrcurve.lo ./ogr/ogrlinestring.lo ./ogr/ 
ogrlinearring.lo ./ogr/ogrpolygon.lo ./ogr/ogrutils.lo ./ogr/ 
ogrgeometry.lo ./ogr/ogrgeometrycollection.lo ./ogr/ 
ogrmultipolygon.lo ./ogr/ogrsurface.lo ./ogr/ogrmultipoint.lo ./ogr/ 
ogrmultilinestring.lo ./ogr/ogr_api.lo ./ogr/ogrfeature.lo ./ogr/ 
ogrfeaturedefn.lo ./ogr/ogrfeaturequery.lo ./ogr/ogrfeaturestyle.lo ./ 
ogr/ogrfielddefn.lo ./ogr/ogrspatialreference.lo ./ogr/ 
ogr_srsnode.lo ./ogr/ogr_srs_proj4.lo ./ogr/ogr_fromepsg.lo ./ogr/ 
ogrct.lo ./ogr/ogr_opt.lo ./ogr/ogr_srs_esri.lo ./ogr/ 
ogr_srs_pci.lo ./ogr/ogr_srs_usgs.lo ./ogr/ogr_srs_dict.lo ./ogr/ 
ogr_srs_panorama.lo ./ogr/swq.lo ./ogr/ogr_srs_validate.lo ./ogr/ 
ogr_srs_xml.lo ./ogr/ograssemblepolygon.lo ./ogr/ogr2gmlgeometry.lo ./ 
ogr/gml2ogrgeometry.lo \
     -rpath /usr/local/lib \
     -no-undefined \
     -version-info 12:2:11

Then I 'sudo make install' the libraries and run './exercise.sh' to  
hit all the code I use often. After that the profiling files have  
been produced. I can't use 'make clean' because it will erase the  
profiling files, so I use the following commands:
sudo find . -name \*.o -exec rm {} ";"
sudo find . -name \*.lo -exec rm {} ";"
sudo find . -name \*.a -exec rm {} ";"
sudo find . -name \*.la -exec rm {} ";"
sudo find . -name \*.lai -exec rm {} ";"
sudo find . -name \*.dylib -exec rm {} ";"

Now is the problem I'm stuck on. I can compile with '-fprofile-use',  
but I can't add any optimization (even '-O1') because I immediately  
get this error:
/bin/sh /usr/local/gdal/gdal-1.4.2/libtool --mode=compile g++ -Wall  - 
O1 -fprofile-use   -DOGR_ENABLED -O1 -fprofile-use -I/usr/local/gdal/ 
gdal-1.4.2/port  -c -o cpl_conv.o cpl_conv.cpp
  g++ -Wall -O1 -fprofile-use -DOGR_ENABLED -O1 -fprofile-use -I/usr/ 
local/gdal/gdal-1.4.2/port -c cpl_conv.cpp  -fno-common -DPIC - 
o .libs/cpl_conv.o
cpl_conv.cpp: In function 'void* CPLRealloc(void*, size_t)':
cpl_conv.cpp:194: error: corrupted profile info: number of executions  
for edge 6-7 thought to be -93808
cpl_conv.cpp:194: error: corrupted profile info: number of executions  
for edge 6--2 thought to be 320155
make[1]: *** [cpl_conv.o] Error 1
make: *** [port-target] Error 2

Does anyone have an idea what is causing this? If I add '-O1' to the  
first compile, I still get this error, so I don't think it's a  
mismatch. Ideas on how to proceed?
~Seth



More information about the Gdal-dev mailing list