Skip to content

[lld][WebAssembly] Add missing relocation types to the --compress-relocations path #144578

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SingleAccretion
Copy link
Contributor

@SingleAccretion SingleAccretion commented Jun 17, 2025

Fixes #110045.

Reloc list reference:

+ Already handled
A Added in this change
= Not applicable / expected (though technically legal, e. g. you can relocate v128.const...)

+ R_WASM_FUNCTION_INDEX_LEB,      0
+ R_WASM_TABLE_INDEX_SLEB,        1
= R_WASM_TABLE_INDEX_I32,         2
+ R_WASM_MEMORY_ADDR_LEB,         3
+ R_WASM_MEMORY_ADDR_SLEB,        4
= R_WASM_MEMORY_ADDR_I32,         5
+ R_WASM_TYPE_INDEX_LEB,          6
+ R_WASM_GLOBAL_INDEX_LEB,        7
= R_WASM_FUNCTION_OFFSET_I32,     8
= R_WASM_SECTION_OFFSET_I32,      9
+ R_WASM_TAG_INDEX_LEB,          10
A R_WASM_MEMORY_ADDR_REL_SLEB,   11
A R_WASM_TABLE_INDEX_REL_SLEB,   12
= R_WASM_GLOBAL_INDEX_I32,       13
+ R_WASM_MEMORY_ADDR_LEB64,      14
+ R_WASM_MEMORY_ADDR_SLEB64,     15
= R_WASM_MEMORY_ADDR_I64,        16
A R_WASM_MEMORY_ADDR_REL_SLEB64, 17
+ R_WASM_TABLE_INDEX_SLEB64,     18
= R_WASM_TABLE_INDEX_I64,        19
+ R_WASM_TABLE_NUMBER_LEB,       20
A R_WASM_MEMORY_ADDR_TLS_SLEB,   21
= R_WASM_FUNCTION_OFFSET_I64,    22
= R_WASM_MEMORY_ADDR_LOCREL_I32, 23
A R_WASM_TABLE_INDEX_REL_SLEB64, 24
A R_WASM_MEMORY_ADDR_TLS_SLEB64, 25
= R_WASM_FUNCTION_INDEX_I32,     26

@SingleAccretion
Copy link
Contributor Author

@sbc100

@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2025

@llvm/pr-subscribers-lld-wasm

@llvm/pr-subscribers-lld

Author: None (SingleAccretion)

Changes

Fixes #110045.

Reloc list reference:

+ Already handled
A Added in this change
= Not applicable / expected (though technically legal, e. g. you can relocate v128.const...)

+ R_WASM_FUNCTION_INDEX_LEB,      0
+ R_WASM_TABLE_INDEX_SLEB,        1
= R_WASM_TABLE_INDEX_I32,         2
+ R_WASM_MEMORY_ADDR_LEB,         3
+ R_WASM_MEMORY_ADDR_SLEB,        4
= R_WASM_MEMORY_ADDR_I32,         5
+ R_WASM_TYPE_INDEX_LEB,          6
+ R_WASM_GLOBAL_INDEX_LEB,        7
= R_WASM_FUNCTION_OFFSET_I32,     8
= R_WASM_SECTION_OFFSET_I32,      9
+ R_WASM_TAG_INDEX_LEB,          10
A R_WASM_MEMORY_ADDR_REL_SLEB,   11
A R_WASM_TABLE_INDEX_REL_SLEB,   12
= R_WASM_GLOBAL_INDEX_I32,       13
+ R_WASM_MEMORY_ADDR_LEB64,      14
+ R_WASM_MEMORY_ADDR_SLEB64,     15
= R_WASM_MEMORY_ADDR_I64,        16
A R_WASM_MEMORY_ADDR_REL_SLEB64, 17
+ R_WASM_TABLE_INDEX_SLEB64,     18
= R_WASM_TABLE_INDEX_I64,        19
+ R_WASM_TABLE_NUMBER_LEB,       20
A R_WASM_MEMORY_ADDR_TLS_SLEB,   21
= R_WASM_FUNCTION_OFFSET_I64,    22
= R_WASM_MEMORY_ADDR_LOCREL_I32, 23
A R_WASM_TABLE_INDEX_REL_SLEB64, 24
A R_WASM_MEMORY_ADDR_TLS_SLEB64, 25
= R_WASM_FUNCTION_INDEX_I32,     26

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

1 Files Affected:

  • (modified) lld/wasm/InputChunks.cpp (+12)
diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp
index 9383dcaeb4f55..af35c83e35c9b 100644
--- a/lld/wasm/InputChunks.cpp
+++ b/lld/wasm/InputChunks.cpp
@@ -225,8 +225,14 @@ static unsigned writeCompressedReloc(uint8_t *buf, const WasmRelocation &rel,
     return encodeULEB128(value, buf);
   case R_WASM_TABLE_INDEX_SLEB:
   case R_WASM_TABLE_INDEX_SLEB64:
+  case R_WASM_TABLE_INDEX_REL_SLEB64:
   case R_WASM_MEMORY_ADDR_SLEB:
   case R_WASM_MEMORY_ADDR_SLEB64:
+  case R_WASM_MEMORY_ADDR_REL_SLEB:
+  case R_WASM_MEMORY_ADDR_REL_SLEB64:
+  case R_WASM_MEMORY_ADDR_TLS_SLEB:
+  case R_WASM_MEMORY_ADDR_TLS_SLEB64:
+  case R_WASM_TABLE_INDEX_REL_SLEB:
     return encodeSLEB128(static_cast<int64_t>(value), buf);
   default:
     llvm_unreachable("unexpected relocation type");
@@ -242,11 +248,17 @@ static unsigned getRelocWidthPadded(const WasmRelocation &rel) {
   case R_WASM_MEMORY_ADDR_LEB:
   case R_WASM_TABLE_NUMBER_LEB:
   case R_WASM_TABLE_INDEX_SLEB:
+  case R_WASM_TABLE_INDEX_REL_SLEB:
   case R_WASM_MEMORY_ADDR_SLEB:
+  case R_WASM_MEMORY_ADDR_REL_SLEB:
+  case R_WASM_MEMORY_ADDR_TLS_SLEB:
     return 5;
   case R_WASM_TABLE_INDEX_SLEB64:
+  case R_WASM_TABLE_INDEX_REL_SLEB64:
   case R_WASM_MEMORY_ADDR_LEB64:
   case R_WASM_MEMORY_ADDR_SLEB64:
+  case R_WASM_MEMORY_ADDR_REL_SLEB64:
+  case R_WASM_MEMORY_ADDR_TLS_SLEB64:
     return 10;
   default:
     llvm_unreachable("unexpected relocation type");

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Thanks!

I think it would be good to add all of these to current test(s) for --emit-relocs in lld/test/wasm/?

@SingleAccretion SingleAccretion changed the title [lld][WebAssembly] Add missing relocation types to the --compress-relocs path [lld][WebAssembly] Add missing relocation types to the --compress-relocations path Jun 17, 2025
@SingleAccretion
Copy link
Contributor Author

I think it would be good to add all of these to current test(s) for --emit-relocs in lld/test/wasm/?

Agree; the current testing is a bit spartan. Will do what's possible.

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.

wasm-ld crashes with --compress-relocations
3 participants