This is an archive of the discontinued LLVM Phabricator instance.

[LLVM][XRAY][MIPS] Support xray on mips/mipsel/mips64/mips64el
ClosedPublic

Authored by slthakur on Dec 12 2016, 9:43 PM.

Details

Summary

Adds support for xray instrumentation on mips for both 32-bit and 64-bit.

Diff Detail

Repository
rL LLVM

Event Timeline

slthakur updated this revision to Diff 81178.Dec 12 2016, 9:43 PM
slthakur retitled this revision from to [XRAY][MIPS] Support xray on mips/mipsel.
slthakur updated this object.
slthakur added a reviewer: dberris.
slthakur set the repository for this revision to rL LLVM.
slthakur added subscribers: jaydeep, sdardis.
dberris requested changes to this revision.Dec 12 2016, 10:46 PM
dberris edited edge metadata.
dberris added a subscriber: rSerge.

Thanks for the patch!

I'm not an expert on the mips assembly, so I'll defer to someone else who is (or if you are confident this is "doing the right thing" already, then I'm happy to defer to your judgment here).

@rSerge ran into the same issue I comment on later, we probably need to think about refactoring that logic into a common function higher up in the base class just to consolidate the logic for emitting ELF tables. I'm happy to wait to do the consolidation later, but will ask that you make that change here as well.

lib/Target/Mips/MipsAsmPrinter.cpp
1103–1105

You probably want to do something similar to what we do in x86 where we determine whether the function being instrumented is in a comdat group (and handle that case appropriately). I think we already do that for arm7 (no thumb) and aarch64 too.

This revision now requires changes to proceed.Dec 12 2016, 10:46 PM
slthakur updated this revision to Diff 81219.Dec 13 2016, 5:36 AM
slthakur edited edge metadata.
slthakur marked an inline comment as done.

Added handling of the case where function being instrumented is in a comdat group, as suggested.

sdardis requested changes to this revision.Dec 13 2016, 6:24 AM
sdardis added a reviewer: sdardis.

Some comments inlined. I've highlighted a potential pic bug regarding the clobbering of $gp.

This needs some more tests, such as functions calling functions local to the TU, and functions calling external functions, ensuring that gp is not clobbering by accident.

lib/Target/Mips/MipsAsmPrinter.cpp
1054

This should be const unsigned NoopsInSledCount.

1067

You also need to save t9 here for pic code.

If we have something like:

unsigned short g(unsigned b);

unsigned short m (unsigned short a) {
  return g(a);
}

unsigned short g (unsigned b) {
  return b + b + 5;
}

The prologue of m will contain:

lui $2, %hi(_gp_disp)
addiu $2, $2, %lo(_gp_disp)
addu $2, $2, $25

calculating the gp for this function group. Without saving t9 on entry, after
xray has performed whatever actions it requires, t9 will point to the xray
function stub, and $gp will be wrong for this function.

Please add the example as a test.

1069

You're adding the lower half of __xray_FunctionEntry/Exit to t9 here, not the upper half.

Secondly, looking at the corresponding implementation in compiler rt, this should be ORI, as if bit 15 of the address of __xray_FunctionEntry is set, that half will be sign extended.

This revision now requires changes to proceed.Dec 13 2016, 6:24 AM
slthakur updated this revision to Diff 81373.Dec 14 2016, 6:04 AM
slthakur edited edge metadata.
slthakur marked 3 inline comments as done.

Addressed review comments

dberris accepted this revision.Dec 14 2016, 10:15 PM
dberris edited edge metadata.

Thanks again for doing this @slthakur! I'd suggest you wait for LGTM from @sdardis before landing.

sdardis requested changes to this revision.Dec 20 2016, 4:24 PM
sdardis edited edge metadata.

I'm being hit with an llvm assertions when trying to use the integrated assembler about the function size when not being absolute.

Can you repost the patch with comments addressed, and take a quick look to see if basic sample programs can be instrumented?

Thanks,
Simon

lib/Target/Mips/MipsAsmPrinter.cpp
1070

Ignore this, I'm being hit by phabricator bugs.

1078

I am somewhat sure about this in the case of the produced being non-pic as the gp pointer doesn't (AFAIK) need be changed. Add a FIXME: Is this correct for the static relocation model.

1083

corretly -> correctly.

1094–1097

This is incorrect. GAS will build a pc relative relocation with the value <func> + 0x24, which will overflow. Instead use the temporary symbol, Target, and use that instead.

Also, update the comment on lines 1089 to reflect that we're branching to a label, not a pc-relative offset. Likewise for the below branches,

1110

After testing this, you need to emit the label Target before the addiu. Otherwise we get a SEGV fault.

test/CodeGen/Mips/xray-mips-attribute-instrumentation.ll
8

See my comment above about branching to labels.

This revision now requires changes to proceed.Dec 20 2016, 4:24 PM
slthakur updated this revision to Diff 82201.Dec 20 2016, 10:18 PM
slthakur retitled this revision from [XRAY][MIPS] Support xray on mips/mipsel to [LLVM][XRAY][MIPS] Support xray on mips/mipsel/mips64/mips64el.
slthakur updated this object.
slthakur edited edge metadata.

Addressed review comments. I've also added mips64 support for xray along with this change since the patch was ready.

slthakur updated this revision to Diff 82202.Dec 20 2016, 10:26 PM
slthakur edited edge metadata.
slthakur marked 5 inline comments as done.

Increased patch context.

I'm being hit with an llvm assertions when trying to use the integrated assembler about the >function size when not being absolute.

Can you repost the patch with comments addressed, and take a quick look to see if basic sample >programs can be instrumented?

Sure, Ill compile some more examples with the integrated assembler and check if I can reproduce the assertion.

sdardis added inline comments.Dec 21 2016, 3:50 AM
lib/Target/Mips/MipsAsmPrinter.cpp
1102–1105

This sequence needs to be:

lui t9, // %highest(__xray_FunctionEntry/Exit)
ori t9, // %higher(__xray_FunctionEntry/Exit)
dsll t9, t9, 16
ori t9, t9, // %hi(__xray_FunctionEntry/Exit)
dsll t9, t9, 16
ori t9, t9, // %lo(__xray_FunctionEntry/Exit)
slthakur updated this revision to Diff 82233.Dec 21 2016, 5:50 AM
slthakur marked an inline comment as done.

Addressed review comments.

slthakur updated this revision to Diff 88317.Feb 13 2017, 11:10 PM

Addressed review comments.

sdardis accepted this revision.Feb 14 2017, 3:32 AM

LGTM. Please see my inlined comment about the test case - it hits a bug in llvm-objdump.

test/CodeGen/Mips/xray-section-group.ll
2–13

Running this with ToT shows a bug in llvm-objdump when using -disassemble-all. It attempts to disassemble the string table which is 173 bytes long as instructions, so when it attempts to disassemble the "instruction" starting at offset 172, it crashes on an invalid array access.

For the moment, use llvm-readobj to determine the presence of sections and their corresponding flags.

This revision is now accepted and ready to land.Feb 14 2017, 3:32 AM
slthakur updated this revision to Diff 88501.EditedFeb 15 2017, 2:46 AM
slthakur marked an inline comment as done.

Using llvm-readobj instead of llvm-objdump in test xray-section-group.ll

slthakur closed this revision.Feb 15 2017, 3:10 AM

Committed in revision 295164.