[PATCH] D96234: [MC][WebAssembly] Fix provisional values for data alias relocations
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 7 20:26:13 PST 2021
sbc100 created this revision.
Herald added subscribers: wingo, ecnelises, sunfish, hiraditya, jgravelle-google, dschuff.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
When calculating the symbol offsets to write as provisitonal values
in object files we are only interested in the offset of the symbol
itself. For aliases this offset already includes the offset of the
base symbol.
The testin question was added back in https://reviews.llvm.org/D87407
but I believe the expectations here were incorrect. sym_a lives
at offset 4 and sym_b lives 4 bytes into that (should be 8).
The addresses of the 3 symbosl in this object file are:
foo : 0
sym_a: 4
sym_b: 8
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D96234
Files:
llvm/lib/MC/WasmObjectWriter.cpp
llvm/test/MC/WebAssembly/alias-offset.s
Index: llvm/test/MC/WebAssembly/alias-offset.s
===================================================================
--- llvm/test/MC/WebAssembly/alias-offset.s
+++ llvm/test/MC/WebAssembly/alias-offset.s
@@ -27,8 +27,8 @@
# CHECK-LABEL: <main>:
# CHECK-EMPTY:
-# CHECK-NEXT: 3: 41 88 80 80 80 00 i32.const 8
+# CHECK-NEXT: 3: 41 84 80 80 80 00 i32.const 4
# CHECK-NEXT: 00000004: R_WASM_MEMORY_ADDR_SLEB sym_a+0
-# CHECK-NEXT: 9: 36 02 8c 80 80 80 00 i32.store 12
+# CHECK-NEXT: 9: 36 02 88 80 80 80 00 i32.store 8
# CHECK-NEXT: 0000000b: R_WASM_MEMORY_ADDR_LEB sym_b+0
# CHECK-NEXT: 10: 0b end
Index: llvm/lib/MC/WasmObjectWriter.cpp
===================================================================
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -610,16 +610,13 @@
case wasm::R_WASM_MEMORY_ADDR_I64:
case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB: {
// Provisional value is address of the global plus the offset
- const MCSymbolWasm *Base =
- cast<MCSymbolWasm>(Layout.getBaseSymbol(*RelEntry.Symbol));
// For undefined symbols, use zero
- if (!Base->isDefined())
+ if (!RelEntry.Symbol->isDefined())
return 0;
- const wasm::WasmDataReference &BaseRef = DataLocations[Base],
- &SymRef = DataLocations[RelEntry.Symbol];
- const WasmDataSegment &Segment = DataSegments[BaseRef.Segment];
+ const wasm::WasmDataReference &SymRef = DataLocations[RelEntry.Symbol];
+ const WasmDataSegment &Segment = DataSegments[SymRef.Segment];
// Ignore overflow. LLVM allows address arithmetic to silently wrap.
- return Segment.Offset + BaseRef.Offset + SymRef.Offset + RelEntry.Addend;
+ return Segment.Offset + SymRef.Offset + RelEntry.Addend;
}
default:
llvm_unreachable("invalid relocation type");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96234.322019.patch
Type: text/x-patch
Size: 1954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210208/aa6438aa/attachment-0001.bin>
More information about the llvm-commits
mailing list