This is an archive of the discontinued LLVM Phabricator instance.

[Thumb] Baseline test for incorrect relocation with -ffunction-sections
ClosedPublic

Authored by arichardson on Aug 8 2022, 1:21 PM.

Details

Summary

When calling a dso_local function, we end up creating a call against the
.Lfoo$local label. This might be converted to a relocation against a
section if there is such a matching one (which is a lot more likely with
-ffunction-sections) and then the LSB (Thumb flag) will be lost.

I originally noticed this with Morello LLVM (which uses the LSB to indicate
a C64 encoding mode function). The missing LSB meant that ld.lld would
insert a thunk that switches encoding mode which then resulted in errors
at runtime since functions were being entered with the wrong encoding mode.
Since the Morello backend is not upstream, I looked if any in-tree
backends could also be affected by the missing STT_FUNC flag and noticed
that Thumb is also affected (although the bug is rather difficult to
trigger - it currently requires inline assembly).

Diff Detail

Event Timeline

arichardson created this revision.Aug 8 2022, 1:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 1:21 PM
arichardson requested review of this revision.Aug 8 2022, 1:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 1:21 PM
MaskRay accepted this revision.Aug 8 2022, 4:54 PM

LGTM.

llvm/test/CodeGen/ARM/thumb-function-section-reloc.ll
52

switch to opaque pointers (ptr)

This revision is now accepted and ready to land.Aug 8 2022, 4:54 PM
This revision was landed with ongoing or failed builds.Aug 9 2022, 2:55 AM
This revision was automatically updated to reflect the committed changes.
arichardson marked an inline comment as done.