[llvm] 01a4853 - [MC][WebAssembly] Fix provisional values for data alias relocations
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 8 17:00:17 PST 2021
Author: Sam Clegg
Date: 2021-02-08T16:56:57-08:00
New Revision: 01a48535c31169461d4eedddb48c00b79277f388
URL: https://github.com/llvm/llvm-project/commit/01a48535c31169461d4eedddb48c00b79277f388
DIFF: https://github.com/llvm/llvm-project/commit/01a48535c31169461d4eedddb48c00b79277f388.diff
LOG: [MC][WebAssembly] Fix provisional values for data alias relocations
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
Differential Revision: https://reviews.llvm.org/D96234
Added:
Modified:
llvm/lib/MC/WasmObjectWriter.cpp
llvm/test/MC/WebAssembly/alias-offset.s
Removed:
################################################################################
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 6b775e12f08d..d16be49c92e6 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -610,16 +610,13 @@ WasmObjectWriter::getProvisionalValue(const WasmRelocationEntry &RelEntry,
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");
diff --git a/llvm/test/MC/WebAssembly/alias-offset.s b/llvm/test/MC/WebAssembly/alias-offset.s
index 93dbe21c3f9b..d547e4bb204b 100644
--- a/llvm/test/MC/WebAssembly/alias-offset.s
+++ b/llvm/test/MC/WebAssembly/alias-offset.s
@@ -27,8 +27,8 @@ main:
# 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
More information about the llvm-commits
mailing list