This is an archive of the discontinued LLVM Phabricator instance.

[llvm-profgen] Skip disassembling for PLT section
ClosedPublic

Authored by wlei on Dec 13 2021, 10:47 PM.

Details

Summary

Skip disassembling .plt section, then .plt section code will be treated as external code.

Diff Detail

Event Timeline

wlei created this revision.Dec 13 2021, 10:47 PM
wlei requested review of this revision.Dec 13 2021, 10:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2021, 10:47 PM
wlei updated this revision to Diff 394148.Dec 13 2021, 10:55 PM

Updating D115699: [llvm-profgen] Skip disassembling for PLT section

wenlei added inline comments.Dec 13 2021, 10:57 PM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

are these test changes expected?

wlei added inline comments.Dec 13 2021, 10:59 PM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
11–12

This will be fixed by https://reviews.llvm.org/D115550

76

Oh, sorry, it's the same to https://reviews.llvm.org/D115538, previously I removed by mistake. Let me removed this here.

wlei updated this revision to Diff 394150.Dec 13 2021, 11:00 PM

remove unrelated test case

wenlei added inline comments.Dec 14 2021, 12:33 AM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

If you put them in a stack, these earlier/unrelated changes won't show up.

But still.. why are the remaining test changes, are they all due to PLT?

hoy added inline comments.Dec 14 2021, 9:56 AM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

Good question. Do the counters changed refer to PLT calls?

llvm/tools/llvm-profgen/ProfiledBinary.cpp
557

Move this above the ShowDisassemblyOnly check?

wlei added inline comments.Dec 14 2021, 12:34 PM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

This patch is in the bottom of the patch stack. It appeared that those counter changes are all fixed by the following two patches. I guess it's due to the wrong leading external addr processing. let me confirm what's wrong.

wlei added inline comments.Dec 14 2021, 12:50 PM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

OK, it turned out that the PLT address is just the leading LBR's target, remembering before the two external fix, the whole samples will be ignored.

0x400540 is plt
400870 0x400870/0x400540/P/-/-/1  0x4008bf/0x400870/P/-/-/7  0x7f7448e88cc1/0x400875/P/-/-/1
llvm/tools/llvm-profgen/ProfiledBinary.cpp
557

objdump also print out ".plt" section, I was thinking to print a section name as a hint we have the ".plt" section there(the size is not empty, we just doesn't disassembly it's body). Otherwise people might misunderstand there is no ".plt" section

hoy added inline comments.Dec 14 2021, 12:54 PM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

I see. So the counters 5.1, 5.3 ... correspond to a call to the PLT entries right?

llvm/tools/llvm-profgen/ProfiledBinary.cpp
557

Makes sense, though I was thinking we'll probably use objdump to look at real disasm, and use llvm-profgen to dump only functions of interest.

wlei added inline comments.Dec 14 2021, 12:59 PM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

Nearby the call to PLT, the code after return from PLT.

range [0x400875, 0x4008bf]

400870:	e8 cb fc ff ff       	callq  400540 <rand@plt>
400875:	48 98                	cltq   
400877:	48 69 c8 1f 85 eb 51 	imul   $0x51eb851f,%rax,%rcx
40087e:	48 89 ca             	mov    %rcx,%rdx
400881:	48 c1 ea 3f          	shr    $0x3f,%rdx
400885:	48 c1 f9 26          	sar    $0x26,%rcx
400889:	01 d1                	add    %edx,%ecx
40088b:	69 c9 c8 00 00 00    	imul   $0xc8,%ecx,%ecx
400891:	29 c8                	sub    %ecx,%eax
400893:	89 04 ab             	mov    %eax,(%rbx,%rbp,4)
400896:	48 83 c5 01          	add    $0x1,%rbp
40089a:	48 81 fd c8 00 00 00 	cmp    $0xc8,%rbp
4008a1:	0f 84 69 ff ff ff    	je     400810 <main+0x30>
4008a7:	40 0f b6 c5          	movzbl %bpl,%eax
4008ab:	69 c0 cd 00 00 00    	imul   $0xcd,%eax,%eax
4008b1:	c1 e8 0a             	shr    $0xa,%eax
4008b4:	83 e0 fe             	and    $0xfffffffe,%eax
4008b7:	8d 04 80             	lea    (%rax,%rax,4),%eax
4008ba:	f7 d8                	neg    %eax
4008bc:	40 00 e8             	add    %bpl,%al
4008bf:	75 af                	jne    400870 <main+0x90>
hoy added inline comments.Dec 14 2021, 1:02 PM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

This is probably unimportant but I'm wondering why the counters don't come with a call target like

;CHECK: 5.1: rand@plt : 10

wlei added inline comments.Dec 14 2021, 1:22 PM
llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

Oh, because we rand@plt is not a function, remembering we set isFunctionEntry when dwarf name match symbol name, here it doesn't match.

hoy accepted this revision.Dec 14 2021, 2:36 PM

LGTM.

llvm/test/tools/llvm-profgen/inline-noprobe2.test
76

Gotcha, thanks for explanation.

This revision is now accepted and ready to land.Dec 14 2021, 2:36 PM
wenlei accepted this revision.Dec 14 2021, 4:13 PM

lgtm, thanks.

This revision was landed with ongoing or failed builds.Dec 14 2021, 4:42 PM
This revision was automatically updated to reflect the committed changes.