This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Update skipRelocation for aarch64
ClosedPublic

Authored by yota9 on Apr 7 2022, 12:35 PM.

Details

Summary

The ld might relax ADRP+ADD or ADRP+LDR sequences to the ADR+NOP, add
the new case to the skipRelocation for aarch64.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

Diff Detail

Event Timeline

yota9 created this revision.Apr 7 2022, 12:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2022, 12:35 PM
yota9 requested review of this revision.Apr 7 2022, 12:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2022, 12:35 PM
rafauler added inline comments.Apr 11 2022, 12:53 PM
bolt/lib/Core/Relocation.cpp
227

By ld, do you mean GNU ld? How is the test testing for that? (since it uses lld)

yota9 added inline comments.Apr 11 2022, 12:57 PM
bolt/lib/Core/Relocation.cpp
227

No, I meant generic linker, not bfd. The lld has this optimization too (https://reviews.llvm.org/D117614)

rafauler added inline comments.Apr 11 2022, 1:03 PM
bolt/test/runtime/plt-lld.test
1–2

Is it possible to add a check by dumping the binary symbol table to verify that these are properly updated? having the test as is (checking if a binary runs) is quite opaque for reviewers and makes it a bit hard for us to be helpful and understand what is going on and what your patch is fixing. If we treat these relocations that were relaxed to ADR as real relocs (meaning, we do not have your patch), what does it happen? Does BOLT crash? Do PLT pointers get messed up?

rafauler added inline comments.Apr 11 2022, 1:04 PM
bolt/lib/Core/Relocation.cpp
227

Can you replace ld by "linker", then?

yota9 marked 2 inline comments as done.Apr 13 2022, 7:22 AM
yota9 added inline comments.
bolt/test/runtime/plt-lld.test
1–2

I will add extra test now.

what does it happen?

The pointers in code are messed up, so we will have runtime problems. E.g.
Let's suppose the GOT relocations were relaxed to the local symbol definition

1036c:       d503201f        nop
                     1036c: R_AARCH64_ADR_GOT_PAGE   foo2
10370:       10000080        adr     x0, 10380 <foo2>
                     10370: R_AARCH64_LD64_GOT_LO12_NC       foo2

After bolt without this patch we will have:

400024:       90ffe000        adrp    x0, 0 <_DYNAMIC-0x20388>
400028:       91000000        add     x0, x0, #0x0

Because the extracted value was messed up (we were expecting other instruction)

yota9 updated this revision to Diff 422514.Apr 13 2022, 7:31 AM
yota9 marked an inline comment as done.

Add test

rafauler accepted this revision.Apr 13 2022, 11:10 AM

Looks good, thanks!

This revision is now accepted and ready to land.Apr 13 2022, 11:10 AM
This revision was automatically updated to reflect the committed changes.