This is an archive of the discontinued LLVM Phabricator instance.

Fix a bug that MIPS thunks can overwrite other section contents.
ClosedPublic

Authored by ruiu on Jun 21 2016, 10:33 PM.

Details

Summary

Peter Smith found while trying to support thunk creation for ARM that
LLD sometimes creates broken thunks for MIPS. The cause of the bug is
that we assign file offsets to input sections too early. We need to
create all sections and then assign section offsets because appending
thunks changes file offsets for all following sections.

This patch separates the pass to assign file offsets from thunk
creation pass. This effectively reverts r265673.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu updated this revision to Diff 61505.Jun 21 2016, 10:33 PM
ruiu retitled this revision from to Fix a bug that MIPS thunks can overwrite other section contents..
ruiu updated this object.
ruiu added reviewers: rafael, peter.smith.
ruiu added a subscriber: llvm-commits.
ruiu updated this revision to Diff 61509.Jun 21 2016, 11:26 PM
  • Removed unused functions.
peter.smith edited edge metadata.Jun 22 2016, 3:11 AM

Given that this is effectively a reversion, I won't comment on the specifics as I'm sure there will be another attempt made building from the original base.

Separating the offset updates does make it easier to implement interworking thunks as it does give the freedom to add thunks to any InputSection so I'm in favour of making the change.

It is definitely a good idea to add the test in the opposite order.

In the longer term I think that it would be a good idea to work towards a separation of:

  • Linker added content that does not require an address to know if it is needed and where it needs to be generated (interworking thunks and PLT entries). Only a single pass through relocations is needed.
  • Linker added content that requires an address to know if it is needed and where it needs to be generated (range extension thunks). We don't have any of these implemented now.
  • Operations that are either non-idempotent or expensive to update that need final addresses, but don't alter the sizes of any section.
atanasyan accepted this revision.Jun 22 2016, 4:02 AM
atanasyan edited edge metadata.

LGTM Thanks!

This revision is now accepted and ready to land.Jun 22 2016, 4:02 AM
This revision was automatically updated to reflect the committed changes.