Closed Bug 1478623 Opened 8 years ago Closed 8 years ago

mpi_arm.c functions yield miscompilations when inlined by LTO

Categories

(NSS :: Libraries, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: glandium, Assigned: glandium)

References

Details

Attachments

(1 file, 2 obsolete files)

Bug 1477929 was an obvious build error, this one was only detected because it made Firefox crash at runtime. Details will be in the patch commit message.
While bug 1477929 fixed the obvious build failure, it still allowed the compiler to break things when it inlines the mpi_arm.c functions into its callers via LTO. The problem is that all those assembly blocks take a length as input in a register, and decrement that register. But the constraints are not explicit about those writes to the register, so the compiler may decide to reuse them as the original value for the length in code following the inlined code. It actually happily does so, which leads to interesting crashes.
Attachment #8995164 - Flags: review?(franziskuskiefer)
Comment on attachment 8995164 [details] [diff] [review] Add a r/w constraint to a_len in all asm blocks in mpi_arm.c Looks like this is not enough. Many Android tests still fail with this patch, while they don't if I add __attribute__((noinline)) to all these functions.
Attachment #8995164 - Flags: review?(franziskuskiefer)
While bug 1477929 fixed the obvious build failure, it still allowed the compiler to break things when it inlines the mpi_arm.c functions into its callers via LTO. The problem is that all those assembly blocks take a length as input in a register, and decrement that register. They also update both registers they're passed in with pointers, via post-indexed offsets on ldr and str. But the constraints are not explicit about those writes to the registers, so the compiler may decide to reuse them as if they had their original value in code following the inlined code. It actually happily does so, which leads to interesting crashes.
Attachment #8995164 - Attachment is obsolete: true
Attachment #8995466 - Flags: review?(franziskuskiefer)
Comment on attachment 8995466 [details] [diff] [review] Add r/w constraints to modified registers to asm blocks in mpi_arm.c Review of attachment 8995466 [details] [diff] [review]: ----------------------------------------------------------------- It would be great to have a little more context in the patch here. Can you put this on phabricator?
Attachment #8995466 - Flags: review?(franziskuskiefer)
How would phabricator make a difference here? The patch has all the same information I'd put there.
Oh, more patch context, as in -U8. I don't have arcanist, so phabricator wouldn't help there anyways. I can update the patch to have more context lines, though.
Attachment #8995466 - Attachment is obsolete: true
Attachment #8995897 - Flags: review?(franziskuskiefer)
Blocks: android-lto
Comment on attachment 8995897 [details] [diff] [review] Add r/w constraints to modified registers to asm blocks in mpi_arm.c Review of attachment 8995897 [details] [diff] [review]: ----------------------------------------------------------------- Looks good to me (with my limited ARM assembly foo). Thanks!
Attachment #8995897 - Flags: review?(franziskuskiefer) → review+
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → 3.39
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: