Skip to content

Commit a506ca6

Browse files
committedMay 2, 2019
Disable generating PC-relative relocations in constant builder
This doesn't take care of all the PC relative relocations in constant builder yet. This still breaks on `((.Lgot.$sSTMp.656-($ss18EnumeratedSequenceVMn))-56)+1` Which sits in rodata. Not sure where that's generated yet
1 parent 400fc86 commit a506ca6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎lib/IRGen/ConstantBuilder.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class ConstantAggregateBuilderBase
8282

8383
void addRelativeAddress(llvm::Constant *target) {
8484
assert(!isa<llvm::ConstantPointerNull>(target));
85+
if (IGM().TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
86+
// WebAssembly: hack: doesn't support PCrel data relocations
87+
add(llvm::ConstantExpr::getPtrToInt(target, IGM().RelativeAddressTy, false));
88+
return;
89+
}
8590
addRelativeOffset(IGM().RelativeAddressTy, target);
8691
}
8792

@@ -90,6 +95,13 @@ class ConstantAggregateBuilderBase
9095
/// a "GOT-equivalent", i.e. a pointer to an external object; if so,
9196
/// set the low bit of the offset to indicate that this is true.
9297
void addRelativeAddress(ConstantReference reference) {
98+
if (IGM().TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
99+
// WebAssembly: hack: doesn't support PCrel data relocations
100+
// also, we should set the lowest bit, but I don't know how to do that
101+
// there's no GOT on WebAssembly anyways though
102+
add(llvm::ConstantExpr::getPtrToInt(reference.getValue(), IGM().RelativeAddressTy, false));
103+
return;
104+
}
93105
addTaggedRelativeOffset(IGM().RelativeAddressTy,
94106
reference.getValue(),
95107
unsigned(reference.isIndirect()));
@@ -99,6 +111,11 @@ class ConstantAggregateBuilderBase
99111
/// The target must be a "GOT-equivalent", i.e. a pointer to an
100112
/// external object.
101113
void addIndirectRelativeAddress(ConstantReference reference) {
114+
if (IGM().TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
115+
// WebAssembly: hack: doesn't support PCrel data relocations
116+
add(llvm::ConstantExpr::getPtrToInt(reference.getValue(), IGM().RelativeAddressTy, false));
117+
return;
118+
}
102119
assert(reference.isIndirect());
103120
addRelativeOffset(IGM().RelativeAddressTy,
104121
reference.getValue());

0 commit comments

Comments
 (0)
Please sign in to comment.