Why can't GCC inline functions with -flto optimization and profile optimization in a static library?

I am using GCC version 4.7.2. I am creating a static library with two files "ctest1.cpp" and "ctest2.cpp".

ctest1.cpp

#include <stdio.h>
#include "ctest2.h"
void ctest1()
{
        printf("In ctest1");
        ctest2();
}

ctest2.cpp

#include <stdio.h>
void ctest2()
{
        printf("In ctest2");
}

The header file "ctest2.h" is,

void ctest2();

And similarly, the file "ctest1.h",

void ctest1();

This static library is associated with the following main file "in_test.cpp",

in_test.cpp

#include <stdio.h>
#include "ctest1.h"

using namespace std;

int main()
{
   ctest1();
   printf("InMain\n");
   return 0;
}

I expected that after providing the correct feedback and turning on -flto, the compiler would have to embed the call to the ctest2 () function in the file "ctest1.cpp" (and even call ctest1 () in "in_test.cpp"), but it is not. Following are the following compilation steps:

g++ -Wall -c -g -O3 -fprofile-generate -ftest-coverage ctest2.cpp ctest1.cpp
ar -rcsv libtest.a ctest2.o ctest1.o
g++ -Wall -g -O3 -fprofile-generate -ftest-coverage in_test.cpp -o checking libtest.a

For training, I run the executable file n times, then

g++ -Wall -c -g -O3 -flto -fwhole-program -fprofile-use ctest2.cpp ctest1.cpp
ar -rcsv libtest.a ctest2.o ctest1.o
g++ -Wall -g -O3 -flto -fwhole-program -fprofile-use in_test.cpp -o checking libtest.a

-fuse-linker-plugin, , . , , ( flto ), . . , . -, , , ?

+4

Source: https://habr.com/ru/post/1584470/


All Articles