This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Append original object file name to ThinLTO generated object file's name, so that it can be recorded in link map file.
Changes PlannedPublic

Authored by xushuangqing on Oct 19 2021, 11:03 PM.

Details

Summary

Problem

When I use ThinLTO, ThinLTOCodeGenerator will generate object file whose filename looks like this:

0.x86_64.thinlto.o
1.x86_64.thinlto.o
2.x86_64.thinlto.o
3.x86_64.thinlto.o

So when I use -map option during linking, the generated link map file will contain these object files. It looks like:

# Path: ...
# Arch: x86_64
# Object files:
[  0] linker synthesized
...
[ 10] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/0.x86_64.thinlto.o
[ 11] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/1.x86_64.thinlto.o
[ 12] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/2.x86_64.thinlto.o
[ 13] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/3.x86_64.thinlto.o
[ 14] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/4.x86_64.thinlto.o

# Sections:
# Address Size      Segment Section
...

# Symbols:
# Address Size      File  Name
...

# Dead Stripped Symbols:
#         Size      File  Name
...

If I want to figure out each source file's size in the binary file, the 0.x86_64.thinlto.o confuses me. It contains few information about the original source file.

Optimize

As filenames like 0.x86_64.thinlto.o are joint in ThinLTOCodeGenerator::writeGeneratedObject, we can append the original object file name to it.

So the file name would looks like:

[ 10] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/0.x86_64.ViewController.o0.thinlto.o
[ 11] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/1.x86_64.AppDelegate.o1.thinlto.o
[ 12] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/2.x86_64.main.o2.thinlto.o
[ 13] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/3.x86_64.SceneDelegate.o3.thinlto.o
[ 14] /Users/xushuangqing/Library/Developer/Xcode/DerivedData/XSQLTODemo-flxqbdftarzrkoeyxgvupfvnvbue/Build/Intermediates.noindex/XSQLTODemo.build/Release-iphonesimulator/XSQLTODemo.build/Objects-normal/x86_64/XSQLTODemo_lto.o/4.x86_64.libXSQStaticLib.a(XSQObject.o)4.thinlto.o

When we analyze the link map, we can figure out each source file's size in the binary file.

Diff Detail

Event Timeline

xushuangqing created this revision.Oct 19 2021, 11:03 PM
xushuangqing requested review of this revision.Oct 19 2021, 11:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2021, 11:03 PM
xushuangqing edited the summary of this revision. (Show Details)Oct 19 2021, 11:05 PM

Update unit test case.

steven_wu added a subscriber: davide.

The best solution might still be the linker to map the intermediate file to the original object file since the added file name here is still another level of indirection you need to figure out. @davide for his opinion.

Can you add a testcase?

The best solution might still be the linker to map the intermediate file to the original object file since the added file name here is still another level of indirection you need to figure out. @davide for his opinion.

That sounds like a reasonable solution to me.

Can you add a testcase?

The best solution might still be the linker to map the intermediate file to the original object file since the added file name here is still another level of indirection you need to figure out. @davide for his opinion.

Thank you for your suggestion. It sounds reasonable.
I should think about the solution again.

xushuangqing planned changes to this revision.Oct 23 2021, 9:18 AM