diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index 85e68e306cae04e3d93b9ec4cb7f94b9b043b1c6..18f40ececda196c3db3dcf2402b543e1061688b6 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -3832,6 +3832,9 @@ needSourceNotes dflags = debugLevel dflags > 0
 -- | Should we use `-XLinker -rpath` when linking or not?
 -- See Note [-fno-use-rpaths]
 useXLinkerRPath :: DynFlags -> OS -> Bool
+-- wasm shared libs don't have RPATH at all and wasm-ld doesn't accept
+-- any RPATH-related flags
+useXLinkerRPath dflags _ | ArchWasm32 <- platformArch $ targetPlatform dflags = False
 useXLinkerRPath _ OSDarwin = False -- See Note [Dynamic linking on macOS]
 useXLinkerRPath dflags _ = gopt Opt_RPath dflags