This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Fix several state persistence bugs
ClosedPublic

Authored by loladiro on Jan 7 2016, 7:31 AM.

Details

Summary

This fixes three bugs, in all of which state is not or incorrecly reset between
object (i.e. when reusing the same pass manager to create multiple object files)

  1. AttributeSection needs to be reset to nullptr, because otherwise the backend will try to emit into the old object file's attribute section causing a segmentation fault.
  2. MappingSymbolCounter needs to be reset, otherwise the second object file will start where the first one left off.
  3. The MCStreamer base class resets the Streamer's e_flags settings. Since EF_ARM_EABI_VER5 is set on streamer creation, we need to set it again after the MCStreamer was rest.

Also rename Reset (uppser case) to EHReset to avoid confusion with
reset (lower case).

Diff Detail

Repository
rL LLVM

Event Timeline

loladiro updated this revision to Diff 44211.Jan 7 2016, 7:31 AM
loladiro retitled this revision from to [ARM] Fix several state persistence bugs.
loladiro updated this object.
loladiro added a reviewer: rafael.
loladiro added a subscriber: llvm-commits.

Please, add comments to the reset methods, since they're all closely named.

Also, write up a better commit message, to explain what kind of bugs were you seeing.

Finally, the test, being a simple pass/fail, could also have some longer explanation of what you're not expecting to see here. This could help people later when they find bugs on that test for unrelated changes.

loladiro updated this revision to Diff 44342.Jan 8 2016, 11:09 AM

Address review comments by expanding some code comments.

loladiro updated this object.Jan 8 2016, 11:09 AM
loladiro updated this revision to Diff 44343.Jan 8 2016, 11:15 AM
loladiro updated this object.

Fix a minor formatting issue

Apart from the small comment, this looks good to me.

lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
1068 ↗(On Diff #44343)

Can't this be changed by a command line flag? Shouldn't we clear based on that?

loladiro added inline comments.Jan 12 2016, 5:15 AM
lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
1068 ↗(On Diff #44343)

I was basing this on https://github.com/llvm-mirror/llvm/blob/e5716c4e3ac95bb5f204390720af3a186814f2cb/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp#L1368, which looks unconditional to me. Is there a place where this gets reset later by a flag?

rengolin accepted this revision.Jan 12 2016, 5:26 AM
rengolin added a reviewer: rengolin.

LGTM. Thanks!

lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
1068 ↗(On Diff #44343)

Hum, it seems not. Whenever someone worries about that, a quick search for EF_ARM_EABI_VER5 will bring them here, and the solution will be whatever it's used there, too.

This revision is now accepted and ready to land.Jan 12 2016, 5:26 AM
This revision was automatically updated to reflect the committed changes.
psmith added a subscriber: psmith.Jan 14 2016, 6:24 AM

I think that there is still some state that is not properly reset. If I use a slightly more complicated test case derived from:
int data = 10;

int func(void)
{

return data;

}
clang -c -emit-llvm t.c --target=arm-none-eabi -mcpu=arm7tdmi -o t.bc
llvm-dis -o test.ll t.bc
llc -compile-twice -filetype=obj test.ll -o twice.o
Running the pass manager twice changed the output.
Writing the result of the second run to the specified output
To generate the one-run comparison binary, just run without
the compile-twice option

Looking at the object files it looks like the discrepancies are in the mapping symbols.

I think that this is caused by LastMappingSymbols retaining state across passes. In my local build adding LastMappingSymbols.clear() to void ARMELFStreamer::reset() appears to solve the problem.

I can also reproduce the problem with the AARCH64 backend, also mapping symbol related although I haven't attempted to fix that locally. Would you be able to take another look?

Thanks in advance

Peter