Skip to content

Conversation

@hwti
Copy link
Contributor

@hwti hwti commented Nov 14, 2025

In this case, the value is a constant, not an addend to a relocation.
So the "Relocation Not In Range" error must not be triggered.

Regression from PR #112877
Fixes #132322

In this case, the value is a constant, not an addend to a relocation.
So the "Relocation Not In Range" error must not be triggered.

Regression from PR llvm#112877
Fixes llvm#132322
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2025

@llvm/pr-subscribers-backend-arm

Author: Loïc Yhuel (hwti)

Changes

In this case, the value is a constant, not an addend to a relocation.
So the "Relocation Not In Range" error must not be triggered.

Regression from PR #112877
Fixes #132322


Full diff: https://github.com/llvm/llvm-project/pull/168072.diff

2 Files Affected:

  • (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp (+1-1)
  • (added) llvm/test/MC/ARM/arm-movt-movw-absolute-pass.s (+14)
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index f8196e460ae9c..02a7b1a3d0919 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
@@ -428,7 +428,7 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
   // signed 16bit range.
   if ((Kind == ARM::fixup_arm_movw_lo16 || Kind == ARM::fixup_arm_movt_hi16 ||
        Kind == ARM::fixup_t2_movw_lo16 || Kind == ARM::fixup_t2_movt_hi16) &&
-      (Addend < minIntN(16) || Addend > maxIntN(16))) {
+      !Target.isAbsolute() && (Addend < minIntN(16) || Addend > maxIntN(16))) {
     Ctx.reportError(Fixup.getLoc(), "Relocation Not In Range");
     return 0;
   }
diff --git a/llvm/test/MC/ARM/arm-movt-movw-absolute-pass.s b/llvm/test/MC/ARM/arm-movt-movw-absolute-pass.s
new file mode 100644
index 0000000000000..ed888a0a4aaae
--- /dev/null
+++ b/llvm/test/MC/ARM/arm-movt-movw-absolute-pass.s
@@ -0,0 +1,14 @@
+@RUN: llvm-mc -triple armv7-eabi -filetype obj -o - %s 2>&1 | FileCheck %s
+
+    .text
+a:
+    movw    r1, #:lower16:b - a + 65536
+    movt    r1, #:upper16:b - a + 65536
+b:
+
+@CHECK-NOT: error: Relocation Not In Range
+@CHECK-NOT: movw    r1, #:lower16:b - a + 65536
+@CHECK-NOT: ^
+@CHECK-NOT: error: Relocation Not In Range
+@CHECK-NOT: movt    r1, #:upper16:b - a + 65536
+@CHECK-NOT: ^

@hwti
Copy link
Contributor Author

hwti commented Nov 14, 2025

cc @Stylie777 @DavidSpickett @jthackray from the PR which added the Relocation Not In Range error

movt r1, #:upper16:b - a + 65536
b:

@CHECK-NOT: error: Relocation Not In Range
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking for the error message, please just check that we generate the correct instruction encoding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used arm-movt-movw-range-pass.s as a model.

llvm-mc -show-encoding produces :

        movw    r1, :lower16:((b-a)+65536)      @ encoding: [A,0x10'A',0b0000AAAA,0xe3]
                                        @   fixup A - offset: 0, value: (b-a)+65536, kind: fixup_arm_movw_lo16
        movt    r1, :upper16:((b-a)+65536)      @ encoding: [A,0x10'A',0b0100AAAA,0xe3]
                                        @   fixup A - offset: 0, value: (b-a)+65536, kind: fixup_arm_movt_hi16

so it doesn't show the value is resolved.

Do you want a test with llvm-objdump, like :

@RUN: llvm-mc -triple armv7-eabi -filetype obj %s -o - | llvm-objdump -d --triple armv7-eabi - | FileCheck %s

a:
    movw    r1, #:lower16:b - a + 65536
    movt    r1, #:upper16:b - a + 65536
b:

@CHECK: 0: e3001008 movw r1, #0x8
@CHECK: 4: e3401001 movt r1, #0x1

?

But it actually tests more, so I don't know know if you meant with "just check ...".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something with llvm-objdump seems fine, yes.

if ((Kind == ARM::fixup_arm_movw_lo16 || Kind == ARM::fixup_arm_movt_hi16 ||
Kind == ARM::fixup_t2_movw_lo16 || Kind == ARM::fixup_t2_movt_hi16) &&
(Addend < minIntN(16) || Addend > maxIntN(16))) {
!Target.isAbsolute() && (Addend < minIntN(16) || Addend > maxIntN(16))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe could use IsResolved here instead? I guess it's basically the same thing in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, changed to !IsResolved.

@github-actions
Copy link

🐧 Linux x64 Test Results

  • 186275 tests passed
  • 4849 tests skipped

Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@efriedma-quic efriedma-quic merged commit 5e80358 into llvm:main Nov 18, 2025
10 checks passed
@github-actions
Copy link

@hwti Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@hwti hwti deleted the arm-movw-movt-offset branch November 19, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compilation failure in Webkit 2.48.0 with Clang-20 on ARM

3 participants