'How can let new version of gcc/g++ auto inline function from multi files?

I remember clearly that when compiling multi files from gcc/g++ with -O3 at one time, it will automatically inline the function from other files.

About a few years ago, I compiled two files:

test.c:

void kkk();
int main()
{
    kkk();
    return 0;
}

test2.c:

void kkk()
{}

with:

gcc -O3 test.c test2.c -o a1.out

gcc -O3 -c test.c
gcc -O3 -c test2.c
gcc test.o test2.o -o a2.out


md5sum a1.out
md5sum a2.out

the md5s of a1.out and a2.out were different.

and compile with:

gcc -O3 test.c -S -o test_single.s

gcc -O3 test.c test2.c -S

The result of test.s and test_single.s were different. In test.s it will not call kkk but inline it. But in test_single.s it will call the kkk.

I found this in https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

The compiler performs optimization based on the knowledge it has of the program. Compiling multiple files at once to a single output file mode allows the compiler to use information gained from all of the files when compiling each of them.

But recently I recompiled the two files with gcc-11 and gcc-12. The result is same, it will always call kkk function even thougth compile test.c and test2.c together. The g++ compiler is the same too.

I don't know where I make mistakes, I can't see auto inline in multi-files again now, should I turn on some of compiler flags? Can any one help me? Thanks very much.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source