This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Fix wrapping personality symbol on ARM
ClosedPublic

Authored by smeenai on Sep 27 2021, 8:15 PM.

Details

Summary

The ARM backend was explicitly setting global binding on the personality
symbol. This was added without any comment in a7ec2dcefd954, which
introduced EHABI support (back in 2011). None of the other backends do
anything equivalent, as far as I can tell.

This causes problems when attempting to wrap the personality symbol.
Wrapped symbols are marked as weak inside LTO to inhibit IPO (see
https://reviews.llvm.org/D33621). When we wrap the personality symbol,
it initially gets weak binding, and then the ARM backend attempts to
change the binding to global, which causes an error in MC because of
attempting to change the binding of a symbol from non-global to global
(the error was added in https://reviews.llvm.org/D90108).

Simply drop the ARM backend's explicit global binding setting to fix
this. This matches all the other backends, and a large internal
application successfully linked and ran with this change, so it
shouldn't cause any problems. Test via LLD, since wrapping is required
to exhibit the issue.

Diff Detail

Event Timeline

smeenai created this revision.Sep 27 2021, 8:15 PM
smeenai requested review of this revision.Sep 27 2021, 8:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2021, 8:15 PM
MaskRay added inline comments.Sep 27 2021, 11:31 PM
lld/test/ELF/arm-lto-wrap-personality.ll
1 ↗(On Diff #375463)

Move the test to ELF/lto/ and remove lto- from the filename

10 ↗(On Diff #375463)

%t.bc

11 ↗(On Diff #375463)

%t.bc -o %t.so

Then add llvm-readelf -s %t.so | FileCheck %s and check the binding of ther personality symbol.

We should make better use of a test, not just testing that something doesn't crash.

smeenai updated this revision to Diff 375610.Sep 28 2021, 9:24 AM

Address comments

smeenai marked 3 inline comments as done.Sep 28 2021, 9:27 AM

Thanks for the review.

In following your suggestion to check the binding, I noticed that the original symbol (the target of the wrapping) is retaining its weak binding, which seems counter to the intent of D33621. That isn't related to this patch (all wrapped symbols will exhibit this behavior, as will the personality symbol on all other backends), and I imagine it won't affect most uses of --wrap because everyone will reference the wrapped symbol and not the original.

Thanks for the review.

In following your suggestion to check the binding, I noticed that the original symbol (the target of the wrapping) is retaining its weak binding, which seems counter to the intent of D33621. That isn't related to this patch (all wrapped symbols will exhibit this behavior, as will the personality symbol on all other backends), and I imagine it won't affect most uses of --wrap because everyone will reference the wrapped symbol and not the original.

I dug into this more, and it dates all the way back to rGb45c164fc25200afcf48fd5df8912a52319be3e5. Filed https://bugs.llvm.org/show_bug.cgi?id=52004 for this.

smeenai updated this revision to Diff 375676.Sep 28 2021, 1:00 PM

Add comment to test about unrelated wrapping LTO bug

MaskRay accepted this revision.Sep 28 2021, 1:23 PM

and then the ARM backend attempts to change the binding to global, which causes an error.

Elaborate the error.

lld/test/ELF/lto/arm-wrap-personality.ll
2

We repeat the comment marker (e.g. ;; ) for non-RUN non-CHECK lines in lld/test/ELF and some binary utilities

16

;;

This revision is now accepted and ready to land.Sep 28 2021, 1:23 PM
smeenai updated this revision to Diff 375687.Sep 28 2021, 1:40 PM

Change to ;;

smeenai marked 2 inline comments as done.Sep 28 2021, 1:40 PM
smeenai edited the summary of this revision. (Show Details)

and then the ARM backend attempts to change the binding to global, which causes an error.

Elaborate the error.

Thanks for the review! Does the updated summary look sufficient or would you like more details added?

MaskRay accepted this revision.Sep 28 2021, 1:55 PM

LGTM.

lld/test/ELF/lto/arm-wrap-personality.ll
16
smeenai updated this revision to Diff 375693.Sep 28 2021, 2:03 PM

Capitalize

smeenai marked an inline comment as done.Sep 28 2021, 2:03 PM
This revision was landed with ongoing or failed builds.Sep 28 2021, 3:04 PM
This revision was automatically updated to reflect the committed changes.