[llvm-dev] Question about the example of link time optimization

Fangrui Song via llvm-dev llvm-dev at lists.llvm.org
Sun Oct 11 14:15:22 PDT 2020


On 2020-10-11, Florian Hahn via llvm-dev wrote:
>
>
>> On Oct 10, 2020, at 11:39, Enna1 via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>>
>> Hi all!
>>
>> I played around with the LLVM LTO
>> example(https://llvm.org/docs/LinkTimeOptimization.html#example-of-link-time-optimization),
>> but got some questions.
>>
>> As the document says, the function foo4 should be removed. However,
>> under my test, function foo4 is not removed.
>> I have tried both gnu ld with LLVMgold.so and lld, neither of them
>> removes function foo4.
>>
>> I compile and run the example as instructed:
>> % clang -flto -c a.c -o a.o        # <-- a.o is LLVM bitcode file
>> % clang -c main.c -o main.o        # <-- main.o is native object file
>
>
>I think you also need to build main.c with -flto.
>
>Cheers,
>Florian

More details: main.o is a regular object file. The symbols referenced
(foo4) need to be exported by LTO: the 'VisibileToRegularObj' property
of foo4 is true because foo4's isUsedInRegularObj is true.


More information about the llvm-dev mailing list