Skip to content

Conversation

@yonghong-song
Copy link
Contributor

Currently, the jump table entry contains labels only. For example, the following is one example:

  BPF.JT.0.0:
        .quad   LBB0_1
        .quad   LBB0_2
        .size   BPF.JT.0.0, 16

Since the jump table entry contains a label, the relocation is necessary so linker can resolve the label value. The relocation looks like below:

  Relocation section '.rel.jumptables' at offset 0x160 contains 2 entries:
      Offset             Info             Type               Symbol's Value  Symbol's Name
  0000000000000000  0000000200000002 R_BPF_64_ABS64         0000000000000000 .text
  0000000000000008  0000000200000002 R_BPF_64_ABS64         0000000000000000 .text

You can see that the symbol value is 0 which makes .rel.jumptables not very useful.

Instead of having the label itself in the jump table entry, use the difference of label and the section begin symbol. This can avoid the relocation and the eventual jumptable entries in object file remains the same as before.

  Hex dump of section '.jumptables':
  0x00000000 68000000 00000000 78000000 00000000 h.......x.......

@yonghong-song yonghong-song requested review from 4ast and eddyz87 November 4, 2025 04:53
@github-actions
Copy link

github-actions bot commented Nov 4, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@yonghong-song
Copy link
Contributor Author

cc @aspsk

Currently, the jump table entry contains labels only.
For example, the following is one example:

  BPF.JT.0.0:
        .quad   LBB0_1
        .quad   LBB0_2
        .size   BPF.JT.0.0, 16

Since the jump table entry contains a label, the relocation
is necessary so linker can resolve the label value. The relocation
looks like below:

  Relocation section '.rel.jumptables' at offset 0x160 contains 2 entries:
      Offset             Info             Type               Symbol's Value  Symbol's Name
  0000000000000000  0000000200000002 R_BPF_64_ABS64         0000000000000000 .text
  0000000000000008  0000000200000002 R_BPF_64_ABS64         0000000000000000 .text

You can see that the symbol value is 0 which makes .rel.jumptables
not very useful.

Instead of having the label itself in the jump table entry,
use the difference of label and the section begin symbol.
This can avoid the relocation and the eventual jumptable
entries in object file remains the same as before.

  Hex dump of section '.jumptables':
  0x00000000 68000000 00000000 78000000 00000000 h.......x.......
@yonghong-song
Copy link
Contributor Author

@eddyz87 has similar idea before (to have (label - <start_section>)/8 as the jump table entry). Later on it is decided that label itself is good enough. This patch merely change the jump table entry to (label - <start_section>) to avoid unnecessary relocation for jump table.

Copy link
Contributor

@eddyz87 eddyz87 left a comment

Choose a reason for hiding this comment

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

The change makes sense, thank you!
Tested with planned kernel selftests, no more relocations in the .jumptables section.

@yonghong-song yonghong-song merged commit 7272a6c into llvm:main Nov 4, 2025
10 checks passed
@aspsk
Copy link

aspsk commented Nov 5, 2025

Thanks @yonghong-song, tested as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants