-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[JITLink][AArch32] Fix Unaligned Data Symbol Address Resolution #97030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The ARM architecture uses the LSB bit for ARM/Thumb mode switch flagging. This is true for alignments of 2 and 4 but in data relocations the alignment is 1 allowing the LSB bit to be set. ELF::STT_OBJECT typed symbols are made to bypass the TargetFlag mechanism assuming they are the only symbols affected by data relocations. The test is a minimal example of the issue mentioned below. Fixes the issue "Orc global constructor order test fails on 32 bit ARM llvm#95911".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that's great. Thanks for investigating! As you already proposed, maybe turn the condition around and only emit the Thumb
target flag for callable symbols which should be ELF::STT_FUNC
indeed.
@@ -200,6 +200,9 @@ class ELFLinkGraphBuilder_aarch32 | |||
|
|||
protected: | |||
TargetFlagsType makeTargetFlags(const typename ELFT::Sym &Sym) override { | |||
// Data symbols do not have Arm or Thumb flags. | |||
if (Sym.getType() == ELF::STT_OBJECT) | |||
return TargetFlagsType{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With your fix in getRawOffset()
this check shouldn't be necessary anymore, isn't it? Instead we might want to assert that all symbols with the ThumbSymbol
target flag are ELF::STT_FUNC
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree but I had to keep it because of a failed assert in
assert(Sym.isCallable() && "Only callable symbols can have thumb flag"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With your fix in
getRawOffset()
this check shouldn't be necessary anymore, isn't it? Instead we might want to assert that all symbols with theThumbSymbol
target flag areELF::STT_FUNC
.
Updated the condition to check for STT_FUNC
. I found a similar assert to what you mentioned in the previous comment, should I still add one?
.asciz "H1" | ||
.size Lstr.H1, 3 | ||
|
||
# Not 0x324800 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything special here compared to the other two cases? Or is this a left-over comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is actually, this 'H2' string is the critical part which caused the errors. Before the fix we were getting 0x324800 as its address was indexed by 0x2 instead of 0x3. I wanted something like CHECK-NOT though we do not have it in Checker infra currently. So I left it as comment there.
Nice work, I would have had 0 chance of finding this. I've tested this natively. The new test and the existing test are now passing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small note on your FIXME. Otherwise LGTM!
# FIXME: The expression we want is either *{3}(Lstr.H1) = ... | ||
# or *{4}(Lstr.H1) & 0x00ffffff = ... | ||
# The first is not supported and the latter segfaults. | ||
# Also, whitespaces are not recognized and not consumed by the checker. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could write either (*{4}(Lstr.H1))[23:0]
or (*{4}(Lstr.H1)) & 0x00ffffff
. Does that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does! Thanks for the tip.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/11/builds/849 Here is the relevant piece of the build log for the reference:
|
… build The expressive test added in PR #97030 requires debug option in cli.
…#97030) The ARM architecture uses the LSB bit for ARM/Thumb mode switch flagging. This is true for alignments of 2 and 4 but in data relocations the alignment is 1 allowing the LSB bit to be set. Now only `ELF::STT_FUNC` typed symbols are used in the TargetFlag mechanism. The test is a minimal example of the issue mentioned below. Fixes llvm#95911 "Orc global constructor order test fails on 32 bit ARM".
… build The expressive test added in PR llvm#97030 requires debug option in cli.
The ARM architecture uses the LSB bit for ARM/Thumb mode switch
flagging. This is true for alignments of 2 and 4 but in data
relocations the alignment is 1 allowing the LSB bit to be set.
ELF::STT_OBJECT
typed symbols are made to bypass the TargetFlagmechanism assuming they are the only symbols affected by data
relocations.
The test is a minimal example of the issue mentioned below.
Fixes #95911 "Orc global constructor order test fails on 32
bit ARM".